GameMaker: Studio

GameMaker: Studio

View Stats:
Intro_Outro Apr 24, 2017 @ 8:45pm
Instance create and draw events
I'm not that confident with both of these properties and need some help please.

I have an enemy that draws its own health bar at the top of the screenwhen created. It respawns when killed with the help of an alarm. When it respawns it no longer draws its health bar.

Any suggestions?
< >
Showing 1-5 of 5 comments
GLIM888 Apr 25, 2017 @ 3:57am 
is your health variable global?
do you reset the health variable, when you recreate this object?

do you create a new instance, when the old die, or do you use the same?
Intro_Outro Apr 28, 2017 @ 5:24pm 
Thanks for the reply.

health is a (local?) variable called hp.

Not sure how to reset the health variable when the object is recreated.

The enemy parent spawns the same enemy with the same instance id.

Can you respawn the same enemy (obj_enemy) with a different instance id?
DarkToxic Apr 28, 2017 @ 6:12pm 
Could you show us your codes/scripts.
Intro_Outro Apr 28, 2017 @ 7:50pm 
I have three objects: obj_enemy, obj_enemy_parent, and obj_gui.

obj_gui draw event (draws) the obj_enemy_parent health on the screen, top right.


obj_enemy_parent step event:
if obj_enemy (does not) exist (then) instance_create obj_enemy.
//standard stuff for respawning enemies.


Once the obj_enemy has created by the obj_enemy_parent, obj_gui no longer draws the health of obj_enemy_parent. If I try to draw the obj_enemy health, once it dies GM errors stating it does not detect the object.
DarkToxic Apr 28, 2017 @ 7:57pm 
Maybe try this in obj_gui?

_enemy = instance_nearest(x,y obj_enemy_parent);

if(_enemy != noone){
draw_text(x pos, y pos, _enemy.hp)
}

Not sure tho.

EDIT:
Why not do something like this instead:

// par gui step/draw event:
_enemy = (obj_enemy)

if(instance_exists(_enemy)){

with(_enemy){
draw_text(x pos, y pos, string(hp))
}

}
Last edited by DarkToxic; Apr 28, 2017 @ 8:08pm
< >
Showing 1-5 of 5 comments
Per page: 1530 50

Date Posted: Apr 24, 2017 @ 8:45pm
Posts: 5