Answer the question
In order to leave comments, you need to log in
How to get position of DrawNode?
DrawNode* circleInner = DrawNode::create();
circleInner->drawDot(
Vec2(100, 100),
55,
Color4F::BLUE
);
circleInner->setTag(1);
this->addChild(circleInner);
CCLOG("%d", circleInner->getPositionX()); // 0
CCLOG("%d", circleInner->getPosition()); // 0
CCLOG("%d", circleInner->getPositionNormalized()); // 0
auto circleInner = this->getChildByTag(1);
if (circleInner->getBoundingBox().containsPoint(Vec2(100, 100))) {
CCLOG(" is circle pressed");
}
// or
bool HelloWorldScene::onTouchBegan(cocos2d::Touch* touch, cocos2d::Event* event)
{
auto circleInner = this->getChildByTag(1);
if (!circleInner) {
return true;
}
CCLOG(__FUNCTION__);
CCLOG(" getLocation x %d", touch->getLocation().x);
CCLOG(" getLocation y %d", touch->getLocation().y);
if (circleInner->getBoundingBox().containsPoint(touch->getLocation())) {
CCLOG(" is circle pressed");
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question