我有一个tilemap(Kobald Kit的KKTilemapNode)和一个中间的角色,现在我使用操纵杆上下移动tilemap并计算速度,我遇到的问题是如果我向左转角色,它仍然只是向上向下,因为我不知道如何计算一个角度下的新位置。我尝试移植一些 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