5 Replies Latest reply on Oct 30, 2007 4:54 PM by chrisf671

    staying in screen

    chrisf671
      Hello,
      Can someone please give me a code clip to add to a movie clip that that will make it so it does not go out of screen when moved around by the keyboard commands. im making a spaceship game and it pointless if you can go out of screen to avoid the astriods.
      Thanks a lot.
        • 1. Re: staying in screen
          clbeech Level 3
          you need to set up some conditional checks to determine if the MC is beyond the Stage bounds, if it is: don't move, if not: move. This should be with the event that moves the ship, assumably within an onEnterFrame or Inverval loop.

          What is the code you are using to move the ship?
          • 2. Re: staying in screen
            chrisf671 Level 1
            this is the code i am using on the ship to move up and down.


            onClipEvent (load) {
            movement = 4;
            }
            onClipEvent (enterFrame) {
            if (Key.isDown( 38 )) {
            this._y = this._y - movement;
            }
            if (Key.isDown( 40 )) {
            this._y = this._y + movement;
            }
            }
            • 3. Re: staying in screen
              chrisf671 Level 1
              sorry heres a attach code version, it has all of the proper spaces in it.
              • 4. Re: staying in screen
                clbeech Level 3
                OK a few things, first I'd put the codes on the main timeline, in a layer called actions, rather than attached to an instance. There are many ways to go about achieving what you're looking for here, so I just made up a quick sample that you can take a look at to give you a few ideas about how you would like to make you system work. Look in the code on frame one, and study it, see what it's doing and then tailor it the way you want it, don't be afraid to experiement and try new things with it, but I would suggest reading up on the classes involved with this code and that should even give you more ideas :)

                FLA SAMPLE
                • 5. Re: staying in screen
                  chrisf671 Level 1
                  Thanks a lot cbeech this will realy help.