0

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

我创建一个 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*/                             
     }

好吧,就是这样,可能很简单,或者只是不可能这样做.. 抱歉刚开始编码。谢谢你们的时间!

4

1 回答 1

0

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

于 2015-05-03T18:19:08.750 回答