0
我在触摸事件中遇到问题。 我有5个精灵,我想移动一个精灵和只有选定的精灵。但在这时候我在.m文件移动触摸那么只有一个Sprite是移动如何移动的唯一选择雪碧..触摸在Cocos2d中移动
在.h文件中
CCSprite *puzzButton1,*puzzButton2,*puzzButton3;
// create and initialize our seeker sprite, and add it to this layer
puzzButton1 = [CCSprite spriteWithFile: @"ingame_button_idal.png"];
puzzButton1.position = ccp(480/2, 320/2);
[self addChild:puzzButton1];
// create and initialize our seeker sprite, and add it to this layer
puzzButton2 = [CCSprite spriteWithFile: @"ingame_button_idal.png"];
puzzButton2.position = ccp(100, 200);
[self addChild:puzzButton2];
// create and initialize our seeker sprite, and add it to this layer
puzzButton3 = [CCSprite spriteWithFile: @"ingame_button_idal.png"];
puzzButton3.position = ccp(100, 300);
[self addChild:puzzButton3];
和
- (BOOL)ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event
{
return TRUE;
}
- (void)ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint location = [self convertTouchToNodeSpace: touch];
[puzzButton1 stopAllActions];
[puzzButton1 runAction: [CCMoveTo actionWithDuration:0.1 position:location]];
}