【发布时间】:2012-10-04 06:25:37
【问题描述】:
在 cocos2d 中,坐标系非常简单。左下角是 (0,0)。 每当我设置任何东西的位置都可以。
假设一个层是 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 的坐标系不同.. 这很违反直觉.. 对吗?
谢谢!
【问题讨论】:
标签: iphone ios cocos2d-iphone drawing