I want to drop one sprite from the place I touched. However, with this code two sprites are created from the touched location. Please tell me how to operate properly. Thanks
bool HelloWorld::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *unused_event)
{
Vec2 location = touch->getLocation();
addNewSpriteAtPosition(location);
return true;
}
void HelloWorld::addNewSpriteAtPosition(Vec2 p)
{
auto sp = Sprite::create(“aaa.png”);
sp->setPosition(p);
auto body = PhysicsBody::createCircle(sp->getContentSize().width / 2);
sp->setPhysicsBody(body);
this->addChild(sp, 1);
}
michio
February 15, 2018, 7:07am
#2
hi
try this :
bool HelloWorld::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *unused_event)
{
Vec2 location = touch->getLocation();
addNewSpriteAtPosition(location);
return false;
}
instead of returning true in touch Began , return false.
I tried it the first time, but it did not fix it.
I do not know well but I solved it.
The problem was solved.
I handed over from “bool HelloWorld::onTouchBegan” to “void HelloWorld::sprGo” using a “schedule_selector”. I worked after installing a rigid body in "void HelloWorld::sprGo" I just want to know why the crash occurred in the first way
Have you looked at our Programmers Guide, by chance?