Question

In my application I am noticing that there are may things that don't seem right in my CCScene.

Ill just explain 3 things: 1. My FPS does not show anywhere in the view even though I do this from my UIViewController (My CCLayer is its own class)

The .h of my CCLayer class looks like this:

@interface CCMyGame : CCLayer {

CCDirector* director = [CCDirector sharedDirector];
    [CCDirector setDirectorType:kCCDirectorTypeDisplayLink];
    [director setAnimationInterval:1.0/60];
    [director setOpenGLView:self.eaglView];
    [director setDisplayFPS:YES];
    [director runWithScene:[CCSceneGame scene]];

I see one CCSprite of mine but thats it, I do not see anything else.

Then in my CCLayer class I do this to fully activate a CCScene:

+(CCScene *) scene
{
    CCScene *scene = [CCScene node];
    CCSceneGame *layer = [CCSceneGame node];
    [scene addChild:layer];
    return scene;
}

Why is this?

  1. My game loops are not getting called. I am doing this:

    [self schedule:@selector(myGameLoop:)];

Then in my game loop I NSLog it and the log never shows in the console so I realize that it is not getting called.

Also another thing that is odd is that my UIAccelerometer delegate method is not getting called even though I do this:

self.isAccelerometerEnabled = YES;
    [UIAccelerometer sharedAccelerometer].delegate = self;
    [UIAccelerometer sharedAccelerometer].updateInterval = 0.10f/4.0f;

Any reasons why?

  1. And lastly, none but one of my CCSprites are showing. I have a few CCSprites that I add like [self addChild:mySprite]; But I do not see them. They are all attached to b2Bodys and some are animating but I only see one CCSprite and I am not sure why that is the only one I see.

Does anyone have any ideas why any of these things are happening?

Edit1:

#1: Fixed!

#2: I am doing that and it is still not working! I do this to schedule it:

[self schedule:@selector(cocosgameLoop:)];

This is my method:

    -(void)cocosgameLoop:(ccTime)delta {
    NSLog(@"cocosgameLoop");
}

That NSLog is not getting called. And when you showed me the second way, that won't get update like a game loop usually would, that will only make the method called once. Why is that method not getting called?

Also the strange thing is that my UIAccelerometer delegate method is still not getting called! I am now doing this:

self.isAccelerometerEnabled = YES;
[UIAccelerometer sharedAccelerometer].updateInterval = 1/30.0f;

And I NSLogged my UIAccelerometer delegate method and it still doesn't seem like it is getting called:

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
    NSLog(@"accelerometer");
}

Edit2: It now seems that my UIAccelerometer method gets called if I do:

[[UIAccelerometer sharedAccelerometer] setDelegate:self];
[[UIAccelerometer sharedAccelerometer] setUpdateInterval:1/60];

Why would this be? I think I read somewhere that my layer is not added to my hierarchy, is that true? I got that idea from here, maybe that is why all these problems are occurring: http://www.cocos2d-iphone.org/forum/topic/13988

#3: My CCSprites are not following a b2Body, instead it is the other way around. You gave me that code here: b2Body Animation?

I am setting the position of my CCSprites like the UIKit way, maybe that is why. Here is an example of one of the sprites that is not getting shown:

CGPoint point = CGPointMake(50, 50);
point = [[CCDirector sharedDirector] convertToGL:point];
[sprite setPosition:point];
[self addChild:sprite z:1 tag:1];
Was it helpful?

Solution

Missing FPS display: you need to add the "fps_images.png" to your project.


If you schedule this selector:

[self schedule:@selector(myGameLoop:)];

Make sure the method is implemented as follows:

-(void) myGameLoop:(ccTime)delta
{
}

The standard way is to just call

[self scheduleSelector];

and implement:

-(void) update:(ccTime)delta
{
}

It's a tiny tad faster too.

Also, use breakpoints to test if a line of code gets called or not. Read this guide if you haven't been introduced to Xcode debugging.


By enabling accelerometer AND setting the UIAccelerometer delegate you're trying to receive accelerometer events through Cocos2D AND via UIAccelerometer. Pick only one:

self.isAccelerometerEnabled = YES;
[UIAccelerometer sharedAccelerometer].updateInterval = 1/30.0f;

Also, the updateInterval 10/4 = 2.5 … that means you're getting accelerometer events at most every 2.5 seconds. You will want this to be a number that's a fraction of a second, like 0.1 or less.


If sprites attached to b2Bodies are not visible, check their position. I have a hunch that you forgot to convert from Box2D meter coordinates to pixel coordinates. Try for a test if the sprites appear if they're not connected to Box2D bodies.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top