2012-12-10 72 views
0

我試圖讓與的Cocos2D-X一個洛克人類遊戲,並試圖使其在Android設備上運行。 的事情是,我可以seperatly按下按鈕和whatsover有沒有問題,但是當我跑步時左/右,也按跳躍玩家停止移動。多點觸控不起作用

當我手動設置right = true和jump = true時,玩家向右跳躍看起來很漂亮,所以如果其他東西執行的很好。

這是我在的init()

 //add controls 
    buttonLeft = CCMenuItemImage::create(
     "button_left.png", 
     "button_left.png"); 
    buttonLeft->setPosition(ccp(buttonLeft->getContentSize().width/2, buttonLeft->getContentSize().height/2)); 

    buttonRight = CCMenuItemImage::create(
     "button_right.png", 
     "button_right.png"); 
    buttonRight->setPosition(ccp(buttonRight->getContentSize().width/2 + buttonLeft->getContentSize().width, buttonRight->getContentSize().height/2)); 
    CCMenu* controlMenu1 = CCMenu::create(buttonLeft, buttonRight, NULL); 
    controlMenu1->setPosition(CCPointZero); 
    this->addChild(controlMenu1, 1); 

    buttonJump = CCMenuItemImage::create(
     "button_jump.png", 
     "button_jump.png"); 
    buttonJump->setPosition(ccp(winSize.width - buttonJump->getContentSize().width/2, buttonJump->getContentSize().height/2)); 
    CCMenu* controlMenu2 = CCMenu::create(buttonJump, NULL); 
    controlMenu2->setPosition(CCPointZero); 
    this->addChild(controlMenu2, 1); 

做,我得到了這個計劃每0.02秒:

