Web Design Forum: For loop problem. - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

For loop problem. Rate Topic: -----

#1 User is offline   AdamConder 

  • Dedicated Member
  • PipPip
  • View gallery
  • Group: Members
  • Posts: 205
  • Joined: 18-May 09
  • Reputation: 9
  • Gender:Male
  • Location:Newcastle, UK
  • Experience:Intermediate
  • Area of Expertise:Coder

Posted 01 January 2011 - 03:05 PM

Hiya, I'm creating a game for my university project. I have zombies spawning on the stage but want to add a number to the end of the instance for future use (to kill them off later). The for loops working however, I want them to spawn an infinite number of times and secondly the for loops messing up my timer for the spawning:

Heres the code:

		// Variables
		private var fireZombie:FireZombie; // Declare variable and associate it with object
		private var fireZombieContainer:Sprite = new Sprite; // Create container
		private var fireZombieTimer:Timer = new Timer(4000); // timer for every 4 seconds
		private var iceZombie:IceZombie; // Declare variable and associate it with object
		private var iceZombieContainer:Sprite = new Sprite; // Create container
		private var iceZombieTimer:Timer = new Timer(5000); // timer for every two seconds


		public function iceZombieSpawn(e:TimerEvent) {
			for (var i:Number = 0; i <= 10; i++) {
				iceZombie = new IceZombie(Math.random()*stage.stageWidth, -100); // Create new ice zombie at random x position
				iceZombie.name = "iceZombie"+i; // assign name to zombie
				iceZombieContainer.addChild(iceZombie); // Add zombie to container
				trace(iceZombie.name);
			}
		}


And here's the problem:

http://screenr.com/ist
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users