I am trying to have a solid colored sprite (red, blue, etc) look like it is lighted up when it is touched. I am searched through the forums and documentation but haven't found anything that sounded like it would work. Can anyone provide a suggestion of how to accomplish this?
How to make sprite look like it is lighted up when touched
(8 posts) (6 voices)-
Posted 2 years ago #
-
By far the easiest way to do this is to create a new sprite image in photoshop (or whatever) and set the "glowing" texture when your sprite is selected.
You could also just tint the sprite to a different color, but I still think having a completely different image is the way to go.
Posted 2 years ago # -
do you happen to have a code example? or a link to the documentation for how I would accomplish this?
Posted 2 years ago # -
I agree with liquidchaz.
You either need to prepare a entire new sprite on your sheet, and the do this:
[sprite setTextureRect:CGRectMake(128,416, 128, 128)];
This makes the sprite change to that rect from its last rect position.
Another option is creating overlays which have transparencies but really that depends on what you need it to do. If you have 25 sprites and don't want to make 25 highlighted sprites, and the highlight is always the same, use an overlay.
Also, a child which is added to the sprite can perform actions such as fades etc.
Posted 2 years ago # -
I have 4-8 sprites that I need to do this too. Searching through the documentation it looks like I need to use an AtlasSprite and AtlasSpriteManager. Is this correct? Right now I am using just Sprite.
Posted 2 years ago # -
One option is to just create a menu with two image sprites. For the "selected" one, take the original one, blur the alpha channel then decrease the brightness to make a halo.
CCSprite *toolsIcon = [CCSprite spriteWithFile:@"toolIcon.png"]; CCSprite *toolsIconSelected = [CCSprite spriteWithFile:@"toolIconSelected.png"]; CCMenuItemSprite *toolsMenuItem = [CCMenuItemSprite itemFromNormalSprite:toolsIcon selectedSprite:toolsIconSelected target:self selector:@selector(onTools:)]; CCMenu *toolsMenu = [CCMenu menuWithItems:toolsMenuItem, nil]; [self addChild:toolsMenu];Posted 2 years ago # -
You can do the menu item suggested, but I have done the same thing you are thinking of, but I just created my own object, and it happened to be a menu object.
Basically you give it a state and change the state when you touch it. Make sure you handle the touches moved and flag it to stay changed when you touches ended is called.
Are you talking about a menu item?
I can give you some code examples if what I have done relates to yours, but yeah, you'll want to use atlas sprites and the atlas manager, so read up on that. From there you will want to set setTextureRect like napierzaza suggests.
My menu items highlight when you touch them, and if you move off of them, they go back, then when you have it highlighted and you let go (take your finger off) it will select that option. If that's what you want, let me know and I will give a code example. If not, it's easy. In your touches ended, change the atlas sprite like napierzaza suggested.
Posted 2 years ago # -
I would recommend what has been mentioned above, using different images for a menu. However an alternative (that is less flashy) would be to use 'TintTo' to change the color of a graphic. That way if you wanted many different colors you wouldn't have to have many different images. Here is an example of the result when I did this last year with a greyscale image:
http://dothemeep.blogspot.com/2009/07/meeps-color.html
Let us know how it goes!
Posted 2 years ago #
Reply
You must log in to post.