0

how could I tweak CCMenuItemSprite to support only one sprite?

Currently I have:

[CCMenuItemSprite itemWithNormalSprite:one selectedSprite:selectedOne] 

But would like to have:

[CCMenuItemSprite itemWithNormalSprite:one] 

EDIT: I want to modify CCMenuItem to work only with one CCSprite and not two. So I need to change also the internal methods.

mm24
  • 9,280
  • 12
  • 75
  • 170

3 Answers3

1

You can just use the same (normal) sprite as the selected sprite. When clicked, the button will then do nothing.

anon_dev1234
  • 2,143
  • 1
  • 17
  • 33
  • yeah but I is not neat, the two sprites have different beheaviour and animations and include some touchable items – mm24 Mar 13 '13 at 17:17
  • @mm24 I am not understanding the question well then. You said you only wanted to support one sprite for a `CCMenuItem`. However, the methods need to support both unselected and selected sprites. Are you using the menu in another way? – anon_dev1234 Mar 13 '13 at 17:30
  • Added an edit, I need to change the code of CCMenuItem but wanted to have some quick hints before.. I will post my attempt soon. – mm24 Mar 13 '13 at 18:04
  • @mm24 I think your undertaking to modify the code is not the best solution. FYI cocos2D caches textures in memory - so providing the same image as the selected does not add a second sprite. I guess I am confused about exactly what you are trying to accomplish that could only need one sprite when this works just as well and is simple – anon_dev1234 Mar 13 '13 at 18:08
1

You could just use

[CCMenuItemSprite itemWithNormalSprite:one selectedSprite:one]

this way, nothing would happen when you select the sprite

David
  • 1,898
  • 2
  • 14
  • 32
  • yeah but I is not neat, the two sprites have different beheaviour and animations and include some touchable items – mm24 Mar 13 '13 at 17:16
0

try this, just change colour of seleted sprite.

CCSprite *sprite1   = [CCSprite spriteWithFile:@"Button.png"];
CCSprite * sprite2  = [CCSprite spriteWithFile:@"Button.png"];
sprite2.color = ccc3(128, 128, 128);

CCMenuItemImage *itemEasyLevelImage = [CCMenuItemImage  itemWithNormalSprite:sprite1
                                                              selectedSprite:sprite2
                                                                       block:^(id sender){}];
Guru
  • 21,652
  • 10
  • 63
  • 102
  • 1
    That's not what I need to do, I wanted to use only one Sprite :) and not have 2 sprites :) – mm24 Mar 13 '13 at 18:02
  • ok..that's gud idea..One thing is even if u create 2 sprite with same image then cocos2d just creates single openGL texture and loading of this happens only once. So I can say you just targeting fraction's of fractional memory and time :P – Guru Mar 13 '13 at 18:29