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 7617141
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:04:33+00:00 2026-05-31T03:04:33+00:00

I have a cocos2d game with a CCLayer called GameplayLayer placed inside a scene.

  • 0

I have a cocos2d game with a CCLayer called GameplayLayer placed inside a scene. Here is the layer’s init code:

    - (id)initWithScene1BackgroundLayer:(Scene1BackgroundLayer *)scene5UILayer {
    if ((self = [super init])) {
        uiLayer = scene5UILayer;
        startTime = CACurrentMediaTime();
        [self scheduleUpdate];
        self.isAccelerometerEnabled = YES;
        //chipmunk
        [self createSpace];
        [self createGround];
        mouse = cpMouseNew(space);
        self.isTouchEnabled = YES;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            [[CCSpriteFrameCache sharedSpriteFrameCache]
             addSpriteFramesWithFile:@"escapesceneatlas.plist"];
            sceneSpriteBatchNode = [CCSpriteBatchNode
                                    batchNodeWithFile:@"escapesceneatlas.png"];
            hopper = [[[CPHopper alloc] initWithLocation:ccp(200,200) space:space groundBody:groundBody] autorelease];
        } else {
            [[CCSpriteFrameCache sharedSpriteFrameCache]
             addSpriteFramesWithFile:@"escapesceneatlas.plist"];
            sceneSpriteBatchNode = [CCSpriteBatchNode
                                    batchNodeWithFile:@"escapesceneatlas.png"];
            //Viking became hopper and starts at bottom
            hopper = [[[CPHopper alloc] initWithLocation:ccp(100,100) space:space groundBody:groundBody] autorelease];

            //An enemy robot called JJ1 also starts at bottom
            genericBody = [[[CPGenericBody alloc] initWithLocation:ccp(210,200) space:space groundBody:groundBody] autorelease];

            //add the batchnode to layer
            [self addChild:sceneSpriteBatchNode z:0];
        }

        [self addLabel];

        [sceneSpriteBatchNode addChild:hopper z:2];
        [sceneSpriteBatchNode addChild:genericBody z:2];

    }

    return self;
}

The addLabel method calls the debugLabel of the hopper class like this:

-(void)addLabel{
//set debuglabel
CCLabelBMFont *debugLabel=[CCLabelBMFont labelWithString:@"NoneNone" fntFile:@"SpaceVikingFont.fnt"];
[self addChild:debugLabel];
[hopper setMyDebugLabel:debugLabel];    

}

Then the debugLabel code in the hopper class is:

-(void)setDebugLabelTextAndPosition {
CGPoint newPosition = [self position];
NSString *labelString = [NSString stringWithFormat:@"X: %.2f \n Y:%d \n", newPosition.x, newPosition.y];

[myDebugLabel setString: [labelString stringByAppendingString:@" tracking..."]];

float yOffset = screenSize.height * 0.195f;
newPosition = ccp(newPosition.x,newPosition.y+yOffset);
[myDebugLabel setPosition:newPosition];

}

For some reason when I run it the X value is fine, its value seems reasonable, it starts out at 100 but the y value is approx 1,567,385 and then if i move the hopper it goes to 35,633,753 and keeps changing to huge random numbers. It seems very unsteady.

Why could this be?

  • 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-05-31T03:04:35+00:00Added an answer on May 31, 2026 at 3:04 am

    There is a simple typo in your debug label code. You are formatting your floating point number as an integer which just gives garbage results. Because the stringWithFormat function will not implicitly convert the float to int but just take the bit representation of the float and interpret it as an integer number.

    A more detailed explanation is given here.

    So this

    NSString *labelString = [NSString stringWithFormat:@"X: %.2f \n Y:%d \n", newPosition.x, newPosition.y];
    

    should be

    NSString *labelString = [NSString stringWithFormat:@"X: %.2f \n Y:%.2f \n", newPosition.x, newPosition.y];
    

    .

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

Sidebar

Related Questions

I am newbie to Cocos2d. I have this layer that represents my main game
Hi guys I am new to the cocos2D.In my game i have one scene
Using cocos2d for iPhone game development, I am confused between Layer and Scene. For
Currently I have this code in my UIViewController: //Cocos2D methods -(id) init { if((self=[super
I have a Cocos2d game scene that loads with an EAGLView loaded by a
I am developing a game on Iphone using cocos2d. I have a CClayer containing
I have a cocos2d project with some scenes (home scene, level selection scene, game
I have writing a small shooting game in cocos2d. Winning the game is to
I have written my code in following way in cocos2d. id actionTo = [CCFadeOut
I have a Cocos2d/openGL iPhone game. It's a universal app and I'm dealing with

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.