PHP MySQL ebook
February 12, 2011 – 4:57 pm | No Comment

Hey everyone!!
With this section I hope to share with you resources which I have tried and valued
So you’re new to PHP and want to learn from scratch. Well I was in your position not too …

Read the full story »
SEO Tutorials

Need help with Search Engine Optimisation? This is the place to look for the latest tips and hints with the advice we offer. Keep an eye out here for the latest posts.

PHP Tutorials

Learn how to code with PHP to achieve your goal. In here I aim to show and teach you about little tips and tricks that should enhance your coding abilities

Flash Tutorials

Learn how to use Adobe Flash for your own purposes. Little tips and hints to help you along

Website Development

In here I aim to help you with developing your website from scratch. Come here for various tips and pieces of advice to help you build and improve your website.

Home » Flash Tutorials

Movement + Rotation In Flash

Submitted by on July 29, 2007 – 3:20 pmNo Comment

Have you seen these flash space games where you can move and rotate a spaceship. well here is how to do it.

1- Load up flash MX and set the document size to 550 by 400. to do this go to modify>document.

2- create a spaceship what ever you want it to be.

3- select it and press on F8 select movieclip and the press ok.
Press on the spaceship now and load up the actions panel by going to windows>actions. make sure it says Actions-Movie clip not Actions-frame.
add the following in the actions box:

Actionscript:
  1. onClipEvent (load) {
  2. thrust = 1; //sets speed
  3. decay = 1;//sets strenght not needed at the moment
  4. maxSpeed = 15;//maximum speed
  5. }
  6. onClipEvent (enterFrame) {
  7.  
  8. if (Key.isDown(Key.RIGHT)) { //if right button is down
  9. _rotation += 10; //rotate 10 degreese clockwise
  10. }
  11. if (Key.isDown(Key.LEFT)) { //if left button is down
  12. _rotation -= 10; //rotate 10 degreese anti-clockwise
  13. }
  14. if (Key.isDown(Key.UP)) {//if up button is down
  15. xSpeed += thrust*Math.sin(_rotation*(Math.PI/180));
  16. ySpeed += thrust*Math.cos(_rotation*(Math.PI/180));
  17.  
  18. } else {
  19. xSpeed *= decay;
  20. ySpeed *= decay; //slow down
  21.  
  22. }
  23. speed = Math.sqrt((xSpeed*xSpeed)+(ySpeed*ySpeed));
  24. if (speed>maxSpeed) {
  25. xSpeed *= maxSpeed/speed;
  26. ySpeed *= maxSpeed/speed;
  27. }
  28. _y -= ySpeed;
  29. _x += xSpeed;
  30.  
  31. //make the ship come back on screen if it goes out of view
  32. if (_y<0) {
  33. _y = 400; // document height
  34. }
  35. if (_y>400) {
  36. _y = 0;
  37. }
  38. if (_x<0) {
  39. _x = 550; //document width
  40. }
  41. if (_x>550) {
  42. _x = 0;
  43. }
  44. }

test the movie by clicking control+ enter
That should do the job neatly. If you have any problems or errors coming up please do not hesitate to contact me.

VN:F [1.9.13_1145]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.13_1145]
Rating: 0 (from 0 votes)

Popularity: unranked [?]

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

You can use these tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.