A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Newby! :( - flash game

  1. #1
    Junior Member
    Join Date
    Apr 2006
    Posts
    1

    Newby! :( - flash game

    Hi,

    I am attempting to make a side-scrolling space shooter game with flash,

    I'm having a bit of a problem getting my ship to move correctly.

    So far I have just made a square button on the stage and named it "Button" with an instance name of "Button_btn".

    I have attached the script -

    on (keyPress "<Left>") {
    this.Button_btn._x = this.Button_btn._x - 5;
    }

    on (keyPress "<Right>") {
    this.Button_btn._x = this.Button_btn._x +5;
    }

    on (keyPress "<Up>") {
    this.Button_btn._y = this.Button_btn._y - 5;
    }

    on (keyPress "<Down>") {
    this.Button_btn._y = this.Button_btn._y +5;
    }

    This works fine for moving the ship up, down, and left to right, however it does not move diagonly when, for example the "Left" key and "Up" key are both held down, it will move either to the left only, or up.

    I'm sure the code will be large, but if anyone can help!!

    It would be much appreciated!!!

    Thanks!

  2. #2
    I would change your button "ship" into a movie clip. Put the following code onto it.

    Code:
    onClipEvent (enterFrame) {
    	if (Key.isDown(Key.UP)) {
    		this._y -= 5;
    	} else if (Key.isDown(Key.DOWN)) {
    		this._y += 5;
    	}
    	
    	if (Key.isDown(Key.RIGHT)) {
    		this._x += 5;
    	} else if (Key.isDown(Key.LEFT)) {
    		this._x -= 5;
    	}
    	
    }
    If you need me to explain any of the previous code, just ask. Good luck coding!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center