FreshRSS

Zobrazení pro čtení

Jsou dostupné nové články, klikněte pro obnovení stránky.

Counting multiple touches using Cocos2dx 3.2

I'm trying to count the number of active touches in screen in order to perform an an action in case that there are two touches:

auto jumpListener = EventListenerTouchAllAtOnce::create();
    jumpListener->onTouchesBegan = [=](const std::vector<Touch*>& touches, Event* event)
    {
        CCLOG("Multi-touch detected %d", touches.size());
        if(touches.size() == 2)
        {
            this->_player->jump();
        }

    };

But even if I'm touching with two fingers, I get that only 1 touch has been made, any suggestions?

Physics bodies randomly losing Velocity along an axis after impact

This just started occurring and seems to randomly happen during, and between, game sessions. A dynamic moving body collides with a static body and instead of bouncing off looses (almost completely) its Velocity along the collision's normal. This means the dynamic body starts moving along the static body's surface it just collided with, and is most noticeable on the rare occasions it does a 90 degree turn upon hitting a second wall right ahead.

This behaviour is very erratic, and almost seems to come and go between builds with the same code on my content (although it could just be chance), so I'm wondering if it could be an issue with the cocos2d libraries?

For reference, the way I'm setting up these bodies:

For both types it starts with:

PhysicsBody *pawnBody = PhysicsBody::create();
PawnBody->setDynamic(true);
pawnBody->setContactTestBitmask(0xFFFFFFFF);
setPhysicsBody(pawnBody);

Then the static body code does:

myBody->removeAllShapes();
PhysicsShapePolygon *colPolygon = PhysicsShapePolygon::create(&spriteVertices[0], 4,
                                                     PhysicsMaterial(0.f, 1.f, 0.f));
colPolygon->setContactTestBitmask(0xFFFFFFFF);
myBody->addShape(colPolygon, false);
...
getPhysicsBody()->setDynamic(false);

And the dynamic body code does:

getPhysicsBody()->removeAllShapes();
PhysicsShapeCircle *circle = PhysicsShapeCircle::create((getScale() * 
                                                   mySprite->getContentSize().width) / 2,
                                                   PhysicsMaterial(0.f, 1.f, 0.f));
circle->setContactTestBitmask(0xFFFFFFFF);
getPhysicsBody()->addShape(circle);
...
myBody->setVelocityLimit(moveSpeed);
myBody->setDynamic(true);

I believe they are both set up correctly to achieve fully elastic collisions, and I'm sure this was working at some point through a slightly different flow (they didn't share the initial build code). Has anyone experienced any similar behaviour?

❌