cocos2d-x 旅程開始--(實現單擊與長按)
阿新 • • 發佈:2019-01-27
if (turnLeftx->boundingBox().containsPoint(pTouch->getLocation())) //點選處座標在左轉按鈕區域中(這裡末尾加分號的話,會導致點哪裡都左移的情況)
{
turnLeft->setVisible(true); //背景按鈕顯現
turnLeftx->setVisible(false); //上層左轉按鈕消失
boolleft = true; //在update中判斷運動方向
this->schedule(schedule_selector(HelloWorld::update),0.1f); //使用schedule每隔0.1秒執行一次update
}
if (reallyMoved == false) //如果執行了update,reallyMoved會設為true
{ //如果沒執行,就實現點選一下就移動一次
player_1->setRotation(-90); //player_1圖片左轉90度
CCPoint origPo = player_1->getPosition(); //獲得player_1原始的座標
CCPoint newPo = origPo - ccp(10, 0); //設定新的座標,左移10個畫素
newPo.x = newPo.x > 30 ? newPo.x : 30; //如果跑到螢幕邊緣就動了,player_1為30*30
player_1->setPosition(newPo);
}
return true;
{
turnLeft->setVisible(true); //背景按鈕顯現
turnLeftx->setVisible(false); //上層左轉按鈕消失
boolleft = true; //在update中判斷運動方向
this->schedule(schedule_selector(HelloWorld::update),0.1f); //使用schedule每隔0.1秒執行一次update
}
if (reallyMoved == false) //如果執行了update,reallyMoved會設為true
{ //如果沒執行,就實現點選一下就移動一次
player_1->setRotation(-90); //player_1圖片左轉90度
CCPoint origPo = player_1->getPosition(); //獲得player_1原始的座標
CCPoint newPo = origPo - ccp(10, 0); //設定新的座標,左移10個畫素
newPo.x = newPo.x > 30 ? newPo.x : 30; //如果跑到螢幕邊緣就動了,player_1為30*30
player_1->setPosition(newPo);
}
return true;