你好,歡迎來到IOS教程網

 Ios教程網 >> IOS訊息 >> 關於IOS >> cocos2d

cocos2d

編輯:關於IOS

//讓當前圖層實現觸摸

this->setTouchEnabled(true); // 覆蓋cclayer中注冊觸摸分發器 voidFishGame::registerWithTouchDispatcher() {     CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,INT_MIN,false); } voidFishGame::gamelogic(float t){    CCSprite * nowplayer=(CCSprite *)this->getChildByTag(999);     nowplayer->setPositionX(nowplayer->getPositionX()+20);    if (nowplayer->getPositionX()>500) {         nowplayer->setPositionX(0);//當人物走出屏幕時再回到原點     }     nowplayer->setPositionY(nowplayer->getPositionY()+20);    if (nowplayer->getPositionY()>300) {         nowplayer->setPositionY(50);     }  }    boolFishGame::ccTouchBegan(CCTouch *pTouch,CCEvent *pEvent){    CCPoint p=pTouch->getLocation();    CCSprite *nowplayer=(CCSprite *)this->getChildByTag(999);     //nowplayer->setPosition(p);     nowplayer->runAction(CCMoveTo::create(0.5, p));    CCLog("按下 %f,%f",p.x,p.y);     return true; } voidFishGame::ccTouchMoved(CCTouch *pTouch,CCEvent *pEvent){    CCPoint p=pTouch->getLocation();    CCSprite *nowplayer=(CCSprite *)this->getChildByTag(999);     nowplayer->setPosition(p);         CCLog("移動到 %f,%f",p.x,p.y); } voidFishGame::ccTouchEnded(CCTouch *pTouch,CCEvent *pEvent){    CCPoint p=pTouch->getLocation();    CCLog("抬起 %f,%f",p.x,p.y); }
  1. 上一頁:
  2. 下一頁:
蘋果刷機越獄教程| IOS教程問題解答| IOS技巧綜合| IOS7技巧| IOS8教程
Copyright © Ios教程網 All Rights Reserved