我希望能够在拼贴图上拖动精灵,但是却无法将精灵锁定到拼贴上。首先我有:
- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchLocation = [touch locationInView:touch.view];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
objectInTouch.position=touchlocation;
}
这不起作用,因为它使用屏幕坐标而不是tilemap? 然后我想每个瓷砖是16x16像素,所以我会在精灵(objectInTouch)周围做一个“边框”,并且根据它是否击中顶部,底部,左边或右边,精灵会相应地移动。这是我尝试过的,但我得到“表达不可分配。”
- (void)touchMoved:(UITouch *)touch withEvent:(UIEvent *)event{
CGPoint touchLocation = [touch locationInView:touch.view];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
touchLocation = [self convertToNodeSpace:touchLocation];
int xborder = objectInTouch.position.x+16;
int yborder = objectInTouch.position.y+16;
int xleftborder = objectInTouch.position.x-16;
int ybottomborder = objectInTouch.position.y-16;
if(touchLocation.x >= xborder)
objectInTouch.position.x = objectInTouch.position.x+16; -> Expression not assignable
if(touchLocation.y >= yborder)
objectInTouch.position.y = objectInTouch.position.y+16; -> Expression not assignable
if(touchLocation.x <= xleftborder)
objectInTouch.position.x = objectInTouch.position.x-6;; -> Expression not assignable
if(touchLocation.y <= ybottomborder)
objectInTouch.position.y = objectInTouch.position.y-16; -> Expression not assignable
}
哦,如果有人能把我推荐给一些关于这类东西的好书/文件,那就太棒了!
谢谢!