1 Reply Latest reply on Aug 15, 2006 12:18 PM by Applied CD

    need help

    Konsurned_Mom


      ok i got my character to move but it wont go up very far or right very far, but i can go all the way left and all the way down

      here is my script

      global Wor
      global movementdirection

      on exitframe

      case movementdirection of
      "left": if sprite("Wor").left > sprite(1).left then
      sprite("Wor").locH = sprite("Wor").locH-1
      end if

      "right": if sprite("Wor").right < sprite(29).right then
      sprite("Wor").locH = sprite("Wor").locH+29
      end if

      "down": if sprite("Wor").bottom > sprite(25).bottom then
      sprite("Wor").locV = sprite("Wor").locV-25
      end if

      "up": if sprite("Wor").top < sprite(1).top then
      sprite("Wor").locV = sprite("Wor").locV+1
      end if

      end case

      go to the frame


      end

      on keydown
      case the keycode of
      123: movementdirection = "left"
      124: movementdirection = "right"
      125: movementdirection = "up"
      126: movementdirection = "down"
      end case


      end


      on keyup
      movementdirection = ""
      end

      can anyone help?
        • 1. Re: need help
          Applied CD Level 1
          Did you intend for your movement values to be asymmetric? I noticed your character moves 1 pixel per frame left and up, but it moves 29 pixels per frame right and 25 pixels per frame down. Also, I see that the sprite numbers you are using to constrain the movement are the same as the movement distance in pixels, is there a reason why they are the same? If you wanted to constrain the movement of your character you can probably do this with a single sprite, draw a big rectangle on the stage and call it “fence”, set its blend to 0, then change your case statement as follows (note that I’ve also evened out the movement rate to 5 pixels/frame in all four directions):

          case movementdirection of
          "left": if sprite("Wor").left > sprite(“fence”).left then
          sprite("Wor").locH = sprite("Wor").locH-5
          end if

          "right": if sprite("Wor").right < sprite(“fence”).right then
          sprite("Wor").locH = sprite("Wor").locH+5
          end if

          "down": if sprite("Wor").bottom > sprite(“fence”).bottom then
          sprite("Wor").locV = sprite("Wor").locV-5
          end if

          "up": if sprite("Wor").top < sprite(“fence”).top then
          sprite("Wor").locV = sprite("Wor").locV+5
          end if

          end case