Quantcast
Channel: Adobe Community : All Content - Adobe Animate CC - General
Viewing all articles
Browse latest Browse all 13519

Flash Action Script hitTest Change Variable

$
0
0

Hello! I am making a flash game which is my own take on Pacman.  I at trying to make a wall that when the character hits, the character doesn't move at all.  When I put code on the wall itself, the character would hit it, then move forward 10 pixels while the key was pressed and spring back 10 pixels when it wasn't pressed.  Is there any way to make something completely solid? This is the code I was using before. 

 

onClipEvent (enterFrame) {

          if (this.hitTest(_root.char))

          {

                    _root.char._x += 10;

          }

}

 

The code on the character (char) was

 

onClipEvent (enterFrame) {

          var a_variable = 10;

          if (Key.isDown(Key.LEFT))

          {

                    this._x -= a_variable;

                    _root.char.gotoAndStop(2);

          }

          else if (Key.isDown(Key.RIGHT))

          {

                    this._x += a_variable;

                    _root.char.gotoAndStop(1);

          }

          else if (Key.isDown(Key.UP))

          {

                    this._y -= a_variable;

                    _root.char.gotoAndStop(3);

          }

          else if (Key.isDown(Key.DOWN))

          {

                    this._y += a_variable;

                    _root.char.gotoAndStop(4);

          }

}

 

I am wondering if there is a way to set the variable a_variable to 0 when the character hits the wall. 

 

Thanks.

~Walt


Viewing all articles
Browse latest Browse all 13519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>