SKSpritenode在方法TouchesBegan中的当前位置

时间:2014-02-25 17:38:10

标签: sprite-kit touchesbegan skspritenode

这是我的第一个问题,我希望它不是太愚蠢,我已经搜索但找不到答案,我希望你能帮助我!

我创建并向我的场景添加了一个SKSpriteNode,然后我希望能够在方法TouchesBegan中知道它的当前位置,然后根据其当前位置使用条件。

-(id)initWithSize:(CGSize)size {
if (self = [super initWithSize:size]) {

    SKSpriteNode *miChar = [self createCharacter];

    [self addChild: miChar];

}

这里只是将它添加到我的场景的简单方法,然后我想知道miChar.position.y,例如当TouchesBegan

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

     //Here is where i need the position of miChar.position.y

     SKSpriteNode *currentPos=miChar.position.y;

     while(currentPos.position.y > miChar.position.y){

       /* i want to do things here until the position is above for example
       miChar is an SKSpriteNode that is on constant movement so i need to check its 
       position wich will be constantly changing*/                             
     }

嗯,这就是它,可能是这么简单或者不可能这样做..我很抱歉刚刚开始编码。谢谢你的时间!

1 个答案:

答案 0 :(得分:0)

我这个问题here我表明touchesBegan作为执行循环中主线程的一部分在一致的位置运行。我相信所有操作都是在主线程中运行,除非您另行指定,因此在执行代码时没有任何更新它的危险(默认情况下)。