The forums have permanently moved to forum.kirupa.com. This forum will be kept around in read-only mode for archival purposes. To learn how to continue using your existing account on the new forums, check out this thread.


Results 1 to 8 of 8

Thread: Starfield is in front - urgent

  1. #1

    Starfield is in front - urgent

    Hy

    Could u please help me?
    My starfiels is in front of everything.
    What i need to change so that it is behin everything.

    please help

    thx
    Attached Files Attached Files

  2. #2
    ok i dont have flash on this computer but my first question is are you using any actionscript depths on the stars and just leaving the rest?

  3. #3
    Change the depth of the starfield.

  4. #4
    you need to put your stars in a movieclip and then swapDepths of everything else to be above it

    I don't really use deplicateMovieClip so the easy way was not quite working

    but i think the following should do it or point you in the right direction

    Code:
    _root.hp = 100;
    var stars = 150;
    var maxSpeed = 16;
    var minSpeed = 2
    //create and position stars
    this.createEmptyMovieClip("holder",1);
    hero.swapDepths(10);
    enemy1.swapDepths(11);
    trace(hero.getDepth());
    for (var i = 0; i<stars; i++) {
     var mc = holder.attachMovie("star", "star"+i, i);
     mc._x = random(Stage.width);
     mc._y = random(Stage.height);
     mc.speed = random(maxSpeed-minSpeed)+minSpeed;
     var size = random(2)+0.6*(random(4));
     mc._width = size;
     mc._height = size;
    }
    holder.onEnterFrame = function() {
     for (var j = 0; j<stars; j++) {
      var mc = this["star"+j];
      if (mc._x>0) {
       mc._x -= mc.speed;
      } else {
       mc._x = Stage.height;
       mc.speed = random(maxSpeed-minSpeed)+minSpeed;
       mc._x = random(Stage.width);
      }
     }
     if (paused == false) {
      _root.pause._visible = false;
      moveHero(8);
     } else {
      _root.pause._visible = true;
     }
     if(sound_on!=true){
      stopAllSounds();
     }
    };
     
    stop();
    var numEnemy = 3;
    _root.score = 0;
    var fire = false;
    //attach pause
    _root.attachMovie("pause","pause",1000);
    _root.pause._x=250;
    _root.pause._y=150;
    //make pause invisible
    _root.pause._visible = false;
    //make pause variable
    var paused = false;
    //sound variables
    var sound_on=true;
    //get sounds
    var laser=new Sound();
    laser.attachSound("laser");
    var explode=new Sound();
    explode.attachSound("explode");
    var music=new Sound();
    music.attachSound("musicloop");
    music.start();
    //define a listener
    var listener = new Object();
    listener.onKeyUp = function() {
     var code = Key.getCode();
     if (code == 80) {
      if (paused == false) {
       paused = true;
      } else {
       paused = false;
      }
     }
    };
    Key.addListener(listener);
    //add shooting sound
    var shoot=new Sound();
    shoot.attachSound("shoot");
    //add explosion sound
    var explode=new Sound();
    explode.attachSound("explode");
    function moveHero(speed) {
     //check if key is down
     if (Key.isDown(Key.UP)) {
      _root.hero._y -= speed;
     } if (Key.isDown(Key.LEFT)) {
      _root.hero._x -= speed;
     } if (Key.isDown(Key.DOWN)) {
      _root.hero._y += speed;
     } if (Key.isDown(Key.RIGHT)) {
      _root.hero._x += speed;
     }
     if (Key.isDown(Key.SPACE)) {
      if (fire == false) {
       fireBullets();
      }
     }
    }
    var i = 1;
    function fireBullets() {
     i++;
     if (i==10){
      i=0;
     }
     fire = true;
     _root.hero.gotoAndPlay(2);
     //start sound
     laser.start();
     //name bullets
     var newname = "bullet"+i;
     _root.attachMovie("bullet", newname, i*100);
     _root[newname]._y = _root.hero._y+13;
     _root[newname]._x = _root.hero._x+55;
     _root[newname].onEnterFrame = function() {
      if (paused == false) {
       var bullet_speed = 9;
       this._x += bullet_speed;
       if (this._x>555) {
        this.removeMovieClip();
       }
       for (var h = 1; h<=numEnemy; h++) {
        if (this.hitTest(_root["enemy"+h])) {
         this.removeMovieClip();
         _root["enemy"+h].play();
         //trace("enemy"+h);
         //play explode
         explode.start();
        }
       }
      }
     };
    }
    function Enemys() {
     for (j=2; j<=numEnemy; j++) {
      var name = "enemy"+j;
      _root.enemy1.duplicateMovieClip(name, j+10);
     }
    }
    Enemys();
     
    music.onSoundComplete = function() {
     music.start();
    }

  5. #5
    I think he could just make the depth a very high number and it would work.

    Code:
    starfield._depth = 1000000;
    Not entirely sure though.

  6. #6
    im havnt really worked to much with action script depth but if im not mistaken i believe that if you put a depth on an object in action script and the rest is left alone it will put the actionscript element in front of anything that uses a lower depth such as the basic stage depth.

  7. #7
    Depths in AS2 can cause alot of head aches my advice is search around on Google for a depth managing class for as2, to help you manage the depths of display objects.

  8. #8
    Quote Originally Posted by zerdec View Post
    Hy

    Could u please help me?
    My starfiels is in front of everything.
    What i need to change so that it is behin everything.

    please help

    thx
    Oh damn you made a new thread for this. Neways i posted a solution on your previous thread. Here go check it out.

    http://www.kirupa.com/forum/showthread.php?t=295258

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012