Skip to content

Instantly share code, notes, and snippets.

@DarkSector
Created August 28, 2016 00:29
Show Gist options
  • Select an option

  • Save DarkSector/7914309c73a4c98e42c5382869b2711c to your computer and use it in GitHub Desktop.

Select an option

Save DarkSector/7914309c73a4c98e42c5382869b2711c to your computer and use it in GitHub Desktop.
sprite test cocos2d python
import cocos
import pyglet
HEIGHT = 600
WIDTH = 800
DEBUG_FONT_SIZE = 11
class SpriteTest(cocos.layer.ColorLayer):
text_color = (0, 0, 0, 255)
def __init__(self):
super(SpriteTest, self).__init__(255, 255, 255, 255)
img = pyglet.image.load('../assets/sprites/obama_sprite.png')
sprite_x = (WIDTH/2) - (img.width/2)
sprite_y = (HEIGHT/2) - (img.height/2)
t1 = cocos.text.Label("Sprite X,Y @ %s %s" % (sprite_x, sprite_y),
position=(100, HEIGHT-100), font_size=DEBUG_FONT_SIZE,
color=self.text_color)
t2 = cocos.text.Label("World X, Y %s %s" % (WIDTH, HEIGHT),
position=(100, HEIGHT-100-DEBUG_FONT_SIZE-3),
color=self.text_color)
t0 = cocos.text.Label("Sprite Height:%s & Wdith:%s" % (img.height, img.width),
position=(100, HEIGHT - 100 - 2 * DEBUG_FONT_SIZE - 3),
color=self.text_color)
sprite = cocos.sprite.Sprite(img, position=(sprite_x, sprite_y))
self.add(sprite)
self.add(t0)
self.add(t1)
self.add(t2)
cocos.director.director.init(width=WIDTH, height=HEIGHT)
cocos.director.director.run(cocos.scene.Scene(SpriteTest()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment