Quantcast
Channel: Question and Answer » programming
Viewing all articles
Browse latest Browse all 103

Cocos2d Sprite 3D position

$
0
0

When I set a position3D for a Sprite in cocos2dx, it render two times the same sprite, i took a screenshot:

Image

I set the position3D because i want to use the Z position the give an effect of distance, but its rendering these two sprites in the lower left corner, how can I fix that?

Here is my code in .h:

cocos2d::Sprite* mySprite;
cocos2d::Sprite* mySprite2;
cocos2d::Camera* camera;

Here i my code in cpp:

bool HelloWorld::init()
{

if ( !Layer::init() )
{
    return false;
}


auto s = Director::getInstance()->getWinSize();
camera = Camera::createPerspective(60, (GLfloat)s.width / s.height, 1, 100);

camera->setRotation3D(Vec3(0, 0, 0));

this->addChild(camera);
mySprite2 = Sprite::create("idle1.png");
mySprite2->setPosition3D(Vec3(5, 0, -41));
mySprite2->getTexture()->setAliasTexParameters();

this->addChild(mySprite2, 2);

mySprite = Sprite::create("idle1.png");
mySprite->setPosition3D(Vec3(-5, 0, -81));
mySprite->getTexture()->setAliasTexParameters();

this->addChild(mySprite, 0);
}

Viewing all articles
Browse latest Browse all 103

Trending Articles