Monday, May 25, 2015

Cocos2d-x: 2D Sprites covering 3D Sprites

For certain Android devices e.g., Galaxy Tab 2, the 2D sprites will always be rendered on top of all 3D sprites and will cover 3D sprites. This gives the impression that the 3D sprites are never rendered. To solve this problem,  set the Global Z Order  of the 2D sprites to a high negative number, e.g. -1000. Then add your 3D sprite the usual way. For example, if you have a 2D background sprite and a 3D model of a gun, this how you could do it:

Size visibleSize = Director::getInstance()->getWinSize();
auto background = Sprite::create("Gfx/background.jpg");

background->setGlobalZOrder(-1000);
this->addChild(background);

auto gun = Sprite3D::create("Gfx/m16.c3b");
gun->setPosition3D(Vec3(x,y,z));
this->addChild(gun);




1 comment: