function update(self, dt)
go.animate("#sprite", “scale.x”, go.PLAYBACK_ONCE_FORWARD, boss_health/250, go.EASING_LINEAR, 0)
end
The health bar works fine for 95% of the way, but at the final stretch, it seems to suddenly become partially transparent and it stretches in the y direction. Why is this?
Not sure why it would stretch along Y, but blurry/transparent is likely because of the linear texture filtering. You can replace it with nearest filtering.
Ideally you would want a simple shader, that based on an external param would display only a portion of the surface. I’ve made one for StarClick
If it’s a part of your user interface, why don’t you want to try to make it in gui? There is a clipping possibility (or you can use your approach as well, but even with 9 sliced images) and it is very convenient to make health bars
And go.animate() shouldn’t be called inside update() function, it should be called only once when the health value is changed, but in your example you are calling it on every frame. Somehow that can mess things up.
Move it into on_message() function for instance and do msg.post() when a hit happens.
I have no clue how to share projects, so here is the health bar, centred on one side, so you can replicate the problem. First make the stuff from linear to nearest in graphics. Scale it manually in the x direction, maybe around 0.01 and see what happens when it is run.
Instead of stretching a texture another option is to clip the XP bar by another node. Then you can have the clipped texture have special detail over it as well. There should be an example in this project
Another thing we commonly do in our games is to use 9patch for progress bars which repeat horizontally. You set a texture to 9 patch and then only set the first value to be whatever the width of the small base texture is. Then you can size that node to however wide you need and it will look nice.
I scaled it upwards since that seemed like the easiest option and it worked beautifully. Thanks everyone, though I still don’t know why it behaved like it did.