I'm doing a platformer game using cocos2d-x v3 in c++, where the maps are usually very large, the visible screen follows the object through the map.
Let's say I want to show a sprite in the top right corner of the screen and it would be in this position even when the screen is following the object.
Using the object position doesn't do it.
Is there a way to show a sprite or whatever in the screen and it would be in the screen even when the screen is moving?
Ps. I'm super noob in game development
So there are some assumptions that will have to be made to answer this question. I am assuming that you are using a Follow action on your layer that contains your map. Check here for example. Something like:
The code above will cause the viewport to "move" to where the player is in world position. So following the player on your map that's bigger than the current viewport. What I did for my in-game menu/hud is add the Hud onto a different layer and add it to the root of the main game scene. The scene that does not have the follow action running on it. Something like below.
The code above assumes 'this' to be your MainGameScene. This restricts the Follow action from scrolling the element off the screen. Your element will be on the screen no matter where in World space your scene currently is.
Let me know if this is clear enough. I can help you out more if you get stuck.
You can always just put that sprite into different node / layer that everything else is. That way moving this layer / node won't move the sprite
I've managed to do it using a Parallax Node, and using the velocity which the sprite goes to Vec2(0,0), this way it stays always on the same spot in the screen.
As it's written here, you whould use
convertToWorldSpace
So, as you can read,
Or if you wish, you can get position relative to scenes' anchor points with function
convertToWorldSpaceAR
.