• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Randomize Game Characters

New Here ,
Jan 13, 2011 Jan 13, 2011

Copy link to clipboard

Copied

Hi guys,

thanks to Hakan KIRIK, i've learnt hw to display random game characters as an individual using the code below:

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);

Currently, I'm looking deeper.. Let's say if I'm displaying the characters in different parts say Head, Body and Arms, etc.. How do I make sure when I randomize the characters, the correct part of each character is displayed correctly? Instead of characterOne's head appear with characterTwo's Body and characterThree's Arms for example.

TOPICS
ActionScript

Views

411

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2011 Jan 14, 2011

Copy link to clipboard

Copied

If I understood you correctly, you can do something like

var bearOne:Array = [new BearHead1(), new BearBody1(), new BearArms1()];

or better still

var bearOne:Object = {head: new BearHead1(), body: new BearBody1(), arms: new BearArms1()};

or even better still

var bearOne:Bear = new Bear(1);

// "Bear" is a class defines bear's body parts depending on the argument

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jan 14, 2011 Jan 14, 2011

Copy link to clipboard

Copied

LATEST

It isn't clear in what context you would be using body parts.  If you are using arrays for the body parts the same way you do for the bears then you would want to store the random variable such that you could use it multiple times before you are done with a given bear.  Otherwise, the 2nd suggestion to use an object to define the parts that belong to each bear would be a better storage vehicle.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines