最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
简单的物体二段跳效果
时间:2022-07-02 17:06:19 编辑:袖梨 来源:一聚教程网
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);
graphics.drawRect(0,0,w,h);
x=posX;
y=posY;
}
return Sprite(addChild(rect));
}
private function keyDownHandler(evt:KeyboardEvent):void {
keyReleased && inAir && !comboJump&&(comboJump=true,ySpeed=jumpSpeed,trace("comboJump"));
!keyPressed&&(keyPressed=true,inAir=true,ySpeed=jumpSpeed,timer.start());
keyReleased=false;
}
private function keyUpHandler(evt:KeyboardEvent):void {
keyReleased=true;
ySpeed<-5&&(ySpeed+=8)&&ySpeed>0&&ySpeed=0;
}
private function timerHandler(evt:TimerEvent):void {
evt.updateAfterEvent();
ySpeed+=G;
box.y+=ySpeed;
ySpeed>0&&(box.hitTestObject(landObject))&&(trace(landObject.y),box.y=landObject.y-box.height,timer.stop(),keyPressed=false,inAir=false,comboJump=false);
}
}
}
/*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);
graphics.drawRect(0,0,w,h);
x=posX;
y=posY;
}
return Sprite(addChild(rect));
}
private function keyDownHandler(evt:KeyboardEvent):void {
keyReleased && inAir && !comboJump&&(comboJump=true,ySpeed=jumpSpeed,trace("comboJump"));
!keyPressed&&(keyPressed=true,inAir=true,ySpeed=jumpSpeed,timer.start());
keyReleased=false;
}
private function keyUpHandler(evt:KeyboardEvent):void {
keyReleased=true;
ySpeed<-5&&(ySpeed+=8)&&ySpeed>0&&ySpeed=0;
}
private function timerHandler(evt:TimerEvent):void {
evt.updateAfterEvent();
ySpeed+=G;
box.y+=ySpeed;
ySpeed>0&&(box.hitTestObject(landObject))&&(trace(landObject.y),box.y=landObject.y-box.height,timer.stop(),keyPressed=false,inAir=false,comboJump=false);
}
}
}
//文档类
相关文章
- 《无限暖暖》天星之羽获得位置介绍 12-20
- 《流放之路2》重铸台解锁方法介绍 12-20
- 《无限暖暖》瞄准那个亮亮的成就怎么做 12-20
- 《无限暖暖》魔气怪终结者完成方法 12-20
- 《无限暖暖》曙光毛团获得位置介绍 12-20
- 《无限暖暖》日光果获得位置介绍 12-20