Vineet
Vineet

Reputation: 47

Moving origin co ordinates from bottom left to center of screen

The origin i.e - X and Y (0, 0) co-ordinates starts from bottom left of screen (Portrait mode). Is there a way I can move origin(0, 0) to center of screen. So, that I can differentiate when my sprite is on positive or negative axis on both X and Y co-ordinates ?

Or is there any other logic that could be used to know when sprite is either left or right side of screen ?

Upvotes: 0

Views: 90

Answers (1)

Jack
Jack

Reputation: 133587

Cocos2d works with a tree of nodes, the position of each subnode is relative to the parent.

This means that if you add a middle node between your layer and everything else you can easily obtain the desired behavior. For example:

Node* mainNode = Node::create();
mainNode->setPosition(Point(WIDTH/2, HEIGHT/2));
layer->addChild(mainNode);

// this will now place the sprite in the middle of the viewport
Node* sprite = ...
sprite->setPosition(Point::ZERO);
mainNode->addChild(sprite);

Upvotes: 1

Related Questions