I have 5 images stacked in the bottom of my screen. My game's aim is to drag these images and connect them on certain conditions.(Sort of jigsaw puzzle) I used the following code
var touchListener = new CCEventListenerTouchAllAtOnce ();
touchListener.OnTouchesEnded = OnTouchesEnded;
touchListener.OnTouchesMoved = HandleTouchesMoved;
AddEventListener (touchListener, this);
void HandleTouchesMoved (List touches, CCEvent touchEvent)
{
foreach(var tap in touches)
{
var locationOnScreen = tap.Location;
alarmicSprite.PositionY = locationOnScreen.Y;
alarmicSprite.PositionX = locationOnScreen.X;
pressSwitchSprite.PositionY = locationOnScreen.Y;
pressSwitchSprite.PositionX = locationOnScreen.X;
}
}
This code moves all images at once to the touched coordinates. My requirement is to get one image dragged at a time unlike all at once. Cocossharp API and tutorials given in Xamarin and Github in my mind is not that helpful. Is there a method which allows to drag one image on one touch instance? Help appreciated
Here is an example that creates two sprites and lets you drag them individually.
Design:
Notes:
Once you find the the sprite of interest, you return true to "swallow" the touch event and stop the rest of the sprites from calling back. This saves cpu and executes your OnTouchesMoved sooner. The system will not call OnTouchesMoved until it is completely done dealing with OnTouchesBegan.
I followed this link TouchableSpriteTest and achieved my required functionality(with help from jaybers)
Sample code