Hi guys
I'm creating a game where i have some sprites moving up the screen. How do i detect when a user touches these sprites?
hope u can help me
kind regards
Lasse P
A fast, easy to use, free, and community supported 2D game engine
Hi guys
I'm creating a game where i have some sprites moving up the screen. How do i detect when a user touches these sprites?
hope u can help me
kind regards
Lasse P
Great! just what i needed to sort this thing out :]
Thanks alot!
Basically just derive your own sprite class from CCNode:
@interface mySprite : CCNode <CCTargetedTouchDelegate>
{
CCSprite *_mySprite;
}
And add the methods for the <CCTargetedTouchDelegate> protocol (register for touches):
- (void)onEnter
{
[[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self
priority:0 swallowsTouches:YES];
[super onEnter];
}
- (void)onExit
{
[[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
[super onExit];
}
Then use ccTouchBegan and ccTouchEnded.
Regards,
Steve
You must log in to post.