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!