0

this is my first question i hope its just not too stupid, i've searched but couldn't find an answer, i hope you can help me!

I create and add to my scene an SKSpriteNode, then i want to be able to know its current position in the method TouchesBegan, then use a condition depending on its current position.

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

    SKSpriteNode *miChar = [self createCharacter];

    [self addChild: miChar];

}

Here is just the simple way to add it to my scene, then i want to know miChar.position.y for example when 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*/                             
     }

Well, this is it, may be so simple or just not possible to do this way.. im sorry just started coding. Thanks for your time guys!

Connor Pearson
  • 63,902
  • 28
  • 145
  • 142
  • What you have is quite off. Can you explain a bit more about what you're trying to achieve? Perhaps post a bit more code for us? – jervine10 Feb 25 '14 at 17:42
  • You can get hold of miChar by either making it an instance var, or grabbing it by name(childNodeWithName:). On the other hand... expression inside your while bracket will ALWAYS be true, and will lead to while(YES) loop in your case.(Probably faulty logic) Also, this position validation looks more like something you would want to do in update:. – Dobroćudni Tapir Feb 25 '14 at 17:45
  • Thanks! got it i will try it in update, sorry i know that wasn't so much code, just wanted to be simple . about the while... you are right it would be YES always, unless the position of miChar is refreshed ( because its in constant movement ), which is what i want to achieve, to be able to see that new position. i will try it in update, makes more sense ! tyy! – user3352358 Feb 25 '14 at 22:58

1 Answers1

0

I this question here I showed that touchesBegan is run as part of the main thread in the execution loop in a consistent place. I believe that all actions are also run the main thread unless you specify otherwise, so there is no danger (by default) of anything updating it while your code is executing.

Community
  • 1
  • 1
rghome
  • 8,529
  • 8
  • 43
  • 62