0

I am trying to make a simple as2 shooter but when I try to shoot an enemy the bullet just go thru it and doesn't remove the enemy. I tried to put if (hitTest(_root.vihollinen)==true ){ _root.vihollinen.remove(); this.removeMovieClip(); } but nothing happens Most of the code is just copy/paste because I don't know much about coding but I'm trying to learn! https://www.dropbox.com/s/58u34tbeve6oile/game.zip

1 Answers1

0

The most significant issue is that your enemy needs an Instance Name in order for the code to understand it. Simply click on your enemy movieclip, and add vihollinen to the Instance Name field at the top.

Next, your bullet code is close, but needs some adjustments. Here is your code:

_root["bullet" + bulletsFired].onEnterFrame = function(){
    this._x += this.xmov;
    this._y += this.ymov;
    if (hitTest(_root.vihollinen)==true){
        _root.vihollinen.remove();
        this.removeMovieClip();
    }
};
  1. If you're ever using an onEnterFrame handler like that with a function, it's good practice to always refer to the current object with this, like so: if(this.hitTest(_root.vihollinen) == true){

  2. remove() is not an ActionScript2 function. Try using unloadMovie() instead, like this: _root.vihollinen.unloadMovie()

Changing those three things will make your code function. Be sure that you try to go through each part of your code and understand it to the best of your ability - it'll make things much easier in the long run, even if it takes a long time to figure out why each part is there!

interpolack
  • 876
  • 10
  • 26