aliasghar
aliasghar

Reputation: 3

Why does Cocos2d-x not show the sprite the first time?

What is the problem? It does not show the sprite the first time.

playerSprite = Sprite::create("ip.png");
playerSprite->setPosition(Vec2(visibleSize.width/2,visibleSize.height));
    //this->addChild(playerSprite,1);
    auto body = PhysicsBody::createCircle
        (playerSprite->getContentSize().width / 2.5);
    body->setContactTestBitmask(true);
    body->setDynamic(true);
    playerSprite->setPhysicsBody(body);
    this->addChild(playerSprite,0);

Upvotes: 0

Views: 83

Answers (2)

ApDheeraj
ApDheeraj

Reputation: 101

Try Using Another Z-Order of your Sprite. this->addChild(playerSprite,TRY_WITH_SOME_LARGE_VALUE);`

AND see if the result are Same.

Upvotes: 1

Darvas
Darvas

Reputation: 974

Since you questions is not much defined, answer might be incorrect.

First of all, make sure that image is placed correctly and there is no typos in image name.

playerSprite position is in the middle of the top. to center it:

->setPosition(Point(visibleSize.widht * 0.5, visibleSize.height * 0.5));

If this == Scene you can do it like this.

->setPosition(Point(this->getContentSize().width * 0.5, this->getContentSize().height * 0.5));

Also when adding Sprite make sure there is no other Sprite above by setting zOrder to a bigger number

this->addChild(playerSprite, 100);

Upvotes: 0

Related Questions