How to make a game in flash.
ฝัง
- เผยแพร่เมื่อ 8 ก.ย. 2024
- this is a tutorial on how to make a flash game in flash 8, cs4, cs5, cs5.5.
It will show you how to animate your character while it moves. Thanks for watching, comment rate and subscribe for more :)
Watch in HQ.
this is the code for the character.
onClipEvent (load) {
var ground:MovieClip = _root.ground;
var grav:Number = 0;
var gravity:Number = 2;
var speed:Number = 7;
var maxJump:Number = -12;
var touchingGround:Boolean = false;
scale = _xscale;
}
onClipEvent (enterFrame) {
_y += grav;
grav += gravity;
while (ground.hitTest(_x, _y, true)) {
_y -= gravity;
grav = 0;
}
if (ground.hitTest(_x, _y+5, true)) {
touchingGround = true;
} else {
touchingGround = false;
}
if (Key.isDown(Key.RIGHT)) {
_xscale = +scale;
_x += speed;
this.gotoAndPlay(2);
}
if (Key.isDown(Key.LEFT)) {
_xscale = -scale;
_x -= speed;
this.gotoAndPlay(2);
}
if (Key.isDown(Key.UP) && touchingGround) {
grav = maxJump;
this.gotoAndPlay(3);
}
if (Key.isDown(Key.DOWN)){
this.gotoAndPlay(4);
}
if (ground.hitTest(_x+(_width/2), _y-(_height/2), true)) {
_x -= speed;
}
if (ground.hitTest(_x-(_width/2), _y-(_height/2), true)) {
_x += speed;
}
if (ground.hitTest(_x, _y-(height), true)) {
grav = 3;
}
}
onClipEvent (keyUp) {
this.gotoAndStop(1);
}