i want to move a sprite by touching on screen, i want the sprite to move to the place which I touched. i have implemented a code but it crashes, i want to move a sprite by touching the screen to that point but my app crashes.
public class GameLayer extends CCLayer {
static final int kTagSprite = 1;
public static CCScene scene()
{
CCScene scene = CCScene.node();
CCLayer layer = new GameLayer();
scene.addChild(layer);
return scene;
}
protected GameLayer()
{
this.setIsTouchEnabled(true);
CCSprite player2 = CCSprite.sprite("Yellow.png") ;
player2.setPosition(CGPoint.ccp(150 , 150));
addChild(player2 , kTagSprite );
}
@Override
public boolean ccTouchesBegan(MotionEvent event) {
//create point takes coordinates of touch
CGPoint convertedLocation = CCDirector.sharedDirector()
.convertToGL(CGPoint.make(event.getX(), event.getY()));
CCNode s = getChild(kTagSprite);
s.stopAllActions();
s.runAction(CCMoveTo.action(1.0f, convertedLocation));
return CCTouchDispatcher.kEventHandled;
}
}
you have to check the condition:
**
**
It will work.Try this.If not place the log