Using paths and movement in a scrolling room (Game Maker)

A place for people with an interest in developing new shmups.
Post Reply
User avatar
cigsthecat
Posts: 929
Joined: Wed Jan 26, 2005 12:35 am
Location: Burbank, CA

Using paths and movement in a scrolling room (Game Maker)

Post by cigsthecat »

The vert shooter I'm working on consists (so far) of one long room. The view then steadily scrolls upward from the bottom.

If I try using paths on enemies though, they always start moving down too quickly because of the scrolling room. How can I use paths and still keep the same format so I can place enemies in precise locations?
User avatar
ForteMP3
Posts: 178
Joined: Tue Feb 01, 2005 3:15 pm
Location: Somewhere in the Midwest.

Post by ForteMP3 »

On the question of moving objects along a path in a scrolling environment:

One solution would be to change speed during the path as they move down (You can set a percent of the speed to be used at every node of a path).

You could also use alarms or even a timeline to code a path that way, but this might be a bit more difficult. I would recommend just using the easy approach:Modify the speed percentage in the path itself for downward movement.
YOU ARE APPROACHING THE TARGET OF ATTACK! THE MISSION STARTS NOW! ARE YOU READY?!
User avatar
cigsthecat
Posts: 929
Joined: Wed Jan 26, 2005 12:35 am
Location: Burbank, CA

Post by cigsthecat »

OK...I don't understand how to do this though. I have a variable set that says

set variable view_yview to -2

This moves the view -2 from the bottom of the room each step, giving the scrolling. So the boss for example has a speed of -2 to keep it in place. I've tried changing the speeds of the points in the path editor but nothing seems to work. I can't enter negative numbers there however, maybe that's the problem?

There's also a speed setting in the action to set the path, but putting a -2 doesn't work here either.
User avatar
ForteMP3
Posts: 178
Joined: Tue Feb 01, 2005 3:15 pm
Location: Somewhere in the Midwest.

Post by ForteMP3 »

cigsthecat wrote:OK...I don't understand how to do this though. I have a variable set that says

set variable view_yview to -2

This moves the view -2 from the bottom of the room each step, giving the scrolling. So the boss for example has a speed of -2 to keep it in place. I've tried changing the speeds of the points in the path editor but nothing seems to work. I can't enter negative numbers there however, maybe that's the problem?

There's also a speed setting in the action to set the path, but putting a -2 doesn't work here either.
Well, the speed setting in the path editor is a percentage value. So if you move something along a path with a speed of 4 via code, and at a pathnode in the editor, have the path speed set to 50, that's 50 percent of the speed, so the object would move at a speed of 2. The reason you can't use a negative value is because again, the speeds you assign in the path edtitor are percentages of whatever speed you give to your object when it moves along the path. I think this is what you're trying to figure out...If not, clarify and I'll see what I can do.

Also, once you reach the end of the room, you should likely STOP scrolling it. Moving outside the room can cause issues, it has in my work, at least.
YOU ARE APPROACHING THE TARGET OF ATTACK! THE MISSION STARTS NOW! ARE YOU READY?!
User avatar
cigsthecat
Posts: 929
Joined: Wed Jan 26, 2005 12:35 am
Location: Burbank, CA

Post by cigsthecat »

OK, I get how that works. The problem is that paths ignore speeds that instances are set to. Since for example, my boss needs to have a speed of -2 to stay in one spot, anything else means he just scrolls right by. I can't even start level design until I work this out since nothing will do what I want.
User avatar
ForteMP3
Posts: 178
Joined: Tue Feb 01, 2005 3:15 pm
Location: Somewhere in the Midwest.

Post by ForteMP3 »

Well, if an enemy needs to stay in a given location, a path may not be the best way to do it. A timeline may work better. You could set speeds at given times, and keep the vspeed relative to the scrolling speed.

Speaking of which, since you're making a shmup, vspeed and hspeed may be your two best friends. These are separate variables from speed that let you adjust both horizontal speed and vertical speed.

So, for example, if you set a boss' vspeed to -2, and hspeed to 3, he'd move to the right while staying aligned with the screen. Perhaps this will work better than paths.

Again though, you should probably stop scrolling during a boss fight. Also, while you won't need to worry about this until much later, you'll want to learn how to destroy temp objects (IE, bullets) when they leave the view, and also de-activate anything not currently in it. Once you get more of the basics down, let me know and I'll give you some tips on these aspects, as they are CRUCIAL to game speed.
YOU ARE APPROACHING THE TARGET OF ATTACK! THE MISSION STARTS NOW! ARE YOU READY?!
User avatar
cigsthecat
Posts: 929
Joined: Wed Jan 26, 2005 12:35 am
Location: Burbank, CA

Post by cigsthecat »

