Skip to main content
Participating Frequently
December 28, 2015
Question

How can I customise my shooting game with several different 'movieclips' that act as the bullets - AS 3.0

  • December 28, 2015
  • 1 reply
  • 591 views

So I have a very simple shooting game. Right now I have gotten it to shoot with no problem. But what I want to do is randomise the bullet so that it will shoot out different colour bullets that I have created also as movieclips.

The code I have for shooting the same bullet is:

var bulletTimer:Timer = new Timer(200);

bulletTimer.addEventListener(TimerEvent.TIMER, timerListener);

function timerListener(e:TimerEvent):void

{

  //In the Library linkage for a movieclip should be Bullet

  var tempbullet:MovieClip = new bullet();

  //Place the bullet at the tip of the player's gun

  tempBullet.x = player.x +(player.width/2);

  tempBullet.y = player.y;

  tempBullet.cacheAsBitmap = true;

  tempBullet.speed = 10;

  Bullet.push(tempBullet);

  bulletSound.play(); //Play sound

  addChild(tempBullet);

}

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
December 28, 2015

among the ways you could do that is to assign a class property for bullet that let's you assign different colors

Participating Frequently
December 28, 2015

Thank you for your answer. Would you be able to elaborate a bit more on that please?

kglad
Community Expert
Community Expert
December 28, 2015

in your bullet class:

public function set colorF(col:uint):void{

this.transform.colorTransform.color=col;  // import the needed classes

}

and where you create your bullets:

  var tempbullet:MovieClip = new bullet();

bullet.colorF=Math.round(Math.random()*0xffffff);