【问题标题】:How to make turret pointing at an object using 2d frames in tower defense games?如何在塔防游戏中使用 2d 帧使炮塔指向对象?
【发布时间】:2019-06-06 18:44:32
【问题描述】:

我正在开发塔防游戏,我正在使用 stencyl。

我想制作像(部落冲突)这样的 2D 塔防游戏,所以我想知道如何使用像(部落冲突中的佳能)这样的框架制作指向对象的炮塔。

我的意思是当一个物体进入塔的范围时,塔将指向它而不旋转塔,而是使用二维帧而不是通过某种方式使用代码或数学方式。

【问题讨论】:

  • 欢迎来到 Stack Overflow。请阅读asking questions。请edit这个问题明确缩小问题范围,因为现在它非常广泛。您是否在询问如何选择能够呈现指向特定方向的“塔”外观的精灵?
  • 类似的东西。但我希望它用代码或数学方式我已经编辑了问题以获得更多理解。

标签: openfl stencyl


【解决方案1】:

我找到了解决方案。 这样做:

float Direction = 0;
float FinalDirection = 0;
float DirectionDegree = 0;
int NumberOfDirections = 0; // eg: 24 or 32 or even 128 or anything Directions

DirectionDegree = 360 / NumberOfDirections;

void update() // this will run every frame
{
    Direction = Math.atan2(target.y - tower.y, target.x - tower.x ) * (180 / Math.PI);

    if(Direction < 0)
    {
        Direction += 360;
    }

    FinalDirection = Direction / DirectionDegree;
    tower.frame = FinalDirection;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    • 2021-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多