If anyone could clear something up it would be much appreciated.

I have a full screen sprite, made from a file over the top of a
Coloured layer, white. I thought if I reduced the opacity of the
sprite it would tend to white, or whatever colour I set the coloured
layer to.

Instead it tends to black?

If I have no sprite the layer is whatever colour I set it to.

Probably me but I thought I'd ask.

I'm using cocos2d-0.3.0rc0 and my test code is below.

Thanks in advance.

john

from cocos.layer import Layer, ColorLayer
from cocos.sprite import Sprite

class Slide(ColorLayer):

  def __init__( self, filename= None, a = 255, r = 255, g = 255, b =
255):
    super(Slide, self).__init__(r,g,b,a)
    self.BackgroundSprite = None

    if filename is None:
      self.BackgroundFilename = ""
    else:
      self.setBackground(filename, a)

  def setBackground(self, filename, alphaVal = 255):
    if self.BackgroundSprite is not None:
      # remove the current background
      self.remove(self.BackgroundSprite)

    self.BackgroundFilename = filename

    self.BackgroundSprite = Sprite( self.BackgroundFilename)

    # Must add the background image
    self.add(self.BackgroundSprite, z=10)

    # set the picture to the centre, this appears to be relative so
    # resizing the window keeps the picture in the centre, as well as
    # resizing it.
    self.BackgroundSprite.position = (self.width/2, self.height/2)

    self.setBackgroundOpacity(alphaVal)

  def setBackgroundOpacity(self, opacity):
    """Sets the opacity of the background layer

    Parameters
      opacity   0 means fully transparent, 255 mean fully opaque
    """
    if self.BackgroundSprite is not None:
      self.BackgroundSprite.opacity = opacity % 256

# basic test case
if __name__ == "__main__":
  from cocos.director import director
  from cocos.scene import Scene

  director.init(resizable=True)

  # Produces a Black screen
  #slide1 = Slide("components\\testData\\firePit.jpg", 0)

  # produce a white slide
  #slide1 = Slide()

  # puts the image in the windoe
  #slide1 = Slide("components\\testData\\firePit.jpg")

  scene1 = Scene( slide1 )
  director.run( scene1 )

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

Reply via email to