【问题标题】:scale the background layer touch position is changed?缩放背景层触摸位置是否改变?
【发布时间】:2012-02-23 12:34:17
【问题描述】:

我正在 cocos2d 中进行一些研发。我有一个 backgroundLayer 并在该层中添加一个精灵。 在 touches Moved 中,我将精灵位置更改为当前触摸位置。如果背景层没有缩放,这意味着 backgroundLayer 比例为 1,则代码运行完美(只需将触摸位置设置为精灵位置)。如果我缩放 backgroundLayer,我有问题精灵不移动触摸位置..请任何人帮助我。

这是我的代码:

layer1=[CCLayer node];
[self addChild:layer1];
layer1.scale=2;

iconImg=[CCSprite spriteWithFile:@"Icon-72.png"];
iconImg.position=ccp(512,384);
[layer1 addChild:iconImg];

触摸移动

iconImg.position=tchLocation;

我的问题是缩放背景层后如何根据背景层位置找到触摸位置..任何人指导我...

【问题讨论】:

    标签: iphone ios5 cocos2d-iphone


    【解决方案1】:

    您如何计算您的 tchLocation

    它应该适用于:

    CGPoint *tchLocation = [layer1 convertTouchToNodeSpace:touch];
    

    您的 UITouch 在哪里触摸。

    【讨论】:

      猜你喜欢
      • 2013-06-06
      • 1970-01-01
      • 2012-06-27
      • 2011-11-08
      • 1970-01-01
      • 2011-04-09
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      相关资源
      最近更新 更多