Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8966107
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:57:17+00:00 2026-06-15T16:57:17+00:00

I need to do the following: a sprite is moved to a position, when

  • 0

I need to do the following: a sprite is moved to a position, when the sprite goes to this position, I need to execute the reverse action.
For testing in this example I just print “ok” when I reach that position, avoiding so to over-release the action and to risk some exception.

-(id) init
{
    if( (self=[super init]))
    {
        soldier=[CCSprite spriteWithFile: @"soldier.gif"];
        soldier.position= CGPointMake(250, 250);
        [self addChild: soldier];
        CGPoint position=[soldier convertToNodeSpace: CGPointZero];
        CCMoveTo* move=[CCMoveBy actionWithDuration: 2 position: position];
        [move retain];
        [soldier addObserver: self forKeyPath: @"position" options: NSKeyValueObservingOptionNew context: (void*)move];
        [soldier runAction: move];
    }
    return self;
}

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    CGPoint position= [self convertToNodeSpace: soldier.position];
    if(CGPointEqualToPoint(position, CGPointZero));
    {
        NSLog(@"ok");
    }
}

The problem is that it prints “ok” a lot of times, it should print it only a time, why?

EDIT

I removed the extra ‘;’ :

- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    CGPoint position= [self convertToNodeSpace: soldier.position]; // breakpoint here
    if(CGPointEqualToPoint(position, CGPointZero))
    {
        NSLog(@"ok");
    }
}

Now it never prints “ok”.In the breakpoint I print position and the last value is (47,47), it never reaches (0,0).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:57:19+00:00Added an answer on June 15, 2026 at 4:57 pm

    I wouldn’t use KVO/KVC with cocos2d for the simple reason that cocos2d is not KVC/KVO compliant. A Cocos2D class’ properties might change without you ever getting a notification.

    I don’t know if this is the problem here or not, but there’s a good chance if you continue with KVC/KVO you’ll eventually run into problems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need following layout for my application: <TextView/> <ListView/> <Button/> But in this layout
I need following function (from C++ dll) available in C++/CLI extern C _declspec(dllexport) void
I need following namespaces to use native wpf property grid however, VS 2010 doesn't
I need the following C function in Python: int func(Uint8 *bytRecvBuffer, int *iRecvLen); I
I need the following xml to be made in code: <RelativeLayout xmlns:android=http://schemas.android.com/apk/res/android android:orientation=vertical android:gravity=right
I need the following authentication script finished. I am weak at php/pdo so I
I need the following logic. If array contains value , return it else return
I really need the following in magento. When a customer shows the config product
For a part of a program i need the following 2 methods. The first
Please help me to improve the following script: http://jsfiddle.net/n9BkM/8/ I need the following fucntionality:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.