cocos2d rox! it seems really easy even for someone (like me) who's
also learning python. I'm trying to familiarize myself w/ the lib and
ran into some really newbie-ish questions about layers

below is a sample doodle. My questions are:
  - can I make adjust a layers size other than using scale?
      - how did you find that answer in: http://cocos2d.org/doc/api/
  - is it possible to apply actions (like
cocos.actions.grid3d_actions.Ripple3D()) to just a layer?
  - how can I always assure that child objects to a layer have their
0,0 set to the lower left corner of the layer (or is this just the
default)?

--timball

#!/usr/bin/python
#
# 10.py
#
# $Id$
#

import cocos
import pyglet

class background(cocos.layer.Layer):
    """
        load an image... that's about it.
    """
    def __init__(self):
        super(background, self).__init__()
        self.image = pyglet.resource.image('w-640-480.png')

    def draw(self):
        self.image.blit(0,0)


class text(cocos.layer.Layer):
    """
        words (for inside boxes)
            + words = string
            + pos = (x,y) : of words
    """
    def __init__(self, words, pos):
        super(text, self).__init__()
        x,y = cocos.director.director.get_window_size()

#        self.text = cocos.text.HTMLLabel("<font size=50 color=white>
%s<i>!</i></font>" % (word), (x/2, y/2)) ## size doesn't work XXX
        self.text = cocos.text.Label("%s!" % (words),
                                     font_name='Arial',
                                     font_size=32,
                                     x=0, y=0)
        self.text.position = pos
        self.text.do(cocos.actions.ScaleTo(2.5, .250))

        self.add( self.text )


class red(cocos.layer.Layer):
    """
        a box near the bottom of the screen
        adjust width?
    """
    def __init__(self):
        super(red, self).__init__()

        # full size of root window
        self.scale = 0.25
        self.position = (0,-200)
        x,y = cocos.director.director.get_window_size()
        print "red (x,y) : (%s,%s)" % (x,y)

        self.color = cocos.layer.ColorLayer (255, 0, 0, 255)
        self.color.x = -10
        self.add(self.color)

        self.add( white(0.9) )

class white(cocos.layer.Layer):
    """
        a box to put inside other boxes
            + scale =  0 < x < 1
    """
    def __init__(self, scale):
        super(white, self).__init__()

        self.scale = scale
        x,y = cocos.director.director.get_window_size()
        print "red (x,y) : (%s,%s)" % (x,y)

        self.color = cocos.layer.ColorLayer (255, 255, 255, 128)
        self.add(self.color)

        x = (200,100)
        self.add( text("thingies!", x) )

class peach(cocos.layer.Layer):
    """
        in the center
    """
    def __init__(self):
        super(peach, self).__init__()

        # full size of root window
        self.scale = 0.43
        self.position = (0,0)

        x,y = cocos.director.director.get_window_size()
        print "peach (x,y) : (%s,%s)" % (x,y)

        self.color = cocos.layer.ColorLayer (202, 175, 175, 255)
        self.add(self.color)

        x = (0,12)
        self.add( text("toy thingies!", x) )


class blue(cocos.layer.Layer):
    """
        left 50 transperent
    """
    def __init__(self):
        super(blue, self).__init__()
#        self.image = pyglet.resource.image('x-640-480.png')
#        self.image.scale = 0.5

        # full size of root window
        self.scale = 0.5

        x,y = cocos.director.director.get_window_size()
        print "blue (x,y) : (%s,%s)" % (x,y)

        # this seems silly, I should be able to just say box justify
left of parent layer
        self.position = ( (-x/4)+4, 0 )

        self.color = cocos.layer.ColorLayer (0,0,102, 128)
        self.add(self.color)

#    def draw(self):
#        self.image.blit(0,0)


if __name__ == "__main__":
    cocos.director.director.init(resizable=True)
    sc = cocos.scene.Scene()

    sc.add(background(), z=0)

    sc.add(blue(), z=10)
    sc.add(peach(), z=20)
    sc.add(red(), z=30)

    sc.do (
            cocos.actions.interval_actions.Delay(3) +

            cocos.actions.interval_actions.Delay(2) +
            cocos.actions.grid3d_actions.Ripple3D( grid=(32,24),
waves=7, duration=5, amplitude=100, radius=320) +
            cocos.actions.basegrid_actions.StopGrid() +

            cocos.actions.interval_actions.Delay(2) +
            cocos.actions.grid3d_actions.FlipX3D(duration=1) +
            cocos.actions.interval_actions.Delay(.75) +
            cocos.actions.basegrid_actions.StopGrid() +

            cocos.actions.interval_actions.Delay(2) +
            cocos.actions.tiledgrid_actions.JumpTiles3D( jumps=2,
duration=4, amplitude=80, grid=(16,12) ) +
            cocos.actions.basegrid_actions.StopGrid() +


            cocos.actions.interval_actions.Delay(2) +
 
cocos.actions.basegrid_actions.AccelAmplitude(cocos.actions.grid3d_actions.Waves(
 waves=8,
amplitude=50, grid=(32,24), duration=5), rate=2.0) +
            cocos.actions.basegrid_actions.StopGrid()

            )

    cocos.director.director.run(sc)

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