非常非常简单的效果,按任意键进行方块的跳跃,有二段跳效果和轻跳和重跳效果,根据按键长短判定的。这是在兄弟会论坛做的一道题,很应该转来跟大家分享下~
代码如下:
package {
/*author : CYPL*/
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
public class JumpTest extends Sprite {
private static const G:int=1;
private var box:Sprite;
private var landObject:Sprite;
private var ySpeed:int=0;
private var jumpSpeed:int=-15;
private var keyPressed:Boolean= false;
private var keyReleased:Boolean=true;
private var comboJump:Boolean=false;
private var inAir:Boolean=true;
private var timer:Timer;
public function JumpTest() {
box=drawRect((stage.stageWidth-50)/2,100,50,50,0xff0000);
landObject=drawRect(0,300,stage.stageWidth,20);
(timer=new Timer(30)).start();
configureControl();
}
private function configureControl():void {
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,false,0,true);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler,false,0,true);
timer.addEventListener(TimerEvent.TIMER,timerHandler,false,0,true);
}
private function drawRect(posX:Number,posY:Number,w:Number,h:Number,color:uint=0):Sprite {
var rect:Sprite;
with (rect=new Sprite) {
graphics.beginFill(color);
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/2988.html
代码如下:
package {
/*author : CYPL*/
import flash.display.*;
import flash.events.*;
import flash.utils.Timer;
public class JumpTest extends Sprite {
private static const G:int=1;
private var box:Sprite;
private var landObject:Sprite;
private var ySpeed:int=0;
private var jumpSpeed:int=-15;
private var keyPressed:Boolean= false;
private var keyReleased:Boolean=true;
private var comboJump:Boolean=false;
private var inAir:Boolean=true;
private var timer:Timer;
public function JumpTest() {
box=drawRect((stage.stageWidth-50)/2,100,50,50,0xff0000);
landObject=drawRect(0,300,stage.stageWidth,20);
(timer=new Timer(30)).start();
configureControl();
}
private function configureControl():void {
stage.addEventListener(KeyboardEvent.KEY_DOWN,keyDownHandler,false,0,true);
stage.addEventListener(KeyboardEvent.KEY_UP,keyUpHandler,false,0,true);
timer.addEventListener(TimerEvent.TIMER,timerHandler,false,0,true);
}
private function drawRect(posX:Number,posY:Number,w:Number,h:Number,color:uint=0):Sprite {
var rect:Sprite;
with (rect=new Sprite) {
graphics.beginFill(color);
本文转自:http://www.5uflash.com/flashjiaocheng/Flashaschengxu/2988.html