Buttons

This topic contains 2 replies, has 2 voices, and was last updated by  Eternity 1 year, 5 months ago.

Viewing 3 posts - 1 through 3 (of 3 total)
Author Posts
Author Posts
November 10, 2012 at 6:28 pm #245240

Eternity
Participant
@eternity

I want a buttons with the following characteristics:

- A callback shall be called when the button is pressed

- Another callback, triggering the actual event, shall be called when the button is released (if the button was pressed in a correct manner).

I tried to do this with a CCHoldableMenuItemSprite that I found on the net, but now I realize that I cant provide the normal callback selector. Only two blocks, one that is triggered when the button is pressed, and another that is triggered when the button is released, but also when the finger glides off the button (Sic!).

If someone would take a minute to guide me in the right direction I would be more than happy. I really don’t need the full CCMenu functionality (alignments etc), so in my attempts I just added one CCHoldableMenuItemSprite to a CCMenu and made that ccMenu an attribute of a Button class that inherited from CCNode. Maybe there’s a better way. Tell me how you would do it. I’m tired, and have lost time :/

November 10, 2012 at 6:54 pm #391900

cocos
Participant
@cocos

@Eternity It is very easy to have a custom button to do whatever you like. CCMenu could be use for that but I would not go that way.

One of the beautiful solutions is presented by Peter Mares. (BTW. Check out his free game as well.) Check his solution! You can extend it and modify it for your needs.

Code is small, easy to understand and really shows how much flexibility one can have.

This is the link:

http://blog.petermares.com/2010/12/29/cocos2d-iphone-a-basic-button-class/

Feel free to ask any follow up questions if needed.

November 10, 2012 at 7:14 pm #391901

Eternity
Participant
@eternity

Ah! Wonderful. Thanks @cocos!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.