Мультитач не работает

Я пытаюсь сделать игру, подобную MegaMan, с Cocos2d-x и пытаюсь заставить ее работать на устройстве Android. Дело в том, что я могу нажимать кнопки по отдельности, и с этим проблем нет, но когда я бегу влево/вправо, а также нажимаю прыжок, игрок перестает двигаться.

Когда я вручную устанавливаю 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) );

}

}


person Big Dutchee    schedule 10.12.2012    source источник


Ответы (1)


Кажется, это не работает только на моем старом LG, но отлично работает на моем Galaxy s2 и планшете ...

так что, вероятно, мой LG слишком стар: P

person Big Dutchee    schedule 10.12.2012