tags:

views:

154

answers:

2

i am using cocos2d to develop a game, now have a sprite loaded from image, and i would like to draw something on it like square? how can i do that?

A: 

You can subclass the Sprite class and override the draw method.

OscarMk
+1  A: 

This is what I would do:

  1. Create a new CocosNode class. Call it CustomDrawNode
  2. in the draw method of that class I would use drawline to draw what I need.
  3. In the GameScene where you init your sprite, also init an instance of your CustomDrawNode.
  4. Add it to the scene with: [self addChild:myCustomDrawNode z:1000 tag:999]. Use a higher z than the sprite.
  5. Move your instance of CustomDrawNode to the same position as the sprite.
Mattias Akerman
You may want to add it as a child of the sprite.
hudsonb