在cocos2d中,座標系非常簡單..左下角是(0,0)。每當我設置好任何東西的位置。Cocos2d座標系
可以說一層是TouchEnabled。
時,即時通訊設定我的精靈的位置,這是很好..
[crab setPosition:ccp(20, 50)];
,但如果我得到的x和觸摸的y座標(並假設我點擊了精靈..):
- (void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"Touches began!");
NSArray *touchArray = [touches allObjects];
UITouch *one = [touchArray objectAtIndex:0];
pointOne = [one locationInView:[one view]];
CCLOG(@"points are: %f and %f", pointOne.x, pointOne.y);
}
y座標與cocos2d的座標系建議相反,y從上到下增加!
所以即時假設視圖的座標系統是不同於mac的coord系統..這是相當直觀的..是否正確?
謝謝!
convertToNodeSpace將不在當前節點座標系中的點轉換爲自身。例如世界座標(但仍然以openGL格式)到節點座標系。 –
通過添加converttogl方法更新我的答案 – lukaswelte
這仍然不正確。轉換爲節點空間不適用於uikit點 –