On Sun, Jan 29, 2012 at 11:03 AM, Facundo Batista
<[email protected]>wrote:

> Hi!
>
> In a game I'm doing I have a background layer with an image, and a
> couple of layers above it with more stuff.
>
> I want, when the game starts, for the background image to be fully
> visible, and the rest of the images to slowly appear.
>
> An actions.FadeIn, I thought! But cocos.layer.Layer doesn't have an
> 'opacity' attribute.
>
> Is there a way to set a transparency to a whole layer?
>
> Thank you!!
>
> --
> .    Facundo
>


The easy but very limited use case is when the layer(s) you want to fade
are the first to be draw by the visit method; then you can do:

layer_to_fade -> the one you want to fade

fadeable = ColorLayer(0,0,0,255)
fadeable.add(layer_to_fade, z=-1)

Now fadeable has the attrib opacity, thus working with FadeIn - FadeOut
(the roles In - Out are reversed when looking from the layer_to_fade POV)
What we are doing here is painting with black and some alpha over the layer
to fade (yes, yes, its crude)

A working example is attached, put in the cocos\tests so resources are
found.

The general case will need to:
    . draw the layer to an FBO or texture
    . draw the FBO or texture(s) to the screen, with the appropriate alpha

Writing to FBOs can fail on some hardware (like the miserable Intel 945G I
have in this machine), writing to texture may need to consider limitations
in texture size for some hardware.

The practical approach would be to look at your concrete use case and write
for that particular use case.
By example, if your layer to fade is composed by some spites, I  would set
the opacity for layer's childs, maybe with a custom .visit() for the layer.

HTH

--
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.

Attachment: test_fade_layer.py
Description: Binary data

Reply via email to