3

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.

CodeSmile
  • 64,284
  • 20
  • 132
  • 217
Farhan
  • 13,290
  • 2
  • 33
  • 59

1 Answers1

1

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
Andrew
  • 24,218
  • 13
  • 61
  • 90
  • hmmm... second one looks good but as i am a newbie in cocos, a little code would help a lot... – Farhan Oct 14 '11 at 23:15
  • Ok thanx for the edit. but 2 issues: first i was talking about in android and second is, i dont think we can give custom width and height in setContentSize() because it just dont have any effect.... – Farhan Oct 17 '11 at 08:24
  • @Farhan: I've said nothing about setContentSize(). Did not notice 'andoroid'. I think you can easily rewrite this code for android – Andrew Oct 17 '11 at 10:02
  • rewriting is what i have been doing since i started on cocos in android... anyways, actually, i cant have frame for every sprite, so i created a frame of 100x100 and was hoping to resize it to the selected sprite's size and then add it to layer... – Farhan Oct 17 '11 at 10:58
  • @Farhan: to set the sprite size you can set it's scale: [sprite setScaleX: 100 / sprite.contentSize.width]. – Andrew Oct 17 '11 at 11:02
  • After scaling, if i get the size, it shows me same size as before scaling... do i have to do anything else??? i was reading somewhere about the use of updateTransform function, documentation says that it updates the quad after doing scaling/rotating etc... And much much thanx for your help – Farhan Oct 17 '11 at 11:17
  • @Farhan: Write your own function to get the size: x = sprite.contentSize.width * sprite.scale.x – Andrew Oct 17 '11 at 12:09
  • hmmm.. i guess we dont have anyother way... anyways much thanx. – Farhan Oct 17 '11 at 12:13