How to drag & drop a sprite

I am new developing a game using cocos2d-x. I want to know How to drag & drop a sprite. Thanks

@kenhaui
You can refer this link. I have written a complete blog on this
http://techbirds.in/how-to-drag-a-sprite-in-cocos2d-x/

It will easily solve your problem
HAPPY CODING

1 Like

Is it still usable, if you alter the CCxyz things with their modern counterparts, as well as a few other changes. So far, I’ve kiinda suceeded then all this unresolved external stuff happens

1 Like

If you don’t figure this out in 2 days I’ll give you a simple example.

1 Like

How generous, in the meanwhile, I have the rest of the level ready pretty much, even the win animation is nearly done (missing confetti particles), Would you use TILED to make angry birds styled levels?

1 Like

If it were me, I wouldn’t. But that is just my style. You could if that made you more comfortable

I would use a parallax node with images that act as the background etc.

1 Like

Oh Okay. Thanks!

day 1(today), touch event is functioning, Clog precicely displays the mouses location, I’ll try use set position to add a drag effect.

Edit: under approximately 6 minutes later

Yep sorted. Just need to add a physics body

1 Like

Completed:
(made a new project to experiment.)
These are only the listeners, rest is sorted


bool HelloWorld::onTouchBegan(cocos2d::Touch *touch, cocos2d::Event *event)

{

	CCLOG("onTouchBegan x = %f, y = %f", touch->getLocation().x, touch->getLocation().y);


		mySprite->setPosition(touch->getLocation().x, touch->getLocation().y);
	

	return true;

}


void HelloWorld::onTouchMoved(cocos2d::Touch *touch, cocos2d::Event *event)

{

	CCLOG("onTouchMoved x = %f, y = %f", touch->getLocation().x, touch->getLocation().y);
	


	mySprite->setPosition(touch->getLocation().x, touch->getLocation().y);

}



void HelloWorld::onTouchEnded(cocos2d::Touch *touch, cocos2d::Event *event)

{

	CCLOG("onTouchEnded x = %f, y = %f", touch->getLocation().x, touch->getLocation().y);


	physicsBBody->setDynamic(true);
	mySprite->setPosition(touch->getLocation().x, touch->getLocation().y);


}
1 Like