How would I go about drawing an object on top of another object?

R

rauwolf

Guest
hello, I have an enemy ship object created and wanted to have a separate object on top of it that would contain a thrust animation. I tried Add Event > Draw > Draw but was not able to link the thrust animation to follow the enemy ship. I would appreciate any help on how to resolve this. This is for a horizontal shooter game.
 
O

Opticrow

Guest
hello, I have an enemy ship object created and wanted to have a separate object on top of it that would contain a thrust animation.
If it's an object, then just put:
Code:
x = obj_Ship.x;
y = obj_Ship.y;
in the thrust animation object step event.
 

RangerX

Member
Also ajust the depth variable of each object. The higher the depth, the more "in front" it will be.
 
R

rauwolf

Guest
thank you for all the help, its now working perfect for the ship. I have a question, I added the same code to some enemy ships so they could have a thrust animation, but when ever one gets destroyed all the other ships loose their thrust animation. Is there a way I can set some id so that only the ship that gets hit by my laser is the only one that loses its thrust animation?
 
Last edited by a moderator:
ok first dont use a draw event, create an actual object for the thrust thingy.

create it in the ship create event and call it something like

dude = instance_create (self.x,self.y,obj_thruster)

then in the END STEP event of the ship put

Code:
if instance_exists (dude)
{
if dude.x != self.x{dude.x = self.x}
if dude.y != self.y{dude.y = self.y}
}
the reason you put it in the end event of the ship is that if you have the thruster trying to follow in step wit the ship a lag will happen, putting it in the end step of the ship means the ship will move, the ship will move the thruster and then the image will be displayed, the difference is move ship, show, move thruster versus move ship, move thruster, show

and finally when the ship is destroyed you have one line of code before that says

with(dude){instance_destroy()}

that way only the dude you created for the ship when it was created will be the only dude thats destroyed when the ship goes down.

have a great day dude :)
 
O

Opticrow

Guest
ok first dont use a draw event, create an actual object for the thrust thingy.
Although, it would definitely be more efficient to use the draw event instead of an entirely new object. Especially if there will be lots of ships.
 
A

Aura

Guest
@JML: You shouldn't use self.variable when the scope of the code is local. For instance, using x is the same as using self.x.

@Opticrow: Apart from that, if you don't want to use instances, you can simply use a variable which tells if the enemy ship is doing a thrust attack. Then you can simply use the Draw event of the enemy ship object to draw the thrust animation. For instance:

Code:
draw_self();
if (doing_thrust) {
   draw_sprite(spr_enethrust, ind, x, y);
}
...where ind is another variable to hold the current image index of the thrust animation. Increase its value by your desired animation speed in the Step event. You could set doing_thrust to false if it is equal (or larger than) to the number of images (-1). Or you could perhaps reset it to 0 if an enemy ship attacks while doing_thrust is true. That's up to you!
 

Weird Dragon

Wizard
GMC Elder
Also ajust the depth variable of each object. The higher the depth, the more "in front" it will be.
It is actually the opposite, the lower the depth the more "in front", like an object with depth -1 will appear in front of an object with depth 0, and they will both be in front of an object with depth 1.
 
A

Aura

Guest
@JML: In general you should never need to use this keyword, as you can do the same task more efficiently and appropriately using other keywords or functions, and is maintained for legacy support reasons. (source) Also I have seen it cause errors and work differently on different platforms.
 
Top