【问题标题】:Move two CCSprites in Cocos2d/spritebuilder在 Cocos2d/spritebuilder 中移动两个 CCSprite
【发布时间】:2014-09-07 22:24:48
【问题描述】:

我的场景中有两个精灵,我想朝不同的方向移动。我通过搜索尝试了以下方法,但我无法得到任何工作。这是我迄今为止最好的。 如果有人能伸出援手,那就太好了。

-(void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInNode:self];
if(CGRectContainsPoint([redLeash boundingBox], touchLocation))
{
redLeash.position = touchLocation;
}
else if
(CGRectContainsPoint([blueLeash boundingBox], touchLocation))
{
blueLeash.position = touchLocation;
}
}

【问题讨论】:

    标签: objective-c cocos2d-iphone spritebuilder


    【解决方案1】:

    试试这个。我在这里输入了它,所以可能会有一些语法错误,但它应该可以工作。

    -(void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event
     {
        CGPoint touchLocation = [touch locationInNode:self];
    
        if(CGRectContainsPoint([redLeash boundingBox], touchLocaiton))
        {
           [redLeash setPosition:touchlocation];
        }
        else if (CGRectContainsPoint([blueLeash boundingBox], touchLocation))
        {
          [blueLeash setPosition:touchLocation];
        }
      }
    

    【讨论】:

      猜你喜欢
      • 2014-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多