1

我正在尝试改进一个简单的 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

你能帮帮我吗?

4

1 回答 1

0

Might not be exactly what you're after but what about drawing the exact shape you want (be it in flash, or programatically using the graphics class) and then check for collision between the ball and the allowed area.

You can code that very simply by adding something like this inside your mouseMove event function:

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
于 2012-04-18T02:58:39.460 回答