0
我有一个问题,拖动精灵我有精灵左右移动,同时保持y位置相同,但我无法让精灵在x位置保持不变时向上或向下移动。 也在cctouchended的精灵移动,以便它是在一个固定的位置,当所有的触摸已经结束 我想制作一个像斯莱索/ skozzle游戏。可以做一些帮助拖动精灵
c1是正在移动的列,r1是正在移动的行, [pos objectAtIndex:0]是精灵的:red1位置并检查精灵是否在c1中当你进入游戏时,精灵有一个新的随机位置,t1是精灵的坐标,所以你必须点击精灵,因为如果你不在精灵的上方点击并尝试移动精灵跳转到touchlocation。
这里是我的代码:
CGPoint touchLocation = [touch locationInView:[touch view]];
CGPoint prevLocation = [touch previousLocationInView:[touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL:touchLocation];
prevLocation = [[CCDirector sharedDirector] convertToGL:prevLocation];
if (CGRectContainsPoint(c1,touchLocation)) {
if (CGRectContainsPoint(c1,[[pos objectAtIndex:0]CGPointValue])) {
if (CGRectContainsPoint(t1,touchLocation)) {
if (touchLocation.y>0||touchLocation.y<0) {
touchLocation.x = red1.position.x;
[red1 setPosition:ccp(touchLocation.x,touchLocation.y)];
}
}
}
}
if (touchLocation.x>0||touchLocation.x<0) {
touchLocation.y=red1.position.y;
[red1 setPosition:ccp(touchLocation.x,touchLocation.y)];
}
}
感谢
请提供您的代码示例。从您提供的内容中进行调试相当困难。 – Bongeh 2011-01-07 17:12:32