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