Quantcast
Channel: Cocos Forums - Latest topics
Viewing all articles
Browse latest Browse all 17078

PhysicsWorld, window re-positioning, sprite disappears (looks like it went out of the edge body)

$
0
0

@sinoka56 wrote:

Hello, I'm currently using the physicsworld of cocos2d-x in a window 32 bit application, and I have a problem.

I have these codes :

auto scene = Scene::createWithPhysics();
scene->getPhysicsWorld()->setGravity(Vec2(0, 0));

auto edgeBody = PhysicsBody::createEdgeBox(visibleSize, PhysicsMaterial(1.0f, 1.0f, 1.0f), 3);
edgeBody->setCollisionBitmask(9);
edgeBody->setContactTestBitmask(true);
auto edgeNode = Node::create();
edgeNode->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2));
edgeNode->setPhysicsBody(edgeBody);
this->addChild(edgeNode);

ballSprite = Sprite::create("ball.png");
ballSprite->setPosition(visibleSize.width / 2, visibleSize.height / 2);
auto ballSpritePhysicsBody = PhysicsBody::createCircle(ballSprite->getContentSize().height / 2, 
	PhysicsMaterial(1.0f, 1.0f, 0.0f));
ballSpritePhysicsBody->setVelocity(Vec2(400, 400));
ballSpritePhysicsBody->setDynamic(true);
ballSpritePhysicsBody->setCollisionBitmask(1);
ballSpritePhysicsBody->setContactTestBitmask(true);
ballSpritePhysicsBody->setVelocityLimit(800);
ballSprite->setPhysicsBody(ballSpritePhysicsBody);
this->addChild(ballSprite);

when I don't re-position the window, the ball is fine it stays within the edge body bouncing around, but whenever I re-position the window where the ball is visually outside the edge body (the left mouse button is still pressed), the ball disappears / "escapes" the edge body.

I'm sorry if this was asked already before, as I do not know the term to look for.

Posts: 4

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 17078

Trending Articles