Keep my laser moving

  • mikeroesoft
  • Newbie
  • Newbie
  • mikeroesoft
  • Posts: 6
  • Loc: London, England UK

Post 3+ Months Ago

Hi there

I need help to keep a laser moving when it’s fired in a shooter game.

The problem is it stops moving in mid flight if the player releases the space bar.

I’ve tried all of the following possible solutions:

• Forcing the laser to keep moving if it’s X position is less than a certain distance

• Only visualising the laser if a Boolean variable is true when triggered by the space bar (while the laser keeps moving invisibly)

• Only aligning it with the ship if a Boolean variable is true (while it moves off stage)

But they don’t work. All the code is simple. Here it is:

Code: [ Select ]
//This code goes in frame 1

//Make clips dynamic.
attachMovie("laser","laser",80);
attachMovie("ship","ship",100);

//Place ship.
_root.ship._x = 275;
_root.ship._y = 200;

//Align the laser to the ship (to stop it first appearing anywhere else).
_root.laser._x = _root.ship._x;
_root.laser._y = _root.ship._y;

//Generate a new laser clip every 4 seconds.
generate = setInterval(generatelaser,4000);

//Define generate laser function
function generatelaser(){
_root.laser._x = _root.ship._x;
_root.laser._y = _root.ship._y;
}

//This code goes in a separate actions clip

onClipEvent(enterFrame){

//Define fire function
function fire(){
_root.laser._x+=40;
    }
if(_root.laser._x>4000){
 _root.laser.removeMovieClip();
   }
if(Key.isDown(Key.SPACE)){
  fire();
  }
}
  1. //This code goes in frame 1
  2. //Make clips dynamic.
  3. attachMovie("laser","laser",80);
  4. attachMovie("ship","ship",100);
  5. //Place ship.
  6. _root.ship._x = 275;
  7. _root.ship._y = 200;
  8. //Align the laser to the ship (to stop it first appearing anywhere else).
  9. _root.laser._x = _root.ship._x;
  10. _root.laser._y = _root.ship._y;
  11. //Generate a new laser clip every 4 seconds.
  12. generate = setInterval(generatelaser,4000);
  13. //Define generate laser function
  14. function generatelaser(){
  15. _root.laser._x = _root.ship._x;
  16. _root.laser._y = _root.ship._y;
  17. }
  18. //This code goes in a separate actions clip
  19. onClipEvent(enterFrame){
  20. //Define fire function
  21. function fire(){
  22. _root.laser._x+=40;
  23.     }
  24. if(_root.laser._x>4000){
  25.  _root.laser.removeMovieClip();
  26.    }
  27. if(Key.isDown(Key.SPACE)){
  28.   fire();
  29.   }
  30. }

Many thanks for anyone’s help.

mikeroesoft
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Jono S.D.
  • Newbie
  • Newbie
  • User avatar
  • Posts: 13
  • Loc: Shetland, Scotland

Post 3+ Months Ago

you should make the laser delete itself when its way off the page.
im not too sure of much code yet as im new to this stuff too but there is a tute on:
[url]http://www.flashkit.com/tutorials/Games/Building-David_Do-598/index.php[/url]
sorry its not much help![/url]
  • mikeroesoft
  • Newbie
  • Newbie
  • mikeroesoft
  • Posts: 6
  • Loc: London, England UK

Post 3+ Months Ago

Thanks Jono

mikeroesoft

Post Information

  • Total Posts in this topic: 3 posts
  • Users browsing this forum: No registered users and 12 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.