6 Replies Latest reply on Apr 27, 2006 9:06 AM by merc_maniac

    Left Right Up Down arrows

    merc_maniac
      Hello

      I am trying to get a ball to move up down left and right around the stage, using only clicks on the arrows at the bottom of the stage. Here is the code I am using, but there seems to be a problem with it.

      global gvIncrement

      on beginSprite me
      set gvIncrement =2
      se the constraint of sprite the spritenum of me = 1
      end

      on exitFrame me
      case true
      (keypressed(123)): the loch of sprite the spritenum of me = the loch of sprite the spritenum of me - gvIncrement
      (keypressed(124)): the loch of sprite the spritenum of me = the loch of sprite the spritenum of me - gvIncrement
      (keypressed(125)): the locv of sprite the spritenum of me = the loch of sprite the spritenum of me - gvIncrement
      (keypressed(126)): the locv of sprite the spritenum of me = the loch of sprite the spritenum of me - gvIncrement
      end case
      end

      Can anybody point me in the right direction please?
      Tim
        • 1. Re: Left Right Up Down arrows
          Level 7
          I would use an on keyDown function instead of an exitFrame function. You
          probably want that dvIncrement variable to be a property rather than a
          global variable, unless you're using its value somewhere else in the
          movie.

          You say that you are looking for clicks on arrows at the bottom of the
          stage. Are these arrows sprites? The code that you are using is looking
          for key presses on the arrow keys on the computer keyboard. If you want
          to use sprites then the code will be completely different.

          --
          Rob
          _______
          Rob Dillon
          Adobe Community Expert
          http://www.ddg-designs.com
          412-243-9119

          http://www.macromedia.com/software/trial/
          • 2. Re: Left Right Up Down arrows
            Level 7
            On Wed, 26 Apr 2006 09:17:12 GMT, merc_maniac posted in
            macromedia.director.lingo:

            In addition to Rob's observations:

            > Here is the code I am using, but there seems to be a problem with it.

            Care to share what you mean by that? We're not looking over your shoulders
            from out here

            [snip]

            > case true

            I can't test right now, but I suspect that should be:

            case true of



            --
            Mark A. Boyd
            Keep-On-Learnin'
            • 3. Re: Left Right Up Down arrows
              merc_maniac Level 1
              Sorry, I have just started using director recently, so this is all a little new to me. Yes the arrows are sprites, which explains then why the code I am using is not working!

              Does the keypressed 123 refer to the left button on a keyboard, or can it be used in my case allowing the user to press down on a left arrow sprite on stage, which will in turn make the sprite object (a ball) move left?

              Sorry if this seems like a really stupid question.

              Tim

              • 4. Re: Left Right Up Down arrows
                Level 7
                No, you will have to use new and different code to control one sprite
                from another. I can't really tell you what you need to do as I don't
                know what it is that you want to accomplish or what other code you may
                have.

                You might want to go through the tutorials and the example files that
                come with Director. They may help to explain how Director works.

                --
                Rob
                _______
                Rob Dillon
                Adobe Community Expert
                http://www.ddg-designs.com
                412-243-9119

                http://www.macromedia.com/software/trial/
                • 5. Re: Left Right Up Down arrows
                  Level 7
                  The way I would do this.

                  Attach a behavior to the ball with two handlers
                  ====================
                  property spriteNum
                  global theBallsSpriteNum

                  On BeginSprite me
                  theBallsSpriteNum = spriteNum
                  end

                  on MoveBall me, WhichDirection
                  myIncrementAmount = 2
                  case whichDirection of
                  "up":sprite(spriteNum).locV = sprite(spriteNum).locV - myIncrementAmount
                  "down":sprite(spriteNum).locV = sprite(spriteNum).locV +
                  myIncrementAmount
                  "left":sprite(spriteNum).locH = sprite(spriteNum).locH -
                  myIncrementAmount
                  "right":sprite(spriteNum).locH = sprite(spriteNum).locH +
                  myIncrementAmount
                  end case
                  end
                  ===========================

                  Name the arrow cast members up, down,left, right respectively and attach a
                  behavior with this handler

                  ===========================
                  global theBallsSpriteNum
                  property spriteNum

                  on mouseUp me
                  sendSprite(theBallsSpriteNum, #MoveBall, sprite(SpriteNum).member.name)
                  end
                  ===========================

                  A couple of comments.

                  I use an older version of Director. I believe newer versions allow you to
                  name sprite channels, in which case there is no need to save the balls
                  sprite number in a global variable the way I did it here.

                  I use the name of the arrow sprites, so that I can attach the same behavior
                  to each one. This tells the MoveBall handler which direction to move the
                  ball.

                  HTH, Dave




                  • 6. Re: Left Right Up Down arrows
                    merc_maniac Level 1
                    Thanks Dave

                    I have the newer version of Director, so i'll give that a go now.

                    Cheers

                    Tim