Trailer : Adobe flash cs4 Game tutorial Explosion








Dalam tutorial ini Anda akan mempelajari bagaimana membuat ledakan dengan musuh Anda. Anda akan belajar bagaimana membuat animasi ledakan.


timeline code

var sfx_gun:Sound = new sfx();
var sp:MovieClip = new ship();
var tm:Timer = new Timer(1500);


tm.addEventListener(TimerEvent.TIMER, onstart);


var bulletholder:Sprite = new Sprite();


addChild(bulletholder);


addChild(sp);


addEventListener(Event.ENTER_FRAME,onenter);
stage.addEventListener(MouseEvent.CLICK,onclick);


tm.start();
function onstart(e:Event){




var em:Sprite = new enemy();
em.x= Math.random()*550;
addChild(em);




}




function onenter(e:Event):void {
sp.x-=(sp.x-mouseX)*.1;
sp.y-=(sp.y-350)*.2;
}


function onclick(e:Event) {
sfx_gun.play();
sp.y=365;
var bl:Sprite = new bullet();
bl.y=sp.y;
bl.x=sp.x;
bulletholder.addChild(bl);
}




enemy class

package {



import flash.events.Event;

import flash.display.MovieClip;

import flash.display.Sprite;



public class enemy extends Sprite {

private var core:Object;



public function enemy() {

addEventListener(Event.ADDED_TO_STAGE,onadd);

}



private function onadd(e:Event) {

core=MovieClip(root);

addEventListener(Event.ENTER_FRAME,loop);

}



private function loop(e:Event) {

y+=3;



//var dis:Number = Math.abs(y-core.sp.y)/20;

//bd.htmlText=''+dis+'';

//y-=((y-core.sp.y)/dis);

//x-=((x-core.sp.x)/dis);



for (var i:int = 0; i





bullet class

package {

import flash.display.Sprite;

import flash.events.Event;



public class bullet extends Sprite {



private var sw:Number;

private var sh:Number;

private const _SPEED:int=10;

private const _OFFSTAGE:int=-10;



public function bullet():void {

addEventListener(Event.ADDED_TO_STAGE,onadd);

}



private function onadd(e:Event):void {

sw=stage.stageWidth;

sh=stage.stageHeight;

addEventListener(Event.ENTER_FRAME,loop);

}



private function loop(e:Event):void {

if (y<_OFFSTAGE) { removeEventListener(Event.ENTER_FRAME,loop); parent.removeChild(this); } y-=_SPEED; } public function removeListeners():void { removeEventListener(Event.ENTER_FRAME,loop); } } }




explosion class

package {

import flash.display.MovieClip;

import flash.events.Event;

import flash.media.Sound;

public class explosion extends MovieClip {

private var hit:Sound = new sfx_hit();

public function explosion() {

addEventListener(Event.ENTER_FRAME,xkill);

hit.play();

}



private function xkill(e:Event) {

if (currentFrame==framesLoaded) {



removeEventListener(Event.ENTER_FRAME,xkill);

parent.removeChild(this);

}

}

}

}

Blog Archive