Search code examples
androidcocos2d-android

Draw a frame outside the sprite to produce a select effect in Cocos2D Android


I have a view which can contain multiple sprites at a time, now i want to have a select effect when ever i touch a sprite. Some Usefull/helping links would be very helpfull.


Solution

  • I see two ways:

    1. To change the sprite with selected version (make original sprite invisible and show selected).

    2. Create a frame sprite (possibly from multiple parts (add them to one parent)) and show it when you need to select the original sprite.

    SOME CODE

    CCNode *base = [CCNode node];
    CCSprite *original = [CCSprite node]; //change this to create your sprite
    [base addChild:original]
    
    CCNode *frameNode = [CCNode node];
    [base addChild: frameNode];
    [frameNode setVisible:NO];
    CCSprite *part1 = [CCSprite node]; //replace to create your part
    [frameNode addChild: part1];
    [part1 setAnchorPoint:. ...];
    [part1 setPosition: ...];
    [part1 setRotation: ...];
    //add more parts
    

    When your original sprite is selected:

    [frameNode setVisible: YES]; //you can also use some CCAction to make it appear more beautiful