哦,上帝,伙计们,我很抱歉再次打扰,我从没想过开始编写 AS3 会这么难(一开始更容易,但现在我的思维被阻塞了),正如我在第一篇文章中解释的那样三角学试图给球指明方向,我想让球在踢球后移动到鼠标位置,我的意思是把球以所需的速度和角度扔到光标所在的位置,我拿了杰特的示例,但可能我没有正确实施,这是代码:
import flash.geom.Point;
import flash.events.MouseEvent;
import flash.events.Event;
import flash.display.MovieClip;
// here I added a custom cursor to my mouse (it’s an aim in png format)
var cursor:MovieClip;
function initializeGame():void
{
cursor = new Cursor();
addChild(cursor);
cursor.enabled = false;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);
}
function dragCursor(event:MouseEvent):void
{
cursor.x = this.mouseX;
cursor.y = this.mouseY;
}
initializeGame();
var mouse=this.Mouse;
// here I want to make the player (called kicker) to kick the ball
stage.addEventListener(MouseEvent.CLICK, kick);
function kick(evt:Event){
kicker_mc.play(); // here I animate the kicker movieClip
this.addEventListener(Event.ADDED, moveBall);// this is the function that will move the ball towards the goal
}
//And here unsuccessfully trying to make the ball start moving to the cursor position, (currently when I kick the ball it appears at the right upper corner of the swf, exactly where the cursor appears when movie is tested
var speed:Number;
var angle:Number;
speed=200;
angle = Math.atan2(mouse.y-bola.y, mouse.x-bola.x);
function moveBall (event:Event){
ball.x += Math.cos (angle) * speed;
ball.y += Math.sin (angle) * speed;
}
如果有人帮忙让球移动,我将永远欠债,稍后我将从物理开始,但现在我的大脑已经筋疲力尽了