TOUR
PRICING
HELP
Stencylpedia
Blocks Guide
Sample Games
Developer Center
FORUMS
CHAT
#MADEINSTENCYL
EDUCATION
SIGN IN
×
Welcome back!
Username or E-mail
Password
(
Forgot?
)
C
OMMUNITY
Home
Issue Tracker
Inbox [0]
New Posts
New Replies
Search
Stencyl Community
→
Stencyl
→
Ask a Question
→
show X percent of an image/actor?
Pages:
1
show X percent of an image/actor?
KramerGames
Posts: 405
December 08, 2016, 04:29:01 pm
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: 2720
December 08, 2016, 06:35:33 pm
http://static.stencyl.com/games/35672-0.swf
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
December 09, 2016, 09:48:19 am
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
December 09, 2016, 05:02:14 pm
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
December 09, 2016, 06:32:09 pm
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: 2720
December 11, 2016, 06:31:41 pm
Quote from: KramerGames on December 09, 2016, 05:02:14 pm
I would like the option of having the "background" of the bar not just black.
I guess you mean this:
http://static.stencyl.com/games/35698-0.swf
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
December 12, 2016, 05:08:04 am
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)
Pages:
1