2013-11-27 86 views

回答

0

覆蓋的方法在你的SKScene:

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { 

然後,當你在這個接收郵件時,只檢查與位置:

UITouch *touch = [touches anyObject]; 
if(touch){// 
    CGPoint location = [touch locationInNode:self]; 

    .. moving code here 
} 

一旦你有你的位置,只要將它基於其網格項觸控是目前內:

//Grid of 20x20 pixels, with entire grid starting at 0,0 
static const CGFloat GridSize = 20; 

int gridColumn = (int)(location.x/GridSize); //we can lose the precision here 
int gridRow = (int)(location.y/GridSize); //we can lose the precision here 

node.position = CGPointMake(gridColumn*GridSize, gridRow*GridSize); 

當然,您可以通過SKAction爲動作製作動畫,但如果您正在追蹤動作,您可能需要實時動起來。