Question

I have a cocos2d CCLayer class that has both CCSprites as well as UIButtons. I would like the player to be able to touch and drag the UIButtons around on the screen, when the finger is released I want to perform some action.

Here is the snippet of my code that creates UIButton and adds to the layer -

UIButton* button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setFrame:CGRectMake(240, 200, 50, 50)];

[[[[CCDirector sharedDirector] openGLView] window] addSubview:button]; 

[button addTarget:self action:@selector(buttonMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];

I am able to move the UIButton inside the cocos2d layer. My question is, how can I find out when the finger is released from the UIButton?

PS/ I read through Ray Wenderlich's tutorial on UIView in cocos2d as well as Learn Cocos2d Game Development by Steffen Itterheim but neither of them cover how to manage touches to the UIKit elements inside a CCLayer or so I think.

Was it helpful?

Solution

did you try using UIControlEventTouchUpInside/UIControlEventTouchUpOutside control events?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top