void BeginScene::updatePlayerMove(float dt) 
{ 
CCSize winSize = CCDirector::sharedDirector()->getWinSize(); 

int newYpos; 
int maxYpos; 
int minYpos; 

int newXpos; 
int maxXpos; 
int minXpos; 

if(buttonJump->isSelected() && !maxJumpReached){ 
    //jump 
    if(playerMoveAction != NULL){ 
     player->stopAction(playerMoveAction); 
     playerMoveAction = NULL; 
    } 

    if(playerJumpAction != NULL){ 
     player->stopAction(playerJumpAction); 
     playerJumpAction = NULL; 
    } 


    if(buttonLeft->isSelected()){ 
     player->setTexture(CCTextureCache::sharedTextureCache()->addImage("player2.png")); 
     minXpos = player->getContentSize().height/2; 
     newXpos = player->getPosition().x - PIXELS_PLAYER_MOVES; 

     if(newXpos < minXpos){ 
      newXpos = minXpos; 
     } 
    }else if(buttonRight->isSelected()){ 

    player->setTexture(CCTextureCache::sharedTextureCache()->addImage("player1.png")); 
     maxXpos = winSize.width - player->getContentSize().height/2; 
     newXpos = player->getPosition().x + PIXELS_PLAYER_MOVES; 

     if(newXpos > maxXpos){ 
      newXpos = maxXpos; 
     } 
    }else{ 
     newXpos = player->getPosition().x; 
    } 

    maxYpos = player->getContentSize().height/2 + closestGround + MAX_JUMP_HEIGHT; 
    newYpos = player->getPosition().y + PIXELS_PLAYER_MOVES; 

    if(newYpos > maxYpos){ 
     newYpos = maxYpos; 
     maxJumpReached = true; 
    } 


    CCPoint destination = ccp(newXpos, newYpos); 
    float lengthX = destination.x - player->getPosition().x; 
    float lengthY = destination.y - player->getPosition().y; 
    float length = sqrtf((lengthX * lengthX) + (lengthY*lengthY)); 
    float duration = length/DURATION_DIVIDER; 

    playerJumpAction = player->runAction(CCSequence::create(
     CCMoveTo::create(duration, destination), 
     CCCallFuncN::create(this, NULL), 
     NULL)); 

}else if(!buttonJump->isSelected() || maxJumpReached){ //basicly: if not jumping -> gravity will pull always) 
    //descent 
    if(playerMoveAction != NULL){ 
     player->stopAction(playerMoveAction); 
     playerMoveAction = NULL; 
    } 

    if(playerJumpAction != NULL){ 
     player->stopAction(playerJumpAction); 
     playerJumpAction = NULL; 
    } 


    if(buttonLeft->isSelected()){ 
     player->setTexture(CCTextureCache::sharedTextureCache()->addImage("player2.png")); 
     minXpos = player->getContentSize().height/2; 
     newXpos = player->getPosition().x - PIXELS_PLAYER_MOVES; 

     if(newXpos < minXpos){ 
      newXpos = minXpos; 
     } 
    }else if(buttonRight->isSelected()){ 

    player->setTexture(CCTextureCache::sharedTextureCache()->addImage("player1.png")); 
     maxXpos = winSize.width - player->getContentSize().height/2; 
     newXpos = player->getPosition().x + PIXELS_PLAYER_MOVES; 

     if(newXpos > maxXpos){ 
      newXpos = maxXpos; 
     } 
    }else{ 
     newXpos = player->getPosition().x; 
    } 

    minYpos = player->getContentSize().height/2 + closestGround; 
    newYpos = player->getPosition().y - PIXELS_PLAYER_MOVES; 

    if(newYpos < minYpos){ 
     newYpos = minYpos; 
     maxJumpReached = false; 
     jumpButtonPressed = false; 
    } 
    CCPoint destination = ccp(newXpos, newYpos); 
    float lengthX = destination.x - player->getPosition().x; 
    float lengthY = destination.y - player->getPosition().y; 
    float length = sqrtf((lengthX * lengthX) + (lengthY*lengthY)); 
    float duration = length/DURATION_DIVIDER; 

    playerDescentAction = player->runAction(CCSequence::create(
     CCMoveTo::create(duration, destination), 
     CCCallFuncN::create(this, NULL), 
     NULL)); 

}else if(buttonLeft->isSelected()){ 
    //left 
    minXpos = player->getContentSize().height/2; 
    newXpos = player->getPosition().x - PIXELS_PLAYER_MOVES; 

    if(newXpos < minXpos){ 
     newXpos = minXpos; 
    } 

    player->setTexture(CCTextureCache::sharedTextureCache()->addImage("player2.png")); 
    CCPoint destination = ccp(newXpos, player->getPosition().y); 
    float lengthX = destination.x - player->getPosition().x; 
    float lengthY = destination.y - player->getPosition().y; 
    float length = sqrtf((lengthX * lengthX) + (lengthY*lengthY)); 
    float duration = length/DURATION_DIVIDER; 

    playerMoveAction = player->runAction(CCSequence::create(
     CCMoveTo::create(duration, destination), 
     CCCallFuncN::create(this, NULL), 
     NULL)); 

}else if(buttonRight->isSelected()){ 
    //right 
    maxXpos = winSize.width - player->getContentSize().height/2; 
    newXpos = player->getPosition().x + PIXELS_PLAYER_MOVES; 

    if(newXpos > maxXpos){ 
     newXpos = maxXpos; 
    } 

    player->setTexture(CCTextureCache::sharedTextureCache()->addImage("player1.png")); 
    CCPoint destination = ccp(newXpos, player->getPosition().y); 
    float lengthX = destination.x - player->getPosition().x; 
    float lengthY = destination.y - player->getPosition().y; 
    float length = sqrtf((lengthX * lengthX) + (lengthY*lengthY)); 
    float duration = length/DURATION_DIVIDER; 

    playerMoveAction = player->runAction(CCSequence::create(
     CCMoveTo::create(duration, destination), 
     CCCallFuncN::create(this, NULL), 
     NULL)); 

} 

}

回答

0

看來,它只是不工作在我的舊LG,但完美的作品在我的銀河S2和平板電腦...

所以可能我的LG太舊了:P