Question

In Cocos2D, I would like a sprite placed on a screen coordinate, not a map coordinate. I thought I could get by using convertToNodeSpace, but it doesn't seem to do what I want.

I thought this should place a sprite in the middle of my iPad screen:

selectionScreenOverlaySprite.position = [self convertToNodeSpace:CGPointMake(512, 384)];

But it doesn't. It also places it in a different place depending on the size of my map. Does anyone know what I should be using? I've also tried: convertToWorldSpace, convertToNodeSpaceAR, and convertToWorldSpaceAR.

Was it helpful?

Solution

Try this:

CGSize wins = [[CCDirector sharedDirector] winSize];
[yourSprite setPosition:CGPointMake(wins.width / 2, wins.height / 2)];

This is better than using hard-coded values because it will work regardless of resolution.

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