【发布时间】:2013-09-29 22:11:09
【问题描述】:
我有一个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
【问题讨论】:
-
请贴一些代码给我们看看。
-
希望你能从代码中看到我是多么的绝望......正在进行中,我的数学技能很糟糕:(
标签: iphone ios objective-c ios7 sprite-kit