A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Code to generate multiple moving barriers

  1. #1
    Join Date
    Nov 2007

    Smile Code to generate multiple moving barriers

    So I have a simple game going now with a character running forward and I have to jump and duck under barriers. I was able to make it all work so that one of my three random barriers I made comes at a random time at you. However, I don't know how to make it so that multiple barriers come at you. I feel I need some sort of loop. How should I alter the code I have already? This is on one of the barrier moveclips, the first part sets the platform and position to come at you and the second part moves that part towards you. P.s. this is in cs4.

    onClipEvent (load) {
    	plat = Math.floor(Math.random()*3+1);
    	pos = 500+Math.random()*1000;
    	if (plat < 2 ) {
    		_root.platform._x = pos;
    		thing = 1;
    	} else if (plat < 3 && plat > 2) {
    		_root.platform2._x = pos;
    		thing = 2;
    	} else{
    		_root.platform3._x = pos;
    		thing = 3;
    onClipEvent (enterFrame) {
    	if (thing == 1) {
    		_root.platform._x -= 7;
    	if (thing == 2) {
    		_root.platform2._x -= 7;
    	if (thing == 3) {
    		_root.platform3._x -= 7;
    Last edited by Newbieian; 03-31-2010 at 12:05 PM.

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    CFA2h (respect the HEX)
    for the random part.. maybe a timer?

    with a random internal? so that it calls a function at random times?

    (the function being the random attaching of your barrier?)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center