This was my original plan, but I didn't think it was possible! Thanks! :-)

On Tuesday, October 15, 2013 7:55:33 PM UTC+1, Paul Pittlerson wrote:
>
> While it's hard to tell exactly what you are doing wrong without seeing 
> the rest of your code, there are a few things to point out right away.
>
> The idea of a sprite sheet is to have all your sprites in one single 
> image, and divide that image up into discrete sprites inside the program. 
> For example you could have something like this:
> http://s17.postimg.org/4mwxfrdob/running.png
>
> ..where all the images of player is combined in sequence. To access them 
> as an animation you have some options, but I'm quite sure you generally do 
> not want to hard code the animations frame by frame as you are doing. Try 
> something like this:
>
> #!/usr/bin/env python
>
> import cocos
> import pyglet
>
> # load the example running.png as a pyglet image
> spritesheet = pyglet.image.load('running.png')
>
> # use ImageGrid to divide your sprite sheet into smaller regions
> grid = pyglet.image.ImageGrid(spritesheet, 2, 2, item_width=48, 
> item_height=48)
>
> # convert to TextureGrid for memory efficiency
> textures = pyglet.image.TextureGrid(grid)
>
> # access the grid images as you would items in a list
> # this way you get a sequence for your animation
> PlayerRight = textures[:2]
> PlayerLeft = textures[2:4]
>
> # create pyglet animation objects from the sequences
> MovingRight = pyglet.image.Animation.from_image_sequence(PlayerRight, 0.2, 
> loop=True)
> MovingLeft = pyglet.image.Animation.from_image_sequence(PlayerLeft, 0.2, 
> loop=True)
>
> class Main(cocos.layer.Layer):
>     def __init__(self):
>         super(Main, self).__init__()
>       
>         # finally, create a cocos sprite which you can add/remove from 
> layers
>         player_move_right = cocos.sprite.Sprite(MovingRight)
>         player_move_right.position = 100, 100
>         
>         self.add(player_move_right, name='player')
>
> if __name__ == '__main__':
>
>     width, height = 200, 200
>     cocos.director.director.init(width, height, 
> do_not_scale=True,vsync=False)
>     cocos.director.director.run(cocos.scene.Scene(Main()))
>

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