【发布时间】:2010-06-20 11:18:59
【问题描述】:
我尝试在我的 iPhone Cocos2D 游戏中同时支持横向和纵向,但我无法正确转换坐标。
这是我目前正在做的事情。
我有一个 GameWorld 层,无论设备方向如何,我始终保持纵向。以下代码位于 UIDeviceOrientationLandscapeLeft 的 DeviceRotated 事件中。 ('self' 是我的 GameWorld 层)
[self runAction:[CCMoveTo actionWithDuration: 0.25f position:ccp(80, 0)]];
[self runAction:[CCRotateTo actionWithDuration:0.25f angle:90]];
所以我不必为每个方向编写不同的代码,我希望在我的 Sprite 类中使用以下代码来转换 Sprite 坐标。
CGPoint spriteLoc = ccp(0,0);
CGPoint translatedSpriteLoc = [self.parent convertToNodeSpace:spriteLoc];
self.position = translatedSpriteLoc;
但是,这不起作用。
如果设备处于纵向模式且精灵位于左下角,并且我将设备向左旋转,则精灵出现在右下角。我希望精灵在横向中位于左下方,就像在纵向中一样。
是我遗漏了什么还是有更好的方法来翻译坐标?
【问题讨论】:
标签: iphone cocos2d-iphone coordinates