1 Reply Latest reply on Jun 3, 2007 4:50 PM by McFazstp

    How to move sprite

    martijntijn
      The answer is probably simple, but i cant find the right syntaxis.

      I want to move my sprite when i press my arrowkeys:

      on moveCharacter()
      me = sprite(charSpriteNumber)

      if (keypressed(numToChar(28))) then
      updatePosition(me, #left)
      else if (keypressed(numToChar(29))) then
      updatePosition(me, #right)
      else if (keypressed(numToChar(30))) then
      updatePosition(me, #up)
      else if (keypressed(numToChar(31))) then
      updatePosition(me, #down)
      end if
      end

      on updatePosition(me, direction)
      case direction of
      #left:
      --sprite(charSpriteNumber).move(20,20)
      put "move left"
      #right:
      put "move right"
      #up:
      put "move up"
      #down:
      put "move down"
      end case

      end


      What should i use instead of: --sprite(charSpriteNumber).move(20,20) ?
        • 1. Re: How to move sprite
          McFazstp Level 1
          on updatePosition(me, direction)
          case ( direction ) of
          #left:
          move = [-20, 0]
          put "move left"
          #right:
          move = [20, 0]
          put "move right"
          #up:
          move = [0, -20]
          put "move up"
          #down:
          move = [0, 20]
          put "move down"
          end case
          sprite(charSpriteNumber).loc = sprite(charSpriteNumber).loc + move
          end