none
I Need help RRS feed

  • Question

  • Button = Controls.GetButtonCaption( Controls.LastClickedButton )
    GraphicsWindow.CanResize = "False"
    GraphicsWindow.KeyDown = OnKeyDown
    'Adding in shapes
    spacecraft = Shapes.AddEllipse(40, 60)
    Shapes.Move(spacecraft, 0, 385)
    X = 0
    Y = 385
    Sub OnKeyDown
      If GraphicsWindow.LastKey = "Right" Then
        Shapes.Move(spacecraft, X + 10, Y)
      EndIf
    
      If GraphicsWindow.LastKey = "Left" Then
        Shapes.Move(spacecraft, X - 10, Y)
      EndIf
      EndSub
    

    How can I make the spacecraft go to the right and left more? would I use a for loop or a while loop?

    Thursday, April 12, 2012 4:47 PM

Answers

  • Just change the variable X

    Sub OnKeyDown
      If GraphicsWindow.LastKey = "Right" Then
        X = X + 10
        Shapes.Move(spacecraft, X, Y)
      EndIf
      
      If GraphicsWindow.LastKey = "Left" Then
        X = X - 10
        Shapes.Move(spacecraft, X, Y)
      EndIf
    EndSub

    If you are interested, here is a simple example of keyboard control - it overcomes one issue which is the auto-repeat delay for example.  Import WPC384

    Thursday, April 12, 2012 6:08 PM
    Moderator