1
我一直在讀一本書上的cocos2d框架的ios5了幾天,並開發了一個小遊戲,這本書通過引導您。要控制在這個遊戲中的精靈,你使用加速度計:移動與觸摸精靈開始,在OBJ鑄造和參數 - C嗎?
-(void) accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration
{
float deceleration = 0.4f;
float sensitivity = 6.0f;
float maxVelocity = 100;
// adjust velocity based on current accelerometer acceleration
playerVelocity.x = playerVelocity.x * deceleration + acceleration.x * sensitivity;
// we must limit the maximum velocity of the player sprite, in both directions (positive & negative values)
if (playerVelocity.x > maxVelocity)
{
playerVelocity.x = maxVelocity;
}
else if (playerVelocity.x < -maxVelocity)
{
playerVelocity.x = -maxVelocity;
}
// Alternatively, the above if/else if block can be rewritten using fminf and fmaxf more neatly like so:
// playerVelocity.x = fmaxf(fminf(playerVelocity.x, maxVelocity), -maxVelocity);
}
現在我想知道如果我可以改變這個代碼,允許精靈仍然加速/沿x軸有所放緩,但寧願使用觸摸輸入比加速度計更快,觸摸所需的時間越長,速度越快?因此,一個觸摸向右慢慢地將精靈移動到這個位置,如果觸摸被釋放,其停止移動,該點。觸摸持續時間越長,精靈移動的速度越快。
是那裏的框架,讓我實現一個旋轉機構,使我的精靈轉動到位置,觸摸是什麼,所以它看起來像它面臨的問題這就是被感動?