Is there a way to change a CCMenuItem object's graphic?
CCMenuItem change graphic?
(9 posts) (2 voices)-
Posted 1 year ago #
-
If you're referring to a
CCMenuItemSprite, then sure! You're in luck. It has a getter/setter for each of the sprites:normalImage,selectedImage, anddisabledImage.If you want to access them later when a menu has already been created it's as simple. CCMenus are nothing more than layers and menu items are just nodes. Tag the menu item you care about to fetch it later.
Posted 1 year ago # -
Oh, CCMenuItemSprite.. weird, I'm unable to access normalImage though.
Posted 1 year ago # -
You sure? Made a typo, maybe? :P
The following seems to work:
CCMenuItemSprite *thing = [CCMenuItemSprite itemFromNormalSprite:normalSprite1 selectedSprite:selectedSprite1]; [thing setTag:555]; CCMenu *menu = [CCMenu menuWithItems:thing, nil]; [self addChild:menu]; [(CCMenuItemSprite*)[menu getChildByTag:555] setSelectedImage:selectedSprite2];Posted 1 year ago # -
... Typo >____>
Thanks, now the image changes!
Now I got a small problem:The new image I'm trying to give is this:
tmp2 = [CCSprite spriteWithSpriteFrameName:@"NO.png"];But instead of changing to the NO.png graphic, the button changes to... a completely different graphic, or even nothing... or crashes...
[(CCMenuItemSprite*)[menu getChildByTag:1] setNormalImage:tmp2];Then I used break points, and in that same line, sometimes it says "EXC_BAD_ACCESS".
When it doesn't say that, well, it changes to a random images or changes to nothing...Posted 1 year ago # -
ZOMBIES! Er, Instruments!
Launch Instruments and create an instrument from the Zombie template under the Simulator's memory section.
Select "Choose a Target" and select to either attach it to a process if you have the app running in the simulator, or choose your app as a target if you've ran it previously in the instruments tool.
Whenever you're ready, hit record and let it go for a few seconds. Afterwards, do the thing that causes it to crash. The allocations tool will give you a popup saying it found a Zombie (ARG! rawrrr!!!).
Click on the little icon arrow thingy at the end of the sentence, and you'll be directed to a list of everything that happened to the object from birth to being turned into the living dead. Look through the list and see where the ref count dropped to 0, then check where it turned into a Zombie with a ref count of -1. You can then double click on the event and be taken to the piece of code that caused it. Look around, and you'll see what's up :).
Most likely it's an over released object.. that you're trying to communicate to. You can't talk to zombies, silly.
I haven't used sprite framenames much, but if I remember correctly they caused me a whole headache of problems when I was trying out spritesheets. I switched over to
spriteWithFile:rectfor sprite sheet use and it's been heavenly :).Posted 1 year ago # -
Which template is supposed to be the "Zombie Template"? I used both object allocations and leaks, and none of them gave me a message... I will be doing more checks.
EDIT: Nnnngh... you were right... it was a zombie.. >__> How can you be.. always right >.<
It seems this sprite was auto released.. I retained it, and now it works wonderfully.Thanks, this is valuable experience for me :D
By the way, you said spriteWithSpriteFrameName was not very good for you? How exactly? I though it was the... somehow best way when you had many sprites =/
Posted 1 year ago # -
*shrugs* If you were wrong, therefore everyone else was right? Right?
I don't know. I tried sprite sheets as the first thing when I started Cocos2D and it scared me. Had nightmares from all of the crashes for nights ahead. Probably because I didn't know what I was doing then as I haven't used Objective-C in years. You're probably more than fine to use them ;). I was just kiddin'.
Posted 1 year ago # -
Nnnngh... you were right again >__>... wait.... ugh, nevermind. Thanks.
Posted 1 year ago #
Reply
You must log in to post.