我想創建一個「蠕蟲」風格的回合炮兵遊戲是as3。我可以在角色的x/y位置添加我的球,並且在發出咔嗒聲時讓球向着鼠標位置的方向射擊,但是我現在難以向球施加重力。如果任何人都可以幫助我,那麼我需要做的就是讓球在被擊出後以弧線形式落下,這很棒。as3將重力應用於導彈
我的用於添加的球和具有它觸發在選定方向代碼是: 遊戲機主機:
功能redFollow(E:MouseEvent)方法:無效 {
var a1 = mouseY - redPower.y;
var b1 = mouseX - redPower.x;
var radians1 = Math.atan2(a1,b1);
var degrees1 = radians1/(Math.PI/180);
redPower.rotation = degrees1;
}
public function redFIRE(Event:MouseEvent)
{
removeChild(redPower);
turnchangeover();
addChild(RPBall);
trace("FIRE!");
RPBall.x = red.x;
RPBall.y = red.y;
RPBall.rotation = redPower.rotation + 90;
}
,然後球的類代碼爲:
包{
import flash.display.MovieClip;
import flash.events.Event;
public class redBall extends MovieClip {
public function redBall() {
this.addEventListener(Event.ENTER_FRAME, moveShot);
}
function moveShot(event:Event){
var thisMissile:redBall = redBall(event.target);
var _missileSpeed:int = 7;
var gravity:int = 0.8;
//get the x,y components of the angle
var missileAngleRadians = ((-thisMissile.rotation - 180) * Math.PI /180);
//trace("missle angle: " + missileAngleRadians);
var yMoveIncrement = Math.cos(missileAngleRadians) * _missileSpeed;
var xMoveIncrement = Math.sin(missileAngleRadians) * _missileSpeed;
thisMissile.y = thisMissile.y +yMoveIncrement;
thisMissile.x = thisMissile.x + xMoveIncrement;
trace(thisMissile.y);
}
}
}
感謝您的幫助,但我仍然有點迷路,似乎無法執行您告訴我的內容。還有什麼建議嗎?先謝謝你! – user2594986
你是否介意用你現在擁有的內容更新問題中的代碼,以便我可以查看並提供詳細的建議? – Vesper