好久没玩flash

抓紧时间操练了一把,用下面代码作了一个粉简单的坦克控制:)

[actionscript]
class Move extends MovieClip {

private var speed = 3;
private var xMin = 0;
private var yMin = 0;
private var xMax = 400;
private var yMax = 400;

public function onLoad(){
Key.addListener(this);
this.xMin += this._width/2;
this.xMax -= this._width/2;
this.yMin += this._height/2;
this.yMax -= this._height/2;
}

public function onEnterFrame(){
if( this._x < this.xMin ){
this._x = this.xMin;
}
if( this._x > this.xMax ){
this._x = this.xMax;
}
if( this._y < this.yMin ){
this._y = this.yMin;
}
if( this._y > this.yMax ){
this._y = this.yMax;
}
}

public function setSpeed(speed:Number){
this.speed = speed;
}

public function onKeyDown(){
switch(Key.getCode()){
case 83: // s
this._rotation = 180;
this._y += this.speed;
break;

case 65: // a
this._rotation = -90;
this._x -= this.speed;
break;

case 68: // d
this._rotation = 90;
this._x += this.speed;
break;

case 87: // w
this._rotation = 0;
this._y -= this.speed;
}
}

private function onRelease(){
trace(’test’);
}
}

[/actionscript]

作者: 发表于August 3, 2002 at 8:33 am

版权信息: 可以任意转载, 转载时请务必以超链接形式标明文章原始出处作者信息及此声明

Tags:

留条评论