Shoot Game Part 3: Creating Multiple Targets on Stage

Tue, Oct 13, 2009

ActionScript

This movie requires Flash Player 9

How does the Timer Event Repeat count work? On this tutorial we place 10 moving targets on stage, but not at once, by creating a timer, an event listener, an interval and a repeat count.

CLICK HERE FOR COMPLETE CLASSIC GAMING CARTOON SMART TUTORIAL

HERE IS THE SOURCE CODE!

//The Shoot Game – Placing Multiple Targets on Stage
// solutions at say-web dot com
// FREE to USE, COPY and DISTRIBUTE

var cursor:MovieClip;

//this creates the movie clip
//we will place on stage

// Let’s declare a few variables
// to create 10 airplanes on stage

var airplanesIngame:uint; //This will define how many airplanes on stage
var airplaneMaker:Timer; //This event will call a function
var container_mc:MovieClip; // We will place all planes inside a movie clip

function initializeGame():void {

airplanesIngame = 10; //I will test if this is not too much

airplaneMaker = new Timer (1000, airplanesIngame);
//Timer will run 10 times 1000 miliseconds each (1 second)

container_mc = new MovieClip;

// let;s place the container on stage
addChild(container_mc);

airplaneMaker.addEventListener(TimerEvent.TIMER, createAirplanes);
// This event will call the function that creates airplanes
// and places them inside of the container

//Let’s start our timer
airplaneMaker.start();
//This will fire the timer that will repeat 1 second 10 times

cursor = new Cursor;

//Note that the class has
//Capital C on the name
//cursor with a small c is the moive clip
// name

addChild(cursor);
//this will place a cursor on stage

cursor.enabled = false;
// this will neutralize the cursor
Mouse.hide();
//This will hide our own mouse (cursor)

stage.addEventListener(MouseEvent.MOUSE_MOVE, dragCursor);
// this functions fires when the mouse moves
// changes the cursor location

}

function dragCursor (event:MouseEvent):void{

cursor.x=this.mouseX;
cursor.y=this.mouseY;
// this will place the cursor on stage according
// to the mouse coordinates

}

function createAirplanes (event:TimerEvent):void {

var airplaneInstance :MovieClip;
airplaneInstance = new Airplane;

airplaneInstance.x = (Math.random()*stage.stageWidth)/3;
// We want the airplanes on the left side of the stage
airplaneInstance.y = Math.random()*stage.stageHeight;

container_mc.addChild(airplaneInstance);

}

initializeGame();

Cartoonist Drawing Tutorials

Related Articles:

, , , , , , , , , , ,

14,170 Responses to “Shoot Game Part 3: Creating Multiple Targets on Stage”

  1. udqhrcyb Says:

    best otc sleeping aid http://www.wnet.co.il/forum/showthread.php?t=550485 lunesta directions lunesta oral sleeping aid ambien [url=http://www.wnet.co.il/forum/showthread.php?t=550485]lunesta oral[/url]

  2. wjanoffgok Says:

    Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 4864 bytes) in /home/content/23/5413223/html/say-web/wp-includes/formatting.php(211) : runtime-created function on line 1