Page 1 of 1

Problem with multiple enemies and hp bars

PostPosted: Mon Apr 01, 2013 4:56 am
by Hblade
So I have an Enemy HP bar, right? The only problem is, it seems to go up and down randomly as if it things -EVERY- enemy is its first creator or something? Here's the code for the HP bar to read the newly created enemies HP.
Code: Select all
X=creator.ehp;
Y=creator.mhp;
Z=width*X/Y;
erase(0, 0, 0, 0);
for(i=0;i<Z;i++)
{
    setpen(255, 0, 0, 0, 1);
    moveto(i, 0);
    lineto(i, height);
}


if(creator.ehp<=0)
{
    DestroyActor("Event Actor");
}

X Y and Z are creator variables, as is i. I can't figure out whats going on o.O When I hit 1 enemy, every bar jumps a little xD

EDIT:
It works fine on the first enemy.. sometimes xD?

Re: Problem with multiple enemies and hp bars

PostPosted: Mon Apr 01, 2013 9:35 am
by lcl
Are you using canvas actor clones?
If, you should know that all canvas actor clones share the same image,
you can't draw on just one of them. It's a bad limitation in GE. :|

Re: Problem with multiple enemies and hp bars

PostPosted: Mon Apr 01, 2013 4:49 pm
by Hblade
I'm using 1 canvas actor, each time an enemy is spawned it creates a new canvas (Which I assume works the same way as clones :( )

Re: Problem with multiple enemies and hp bars

PostPosted: Mon Apr 01, 2013 5:38 pm
by lcl
Yup, that is cloning, so doesn't work.

Here's a solution:

Use only one canvas same size as the screen
and use a for loop to go through the clones and draw
the hp bars over them based on their location and hp. :)

Re: Problem with multiple enemies and hp bars

PostPosted: Mon Apr 01, 2013 7:16 pm
by Hblade
WOW thanks! That'd also be a lot faster with drawing! This is the game I wanted enemy HP bars over:

Re: Problem with multiple enemies and hp bars

PostPosted: Tue Apr 02, 2013 11:27 am
by lcl
I'm glad I could be of help to you. If you have problems implementing it, just tell me and I'll help.
I'm pretty sure you can manage, though. :D

Hey cool! The original game was awesome!
I'm interested of getting to play this one!! :D

Re: Problem with multiple enemies and hp bars

PostPosted: Tue Apr 02, 2013 3:15 pm
by Hblade
Thanks lcl! ^_^