【问题标题】:Cocos2d-iphone sprite moving in wrong directionCocos2d-iphone 精灵向错误的方向移动
【发布时间】:2013-06-10 20:20:24
【问题描述】:

cocos2d 1.0.1 版 xcode 4.6.2 iphone 6.1 模拟器 部署目标 4.3

我为我的游戏编写了简单的代码,其中我试图在触摸精灵时使精灵向左移动 10 点。 问题是当我触摸精灵时它向左移动并且精灵边界框向下移动,即精灵在-x 轴上移动但精灵边界框在-y 轴上移动。请帮我解决这个问题我不知道坐标系或设备方向设置是否有问题

    -(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
   {
     UITouch *touch = [touches anyObject];
     CGPoint touchLocation = [touch locationInView:[touch view]];

     CCSprite *mysprite = (CCSprite*)[self getChildByTag:1];

     if (CGRectContainsPoint([mysprite boundingBox], touchLocation)) {
        [mysprite runAction:[CCMoveBy actionWithDuration:1 position:ccp(-10,0) ]];
        }


    }

【问题讨论】:

    标签: objective-c cocos2d-iphone


    【解决方案1】:

    问题解决了。

    在 if 条件之前我添加了这段代码

    touchLocation = [[CCDirector sharedDirector]convertToGL:touchLocation];
    

    【讨论】:

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