auto node = Node::create(); node->setPosition(Vec2(100, 200)); Vec2 pos = node->getPosition(); // pos = Vec2(100, 200)
auto sprite = Sprite::create("image.png"); sprite->setPosition(VisibleRect::center()); Vec2 pos = sprite->getPosition(); // pos = (screenWidth/2, screenHeight/2)This code creates a new Sprite from an image file, sets its position to the center of the screen, and retrieves its position using getPosition(). Package/Library: Cocos2d-x.