Problem with multiple enemies and hp bars

Non-platform specific questions.

Problem with multiple enemies and hp bars

Postby Hblade » Mon Apr 01, 2013 4:56 am

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?
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Problem with multiple enemies and hp bars

Postby lcl » Mon Apr 01, 2013 9:35 am

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. :|
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Problem with multiple enemies and hp bars

Postby Hblade » Mon Apr 01, 2013 4:49 pm

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 :( )
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Problem with multiple enemies and hp bars

Postby lcl » Mon Apr 01, 2013 5:38 pm

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. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Problem with multiple enemies and hp bars

Postby Hblade » Mon Apr 01, 2013 7:16 pm

WOW thanks! That'd also be a lot faster with drawing! This is the game I wanted enemy HP bars over:
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score

Re: Problem with multiple enemies and hp bars

Postby lcl » Tue Apr 02, 2013 11:27 am

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
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Problem with multiple enemies and hp bars

Postby Hblade » Tue Apr 02, 2013 3:15 pm

Thanks lcl! ^_^
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron