0

タイルマップ (Kobald Kit の KKTilemapNode) と真ん中にキャラクターがいます。ジョイスティックを使用してタイルマップを上下に移動し、速度を計算します。問題は、キャラクターを左に回すと、まだ上に行くことです。角度の下で新しい位置を計算する方法がわからないため、下に移動します。Flash の例をいくつか移植しようとしましたが、見つけたものにはタイル マップがありません :(

編集 (ソースの追加):

rotationStep = (_velocity.x / 20); // Rotate the car by

if (fabs(_speed) > 0.3) {
    _carRotation -= (rotationStep * (_speed / maxSpeed)); // Rotation angle if speed is at least 0.3
}

CGFloat speedX = ((_carRotation * (M_PI / 180)) * _speed); // Calculation stolen from the flash game and probably changed over tooo much
CGFloat speedY = ((_carRotation * (M_PI / 180)) * _speed);

CGFloat rotationValue = (degreesToRadians(_carRotation)); // Getting radians for the rotation

if (_velocity.x != 0 || _velocity.y != 0) {
    _car.zRotation = rotationValue; // Setting correct rotation
}

NSLog(@"Speed X: %f - Y: %f", speedX, speedY); // Getting probably very incorrect values

[_track setPosition:CGPointMake(5, (_track.position.y - _speed))]; // And moving the tile map just up and down in the end based on a speed I have calculated earlier
4

1 に答える 1

1

角度を計算する 1 つの方法:

float angle = atan2f (touchY - joystickY, touchX - joystickX);

ここで、touchY と touchX はプレイヤーがジョイスティックに触れた座標であり、joystickY と joystickX はジョイスティックの座標です。SKAction を使用してその角度だけノードを移動するには (アクションを使用したくない場合もありますが、数学を使用して目的の座標を計算することはできます)。

SKAction *moveWhatever = [SKAction moveByX: yourDistance*cosf(angle) y:yourDistance*sinf(angle) duration:yourDuration];
[node runAction: moveWhatever];

yourDistance と yourDuration を設定する場所。

于 2013-09-30T06:23:32.167 に答える