(Solved)help with draw text behavior on enemies

hey can anyone help me with a behavior. im trying ti draw text over enemy actor that displays his health the health says HP10 when he is hit and decrements by -1when he is hit. when he reaches zero he is killed

so far  i can draw the text and kill the enemy actor when his hp reaches zero. the problem is i want the HP to appear when he is hit at x of self the text fades disappears. another problem is i need it to only happen on the actor that is hit. for some reason it spawns on all the actors that are the same type. i just need a little help. here is a snap shot of what i mean  you can see the blue text on the right. thanks

« Last Edit: June 09, 2013, 04:05:56 pm by therealistone2003 »

Meestar

  • Posts: 654
Hi, hope I can help!

In this case, you should use a separate actor to display the damage.  In the code where the actor is hit, create the damage actor.  This should be the code on the damage actor:

When Created:
Set Y-Speed for self to -1
Set opacity (attribute) to 100
Do Every .1 seconds
  if opacity > 0
     decrement opacity (attribute) by 2
  else
     kill self
     cancel

When Drawing:
(Draw Code Block)Set Opacity to <opacity (attribute)> %
Draw Text damage at x, y

Then you can either use a custom block to set the damage display (info on custom blocks can be found in Stencylpedia) or you can use the for actor set attribute in behavior block that Stencyl provides.  That block would go right after you create the damage display actor.
PM me if you require help.  I'm always glad to help out!

ok  i really appreciate your help. so let me clarify. when  you say i need to create a separate damage actor im no sure what you mean. are you saying the actor that i want to damage in a when created block

 Set Y-Speed for self to -1
Set opacity (attribute) to 100
Do Every .1 seconds
  if opacity > 0
     decrement opacity (attribute) by 2
  else
     kill self
     cancel

 what do you mean by (ELSE)

 i understand the drawing part also do i need a game attribute or a local.
let me show you what i have. sorry i dont understand i have gotten far with the coding but i still have many many miles to go.

Meestar

  • Posts: 654
ok  i really appreciate your help. so let me clarify. when  you say i need to create a separate damage actor im no sure what you mean. are you saying the actor that i want to damage in a when created block

 Set Y-Speed for self to -1
Set opacity (attribute) to 100
Do Every .1 seconds
  if opacity > 0
     decrement opacity (attribute) by 2
  else
     kill self
     cancel

 what do you mean by (ELSE)

 i understand the drawing part also do i need a game attribute or a local.
let me show you what i have. sorry i dont understand i have gotten far with the coding but i still have many many miles to go.

Sorry, I've been doing a lot of non-Stencyl programming lately.

When I say separate damage actor, I mean go into your actor tab and create a blank actor, which will be used to display the damage.  When I said ELSE, that's the programming equivalent of the OTHERWISE block in Stencyl.

The attributes I mentioned should be local attributes, not Global, meaning that they are to be created through the behavior's attribute tab.

I hope I've cleared things up.
PM me if you require help.  I'm always glad to help out!

yes sir you surely have cleared it up and its much appreciated. im going to give it try. i never thought about the blank actor thing. interesting.

Meestar

  • Posts: 654
yes sir you surely have cleared it up and its much appreciated. im going to give it try. i never thought about the blank actor thing. interesting.

Yes, far more effective than drawing it on the damaged actor, in my opinion.  Glad I could help.
PM me if you require help.  I'm always glad to help out!

thanks got it working.