Skip to main content
Participant
January 13, 2011
Answered

Randomize Game Characters

  • January 13, 2011
  • 1 reply
  • 931 views

Hi guys,


I've a question to ask regarding randomization using actionscript. Given a situation where you have different designed game characters and you would like to display different characters as the player replay/restart the game. How would you go about doing so? Any idea?

This topic has been closed for replies.
Correct answer

var bearOne = new bearMC();
var bearTwo = new bearMC_2();
var bearThree = new bearMC_3();
var characters:Array = new Array(bearOne,bearTwo,bearThree);

var mcChar:MovieClip=characters[int(Math.random()*3)];

addChild(mcChar);

1 reply

January 13, 2011

var characters:Array = new Array("char1","char2","char3");


trace(characters[int(Math.random()*3)]);
MattatronAuthor
Participant
January 13, 2011

If

var bearOne = new bearMC();
var bearTwo = new bearMC_2();
var bearThree = new bearMC_3();
var characters:Array = new Array(bearOne,bearTwo,bearThree);
trace(characters[int(Math.random()*3)]);

how do I display the character using addChild() or another other methods?

Correct answer
January 13, 2011

var bearOne = new bearMC();
var bearTwo = new bearMC_2();
var bearThree = new bearMC_3();
var characters:Array = new Array(bearOne,bearTwo,bearThree);

var mcChar:MovieClip=characters[int(Math.random()*3)];

addChild(mcChar);