Well now I have a problem! I have both my images (one sheet for the player 
moving left and one for right (I'd like to have it this way)), but both of 
them draw... and only draw. The animation doesn't play. Is there a way I 
can make it so an image wont draw in Cocos unless I set it to, and also to 
stop/start an animation when I want too? If you want *all* my code:

import cocos, pyglet

windowWidth = 800
windowHeight = 600

title = "Mr. BallGuy"

class Player(cocos.cocosnode.CocosNode):
    def __init__(self):
        self.x = 100
        self.y = 100
        self.w = 32
        self.h = 32

        self.playerSheetLeft = 
pyglet.image.load("assets/img/playerLeft.png")
        self.playerSheetRight = 
pyglet.image.load("assets/img/playerRight.png")

        self.playerLeftGrid = pyglet.image.ImageGrid(self.playerSheetLeft, 
1, 1, item_width=32, item_height=32)
        self.playerRightGrid = 
pyglet.image.ImageGrid(self.playerSheetRight, 1, 1, item_width=32, 
item_height=32)

        self.playerLeftTexture = 
pyglet.image.TextureGrid(self.playerLeftGrid)
        self.playerRightTexture = 
pyglet.image.TextureGrid(self.playerRightGrid)

        self.playerLeftAnim = 
pyglet.image.Animation.from_image_sequence(self.playerLeftTexture, .32, 
loop=True)
        self.playerRightAnim = 
pyglet.image.Animation.from_image_sequence(self.playerRightTexture, .32, 
loop=True)

player = Player()

class Playing(cocos.layer.Layer): 
    def __init__(self): 
        super(Playing, self).__init__() 

        player.playerLeft = cocos.sprite.Sprite(player.playerLeftAnim)
        player.playerRight = cocos.sprite.Sprite(player.playerRightAnim)

        player.playerLeft.position = player.x, player.y

        self.add(player.playerLeft, name="playerLeft")
        self.add(player.playerRight, name="playerRight")

if __name__ == '__main__':
    cocos.director.director.init(windowWidth, windowHeight, 
resizable=False, vsync=False, caption=title) 

    playing = Playing() 

    playingScene = cocos.scene.Scene(playing) 

    cocos.director.director.run(playingScene) 


On Tuesday, October 15, 2013 6:38:12 PM UTC+1, Eamonn Rea wrote:
>
> Hi! I'm developing a game, and in my game I would like to have some sprite 
> sheet animation. It isn't uncommon for games to have sprite sheet 
> animation. I looked into it, and I couldn't find anything on it. So, I 
> decided to do a little DIY thing.
>
> I checked out PyGlet a little more and found the pyglet.image.Animation, 
> which took a list of pyglet.image.AnimationFrame objects, which took an 
> image, which I used cocos.sprite.Sprite() for. So, after a lot of testing, 
> I came up with this:
>
>         playerLeft1 = cocos.sprite.Sprite("assets/img/playerLeft1.png")
>         playerLeft2 = cocos.sprite.Sprite("assets/img/playerLeft2.png")
>         playerLeft3 = cocos.sprite.Sprite("assets/img/playerLeft3.png")
>
>         playerRight1 = cocos.sprite.Sprite("assets/img/playerRight1.png")
>         playerRight2 = cocos.sprite.Sprite("assets/img/playerRight2.png")
>         playerRight3 = cocos.sprite.Sprite("assets/img/playerRight3.png")
>
>         playerLeftFrame1 = pyglet.image.AnimationFrame(playerLeft1, .11)
>         playerLeftFrame2 = pyglet.image.AnimationFrame(playerLeft2, .11)
>         playerLeftFrame3 = pyglet.image.AnimationFrame(playerLeft3, None)
>
>         playerRightFrame1 = pyglet.image.AnimationFrame(playerRight1, .11)
>         playerRightFrame2 = pyglet.image.AnimationFrame(playerRight2, .11)
>         playerRightFrame3 = pyglet.image.AnimationFrame(playerRight3, None)
>
>         playerLeftAnimationList = [playerLeftFrame1, playerLeftFrame2, 
> playerLeftFrame3]
>         playerRightAnimationList = [playerRightFrame1, playerRightFrame2, 
> playerRightFrame3]
>
>         playerLeftAnimation = 
> pyglet.image.Animation(playerLeftAnimationList)
>         playerRightAnimation = 
> pyglet.image.Animation(playerRightAnimationList)
>
> I was very proud of myself for being able to do this, after having only 
> used Cocos2d for about 10-15 minutes. But sadly, when I went to run the 
> program, I got the following error:
>
> Traceback (most recent call last):
>   File "/Users/eamonn/Desktop/Programming/Python/Game 
> development/2D/Cocos/Mr. BallGuy/main.py", line 52, in <module>
>     director.run(helloScene) 
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/director.py",
>  
> line 371, in run
>     self._set_scene( scene )
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/director.py",
>  
> line 499, in _set_scene
>     scene.on_enter()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/scene.py",
>  
> line 110, in on_enter
>     super(Scene, self).on_enter()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/cocosnode.py",
>  
> line 519, in on_enter
>     c.on_enter()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/layer/util_layers.py",
>  
> line 89, in on_enter
>     super(ColorLayer, self).on_enter()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/layer/base_layers.py",
>  
> line 89, in on_enter
>     super(Layer, self).on_enter()
>   File 
> "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/cocos2d-0.5.5-py2.7.egg/cocos/cocosnode.py",
>  
> line 519, in on_enter
>     c.on_enter()
> AttributeError: 'Animation' object has no attribute 'on_enter'
>
> I'm not entirely sure why I would be getting this error. I mean, from what 
> I can tell it's looking through an Animation object and trying to find an 
> attribute called on_enter. I haven't did too much on attributes in Python, 
> but from what I can tell they're basically just userdata, right? It's just 
> an empty value that you can give to an object. To set an attribute you do 
> something like __setattr__ or something like that. I'm not new to Python, 
> but I've been learning so much of it over the past few days! :D
>
> Thanks for reading! Any help is appreciated!
>

-- 
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to