show X percent of an image/actor?

KramerGames

  • Posts: 405
Is it possible to show a certain percent of an image or actor (using a variable)? Say for example I have a health bar that is red on the left and green on the right, with the colors blending into each other. If I were to use the "grow to" block it would look pretty bad. I would like to show always the full height but only x percentage of the width. Thanks

« Last Edit: December 08, 2016, 06:14:50 pm by KramerGames »
Parasites United  (Idle Parasite Game)

LIBERADO

  • *
  • Posts: 2718
<a href="http://static.stencyl.com/games/35672-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/35672-0.swf</a>

Use the Image API: http://www.stencyl.com/help/view/image-api
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

BMJ

  • Posts: 278
I think the easiest (and best looking) solution is to use a black colored actor on top of the health bar. Set its origin to the right and "grow" it from the right towards the left as your character's health is depleted, covering up more and more of the health bar. That way, the green disappears incrementally, you get to use your gradient, *and* you get to use easing on the black actor grow tween to make the change in health look slick and professional. All those benefits plus one more -- it's easy.

I think the only advantage that image API holds is that you could make the empty health bar space transparent.

KramerGames

  • Posts: 405
thanks to both of you!

@LIBERADO: Any chance you could tell me which code blocks you've used? I've been playing around with the image API with medium success. Furthermore the article says "Many of these operations, particularly pixel swap, effects and masks perform these operations in software, so they are not meant to be used in real-time but rather, applied sparingly." I'm a bit worried about that.

@BMJ: That would work fine in this case, but I would like the option of having the "background" of the bar not just black.
Parasites United  (Idle Parasite Game)

Natrium

  • *
  • Posts: 111
Personnally, I prefer when the entire bar is only one color, but that the color depends on the life remaining. If in full health, the entire bar is green, if in low health, the entire bar is red and if in mid health the entire bar is yellow.

You would achieve that by interpolating the RGB values according to the health percentage.

Well, that was just my two cents.

LIBERADO

  • *
  • Posts: 2718
I would like the option of having the "background" of the bar not just black.
I guess you mean this:
<a href="http://static.stencyl.com/games/35698-0.swf" target="_blank" class="new_win">http://static.stencyl.com/games/35698-0.swf</a>

I have attached the .stencyl file to this post. You can download it.
For good performance, don't use the code in a "when updating" event if you are testing it on mobile devices.
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

KramerGames

  • Posts: 405
Awesome, thanks! I wouldn't have come up with that myself, I'll try to learn more about the image API and play around with it.
Parasites United  (Idle Parasite Game)