Sunday, June 7, 2009

Yesterday I spent a while trying to learn to program games in Flash. This is the first file I've made, which doesn't do a whole lot but I was excited when I figured out how to make something move using the arrow keys. The reason it changes color when you go different directions is because I wanted to make sure I could have it display different symbols depending on what direction it's going. That way a game character can look like they're walking up/down/left/right. I added the little bouncing white circle because I knew that a walking character would need to have a walking animation in each of its walking directions. I haven't gotten the animation to run except when the square is standing still - I still have to figure that out.

Try clicking on the Flash movie and then play with the arrow keys!


Here are a few things I learned: (this was programmed using actionscript 2.0)

  • The keylistener.onKeyUp event only tells you that some key on the keyboard has been released, but not which key. At first I thought I could use Key.getCode() to found out which key, but it turns out Key.getCode() only tells you the most recent key that was pressed. This means that if you press and hold the down arrow, then press and hold the left arrow at the same time, then release the down arrow, the Key.getCode() method will tell the the left arrow because it was last key pressed, even thought the down arrow is the one that triggered onKeyUp.
  • Hit tests are really easy in flash because movieclips already have a built in method called hitTest. I used it in code for the space bar. If you press the space bar nothing will happen unless you move the red square so it's touching the blue-green colored oval at the top. The code for the hit test is "if (s1.hitTest(npc)){bblHi._visible=true}". You just type the name of one movieclip (the instance name of the square is s1) and then .hitTest(instance name of second movieclip) (the blue green oval is called npc).

No comments:

Post a Comment