0

## 程式如下

function fire(e:MouseEvent){
var theeX:int = mouseX - theArrow.x;
var theeY:int = (mouseY - theArrow.y) * -1;
var bullet:Bullet = new Bullet();
bullet.x = 144.45;
bullet.y = 175.95;

}

## function on_move_bullet(e:Event):void{ bullet.x = theeY; bullet.y = theeX; }

### 2 個回答

4
wordsmith
iT邦高手 1 級 ‧ 2011-12-30 21:55:12

``````&lt;pre class="c" name="code">
class Bullet
{
//用來儲存theeX、theeY的私有變數，你的theeX、theeY是用int，不過要精準一點的話，應該會有浮點數，所以用Number是比較適合的，不過如果還是想用int的話，下面兩個變數的型別就要改int，總之要一致就是了
private var _newPositionX:Number;
private var _newPositionY:Number;

function Bullet(newPosX:Number,newPosY:Number)
{
//將點擊取得的theeX、 theeY指定給變數
_newPositionX = newPosX,
_newPositionY = newPosY;
}
//寫一個method來執行指定x,y值的動作
public function letBulletFly():viod
{
this.x = _newPositionX;
this.y = _newPositionY;
}
/*
其他原本的程式碼
...
*/

}
``````

``````&lt;pre class="c" name="code"> var bullet:Bullet = new Bullet(theeX,theeY);
``````

``````&lt;pre class="c" name="code">
function on_move_bullet(e:Event):void{
bullet.letBulletFly();
}
``````
4
player
iT邦大師 1 級 ‧ 2011-12-30 21:52:01

var theeX:int;
var theeY:int;

function fire(e:MouseEvent){
theeX = mouseX - theArrow.x;
theeY = (mouseY - theArrow.y) * -1;
var bullet:Bullet = new Bullet();
bullet.x = 144.45;
bullet.y = 175.95;

}

function on_move_bullet(e:Event):void{
bullet.x = theeY;
bullet.y = theeX;
}