【问题标题】:AS3 elliptical constraint for a simple slingshot简单弹弓的 AS3 椭圆约束
【发布时间】:2012-04-15 11:45:21
【问题描述】:

我正在尝试改进一个简单的 AS3 弹弓,可在 http://blog.shaperstudio.com/2010/10/as3-create-a-slingshot-with-an-elastic-effect/ 获得 这样我就可以让它更真实。

我已经对其进行了更改,以便可以将球瞄准任何方向,但现在我正在尝试创建一个函数,将弹弓的最大拉力限制在椭圆区域,最好具有相同的两个点弹弓作为椭圆两个焦点:

if ( mouseX > centerX + _maximumPULL.x) _mouse_x = centerX + _maximumPULL.x;                
            else if ( mouseX < centerX - _maximumPULL.x) _mouse_x = centerX - _maximumPULL.x;
            else _mouse_x = mouseX;

if ( mouseY > centerY + _maximumPULL.y) _mouse_y = centerY + _maximumPULL.y;                
            else if ( mouseY < centerY - _maximumPULL.y) _mouse_y = centerY - _maximumPULL.y;
            else _mouse_y = mouseY;

其中 _maximumPULL 是一个点变量,它返回我们可以将弹性拉到多远,像这样?:

_maximumPULL = new Point(200 * Math.cos(degree * Math.PI / 180), 100 * Math.sin(degree * Math.PI / 180));

我已经在代码上搞砸了太多小时了,我知道这对于像我这样没有编程背景的人来说太过分了,但我就是不能放手,我上瘾了。 ..

我一直试图在这里了解类似的问题:http://www.soundstep.com/blog/2011/04/08/knob-as3-drag-on-circle-or-ellipse/

这里:ActionScript 3 Trig Equations to create Ellipse

你能帮帮我吗?

【问题讨论】:

    标签: actionscript-3 ellipse


    【解决方案1】:

    可能不完全是您所追求的,但是如何绘制您想要的确切形状(无论是在 Flash 中,还是以编程方式使用 graphics 类),然后检查球与允许区域之间的碰撞。

    您可以通过在 mouseMove 事件函数中添加类似这样的内容来非常简单地编写代码:

    if (theBall.hitTestObject( allowedRange )){
        //Put your code that figures out where the ball should be
    }//otherwise, it won't alter the position of the ball :D
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-05
      • 2013-05-12
      • 2011-03-23
      • 2012-08-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多