2 Replies - 813 Views - Last Post: 17 August 2009 - 05:40 AM

#1 davedove   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 11-June 09

Moving an Array of Characters

Posted 16 August 2009 - 12:15 PM

Hi i recently learn actionscript 3 and i am trying to make a wack a mole type of game with Penguins for Targets.I save the penguins generated in an array but the problem is that when i want the penguins to move only the last one is moving and the others stop their movement. Here is the code for movement

function Tuxmove(e:Event):void {
		if (TuxArray[i].x != 0) {
			TuxArray[i].x -=TuxSpeed;
			if (TuxArray[i].rotation == 0) {
				var TuxRotation:Tween = new Tween (TuxArray[i], "rotation", None.easeOut, -5 ,5, 0.2, true);
			}else{
				TuxArray[i].rotation = 0;
			}
		}
		
		if(TuxArray[i].x <= 0) {
			gotoAndStop("5");
		}
		TuxSpeed = 2;
	}


Is This A Good Question/Topic? 0
  • +

Replies To: Moving an Array of Characters

#2 BetaWar   User is offline

  • #include "soul.h"
  • member icon

Reputation: 1513
  • View blog
  • Posts: 8,290
  • Joined: 07-September 06

Re: Moving an Array of Characters

Posted 16 August 2009 - 11:40 PM

You are using a variable i to select the penguin from the array, but that is staying the smae throughout the entire function, so only one penguin is being told to do anything.

I would suggest using a for loop, like so:
function Tuxmove(e:Event):void {
   for(i=0; i<TuxArray.length; i++){
		if (TuxArray[i].x != 0) {
			TuxArray[i].x -=TuxSpeed;
			if (TuxArray[i].rotation == 0) {
				var TuxRotation:Tween = new Tween (TuxArray[i], "rotation", None.easeOut, -5 ,5, 0.2, true);
			}else{
				TuxArray[i].rotation = 0;
			}
		}
		
		if(TuxArray[i].x <= 0) {
			gotoAndStop("5");
		}
		TuxSpeed = 2;
	}
	}

Was This Post Helpful? 0
  • +
  • -

#3 davedove   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 11-June 09

Re: Moving an Array of Characters

Posted 17 August 2009 - 05:40 AM

Thx for the help, the problem was in an another part of the code after all :P. Now it runs smoothly ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1