Wednesday, December 11, 2013

CoCos2d-x to add custom listener CCSprite subclass

If that, I want to customize a class inherits from CCSprite, just listen out of this class is instantiated object (I was in a Layer four years together instantiated object), I would like to rewrite its Touch events, but check some related Information is not always time to touch these objects successfully registered, do not know what steps are required during this period, the following is the code I touch event registration:
class MyOption: public cocos2d :: CCSprite, CCTargetedTouchDelegate
{
void onEnter () {
CCSprite :: onEnter ();
CCLog ("% s", "Ready for your register");
CCDirector :: sharedDirector () -> getTouchDispatcher () -> addTargetedDelegate (this, -100, true); / / program will be blocked here, I do not know why, if the program does not remove this sentence blocking object of this class, but still can not touch the listener event
CCLog ("% s", "Register is over");
}
void onExit () {
CCDirector :: sharedDirector () -> getTouchDispatcher () -> removeDelegate (this);
CCSprite :: onExit ();
};
/ / Listen for the first time, the triggering event
bool ccTouchBegan (CCTouch * pTouch, CCEvent * pEvent)
{
CCLog ("% s", "zzzzzzzzzzz");
CCLog ("% s", this-> getTitle ());
return true;
}
/ / Listen for movement events
void ccTouchMoved (CCTouch * pTouch, CCEvent * pEvent)
{
CCLog ("% s", "zaaaaaaa");
CCLog ("% s", this-> getTitle ());
}
/ / Listen to leave the event
void ccTouchEnded (CCTouch * pTouch, CCEvent * pEvent)
{
CCLog ("% s", this-> getTitle ());
}
void ccTouchCancelled (CCTouch * pTouch, CCEvent * pEvent) {

}
}
Another problem is that when I want to click on objects of this class is to make a poker flop effects, such as Dungeons clearance flop every incentive to get the kind of results (click Solitaire, Solitaire flip 90 degrees, then CCSprite in the picture replaced by another image, continue to invert 90 degrees, the last stop) Do not tell me the rotation together with two elves, adjust transparency, I am here not practical: an object inside my CCSprite not a simple picture, but there are a few elves; 2 This wizard has a completely transparent where you can see the background image, if to do so would be difficult to see disappear before another one can not see.

No comments:

Post a Comment