Thanks, that's a great idea about the hspeed thing. Maybe if I set it's vspeed to something else just briefly it can move in other directions too. Not being able to set the normal enemies to simple paths would suck though.

And yeah, destroying the bullets outside the view will be necessary at some point. It's too bad there isn't an "outside view" event like like the outside room one.
User avatar
ForteMP3
Posts: 178
Joined: Tue Feb 01, 2005 3:15 pm
Location: Somewhere in the Midwest.

Post by ForteMP3 »

Event? No. Means to do it? Yes.

Here's an easy way to destroy any bullet outside the view, put this in the step event of the bullet

if x>view_xview+(put size of view here) || x<view_xview || y>view_yview+(size of view) || y<view_yview
{
instance_destroy()
}

Basically, this will have the bullet check to see if its x or y coordinates are larger than the length/height of the view (Right/bottom), or smaller than the starting points for the view (The left and top).

A similar method can be used for what GM calls activating and de-activating instances. Basically, deactivating an instance 'suspends' it. The object is not removed from the room entirely, but it is made invisible, and none of its code is executed. By using instance de-activation, you can deactivate enemies not currently in the view, and thus prevent their code from executing. This may also help you with your path problem, as they wouldn't actually begin moving until you re-activated them, which you could do as the enter the view.

Note however, that a de-activated instance cannot do ANYTHING until it is re-activated. There's a section in GM6's helpfile about doing this, and it's something I recommend you learn. The basic rule of thumb however, is this...

Keep objects de-activated until you need them. If you no longer need them at all after they have activated (IE, an enemy leaving the bottom of the screen) destroy them.
YOU ARE APPROACHING THE TARGET OF ATTACK! THE MISSION STARTS NOW! ARE YOU READY?!
User avatar
cigsthecat
Posts: 929
Joined: Wed Jan 26, 2005 12:35 am
Location: Burbank, CA

Post by cigsthecat »

I put in the code you said, thank you. Is there a way to make sure that the instances are actually being destroyed?
User avatar
Shatterhand
Posts: 4039
Joined: Wed Jan 26, 2005 3:01 am
Location: Rio de Janeiro - Brazil
Contact:

Post by Shatterhand »

Run the game in debug mode and check the number of instances.
Image
User avatar
cigsthecat
Posts: 929
Joined: Wed Jan 26, 2005 12:35 am
Location: Burbank, CA

Post by cigsthecat »

I really do need to have all enemies outside the view deactivated (then activated once inside the view) now. I found this code in the help file that says it will do exactly that:

Code: Select all

{
  instance_activate_all();
  instance_deactivate_region(view_xview[0],view_yview[0],
                        view_wview[0],view_hview[0],false,true);
}
When I put it in the step event of enemies weird things happen though. Can someone help me implement this? My view is a width of 480, height of 640.
User avatar
ForteMP3
Posts: 178
Joined: Tue Feb 01, 2005 3:15 pm
Location: Somewhere in the Midwest.

Post by ForteMP3 »

That code shouldn't be part of the enemy objects, because a deactivated instance cannot re-activate itself. What you want here is some kind of Controller Object (These can be used for a number of things, not just instance control).

Basically, the object should always remain in the view (X=view_xview Y=view_yview in the step event can handle this easily) and run the instance activate/deactivate code with it. Also, you may want to use a region slightly larger than your view when activating and deactivating instances, so enemies can be spawned/arrive from outside the view (IE, left and right sides of screen).

When doing activation and de-activation, the following variables will need to be taken into account

Your X-View and Y-View (view_xview and view_yview) as well as their width and height (do NOT use the variables for these though, they only define width/height, NOT their locations!).

To define Width and Height for your views, simply use view_xview+(width) for the X View, and view_yview+(height) for the Y View.

Just remember these golden rules about deactivating versus destroying:

-Anything that will not need to return to the screen (IE, bullets, enemies that have already flown by) should be destroyed.

-Anything that will need to enter the screen and possibly re-enter it later should only be deactivated (Inactive enemies, enemies that fly across the screen more than once).

The easiest way to code if an enemy should be destroyed or de-activated after entering the view is to simply have a destroy event (That doesn't process things that would happen if the player KILLED the enemy) occur. For example, let's say you have an enemy that flies straight down, you could do this:


STEP EVENT
if y>view_view instance_destroy()

And in the destroy event, we would have something like this

if hp=0
"Run any code for destroying the enemy like score additions and explosions here."

Basically, that sets it up so the enemy is destroyed permanently after passing the bottom of the screen. If its HP (A life value, basically) is 0, then the actual enemy destruction by player stuff (explosion, points) occurs. Otherwise it's simply removed as if it was never there.

And there you have it! Hope this helped!
YOU ARE APPROACHING THE TARGET OF ATTACK! THE MISSION STARTS NOW! ARE YOU READY?!
Post Reply