0
我正在研究cocos2d中的pong類遊戲,但不是玩家只沿着屏幕的底部邊緣從左到右拖動「槳」他們可以將其拖放到比賽場地的所有四個邊緣,即like this。在cocos2d中沿指定路徑觸摸並拖動精靈
現在,我正在使用ccTouchesMoved進行玩家拖動,並使用具有可碰撞元數據的tilemap作爲「邊界」來限制玩家的移動。它的作品,但不像任何像盧克索iPhone一樣的乒乓類遊戲。
下面是設置了播放器的瓷磚位置和可碰撞精靈代碼:
-(void)setPlayerPosition:(CGPoint)position {
CGPoint tileCoord = [self tileCoordForPosition:position];
int tileGid = [_meta tileGIDAt:tileCoord];
if (tileGid) {
NSDictionary *properties = [_tileMap propertiesForGID:tileGid];
if (properties) {
NSString *collision = [properties valueForKey:@"Collidable"];
if (collision && [collision compare:@"True"] == NSOrderedSame) {
return;
}
}
}
_player.position = position;
}
下面是觸摸/拖曳檢測碼和移動
-(BOOL) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *myTouch = [touches anyObject];
CGPoint point = [myTouch locationInView:[myTouch view]];
point = [[CCDirector sharedDirector] convertToGL:point];
CCNode *sprite = [self getChildByTag:kTagPlayer];
[sprite setPosition:point];
}
在上測試此iPhone,當我將手指拖離玩家精靈的那一刻,它就會停止。可碰瓷磚給予了太多的「摩擦」,我知道它是應該做的,所以我認爲我的控制方法是不好的。
有沒有人做過類似cocos2d的拖動控制方案,可以幫助嗎?是的,我見過Ray Wenderlich的pong教程,但它沒有幫助,因爲我沒有使用box2d,他的教程僅限於沿x軸移動。