-(void) setPosition:(CGPoint)pos { CGSize screenSize = [[CCDirector sharedDirector] winSize]; float halfWidth = contentSize_.width * 0.5f; float halfHeight = contentSize_.height * 0.5f; // Cap the position so the Ship's sprite stays on the screen if (pos.x < halfWidth) { pos.x = halfWidth; } else if (pos.x > (screenSize.width - halfWidth)) { pos.x = screenSize.width - halfWidth; } if (pos.y < halfHeight) { pos.y = halfHeight; } else if (pos.y > (screenSize.height - halfHeight)) { pos.y = screenSize.height - halfHeight; } // must call super with the new position [super setPosition:pos]; }