could also draw a white rectangle using PIL
then using it to create a sprite
use that sprite .color to change the color.
something like
import Image
im = Image.new('RGBA', (600, 50), (255, 255, 255, 255))
im.save('from_pil/life.png')
...
class Life(Sprite):
def __init__(self):
super(Life, self ).__init__('from_pil/life.png')
self.colors = [(51, 198, 244), (248, 152, 29), (237, 32, 36)]
self.color = colors[0]
def update_color(self, v):
self.color = self.colors[v]
On Apr 9, 2:30 pm, claudio canepa <[email protected]> wrote:
> On Mon, Apr 9, 2012 at 5:30 AM, Ivo F.A.C. Fokkema
> <[email protected]>wrote:
>
>
>
>
>
>
>
>
>
> > Hi Pascal,
> > I had been dealing with that as well, and couldn't get any better than
> > this (indeed using ColorLayer, what Claudio already suggested):
>
> > [snip]
> > The bar nicely moves from green to orange to red, if the life of the
> > unit decreases. However, what I've been struggling with and couldn't
> > implement, is trying to change the width of the health bar. I couldn't
> > get that to work. If you find out how, I would be very grateful if you'd
> > tell me how :)
>
> > Good luck on your game!
>
> > Ivo
>
> A second look to ColorLayer shows that width and height changes after
> object creation don't change the vertexes associated to the object, so it
> isn't a good fit to a MetterBar.
>
> But that behavior can be added.
>
> Here a pastebin with two MetterBar versions, one done with plain old open
> GL inmediate mode, another by subclassing ColorLayer
>
> http://pastebin.com/2vDzW2JX
>
> claudio
>
> --
--
You received this message because you are subscribed to the Google Groups
"cocos2d discuss" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/cocos-discuss?hl=en.