cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.22k stars 7.06k forks source link

Can't add 3D Sprite on tmx file background using Cocos-2dx #13386

Open Ninganagouda opened 9 years ago

Ninganagouda commented 9 years ago

We have been working on sample game, wherein we want to show 3D sprite on .tmx file(background). But 3D sprite is never shown up, though we tried setting tileMap->setGlobalZOrder(-1).

Following is the sample code:

CCTMXTiledMap tileMap = new CCTMXTiledMap();
tileMap->initWithTMXFile("map.tmx");    
tileMap->setGlobalZOrder(-1);
//tileMap->setGlobalZOrder(-1000);
this->addChild(tileMap, 0);

//Sprite3D player = Sprite3D::create("player.c3b");
auto player = Sprite3D::create("player.c3b");
player->setScale(10.0f);
player->setPosition3D(Vec3(200, 500, 0));

this->addChild(player, 1);

But 3D Sprite is never shown up. Kindly help.

Your help is highly appreciated!

Thanks.

Dezorat commented 9 years ago

It appears that issue is quite severe and orthogonal and isometric tiles bug out differently: 1) orthogonal tiles get always drawn in front of 3D sprites, hiding them 2) isometric tiles get corrupted (only half of each tile remains) when Sprite3D gets added into scene (tried boss and ogre from tests)

zilongshanren commented 9 years ago

@super626 please take a look at it.

dabingnn commented 9 years ago

@Ninganagouda Could you please describe the requirement?

Ninganagouda commented 9 years ago

Hi,

Thanks for looking into the issue.

We are building an experimental game preferably in 2.5D approach. As 2.5D can be described in two ways: 1) 2D background(May be tmx) with 3D sprite 2) 3D background with 2D sprite

While we were exploring with first approach, we couldn't show 3D sprite on tmx file.

super626 commented 9 years ago

@dabingnn I think this requirement is reasonable.

@dabingnn @Ninganagouda I thought another method to achieve this. Have two cameras, one for tiledmap, and another for the 3D objects. You can keep the two cameras together. You can have a look at the cpptests, Node:Scene3D.

Ninganagouda commented 9 years ago

Hi, Thanks for the suggestion. We will definitely explore the another possibility as suggested.

It would be highly appreciated, if we will be informed about this issue fix(Possibly in upcoming releases).

Thanks again!

stevetranby commented 8 years ago

This is still a bug even if two cameras is a workaround. It may require user setting a "render as 3D" flag on the tilemap, or possibly only need to set the tilemap's global Z to negative to force it into the background.

If the 3D objects need to have a z-depth or sorting order in between tiles or tile layers that is a different beast altogether and probably requires a derived or new implementation (we have such a system, but it's very specific to our game and not generalized).

Alozavr commented 8 years ago

workaround with two cameras works only if you don't add sprite3D as a child to TMXTiledMap. In that case tiles are always drawn over sprite. ZOrder doesn't take any effect. Maybe someone found another workaround?