NewInput
InputIndex = NewInput(Xpos, Ypos, StartingText$)
 
Parameters:

    Xpos = The Xpos of the input cursor
    Ypos = The Ypos of the input cursor
    StartingText$ = The starting text of the input handler
Returns:

    InputIndex = The Index of the newly created input handler
 

      The NewInput function creates an asynchronous input handler ready for use. Unlike the traditional input statement found in older flavors of basic (which isn't very useful for games ) PB's input expansion library gives us the ability to manage/poll user text input during each update of your game. So you can receive input while your game is running!

      The "Input" library manages inputs handlers with a collection of simple functions. These functions allow us to create/delete/poll and query the important properties of the input handler.




FACTS:


      * The NewInput function is part of the "Input" expansion library. Therefore in order to use NewInput in program you need to include that library in your project. To do so, place I.e. #include "Input" at the top of the your program.

      * When an input handler is created with NewInput the handler defaults to Activate mode. When Activate mode is enabled the input handler is active (True) and can receive text input, when it's False, the handler will no longer receive input from the user (the User Hit Enter). You can query the input state using the GetInputActive() function.

      * Use Input() the query the input handler each update

      * Need an old school Input replacement, see the StaticInput() function





Mini Tutorial:


      This example demonstrates the use of asynchronous input. The demo just sets up an input handler and render loop. The loop will execute until the input handler is no longer active (the user pressed Enter). It will then display the entered text message before exiting. The interesting thing about this is that since we control the input loop, we can draw pretty much anything you like while input is taking place. Which is represented by a moving circle.


  
  
; Include the Input Library
  #Include "input"
  
  
; limit the FPS rate to 60 frames per second or less
  SetFPS 60
  
  Sw=GetScreenWidth()
  Sh=GetScreenHeight()
  
  
; load the arial font as font #2, size 32
  LoadFont "arial",2,32,0
  
  
; Create a new input prompt at Xpos 20, Ypos=250,
; with a custom starting text
  MyInput     =NewInput(20,250,_
  "Example Async Input (Get Input While Your Game Updates)")
  
  
; set this input routine to use Font #2
  Inputfont MyInput,2
  
; create some variables to hold and position
; and direction of our moving ball
  x#=Rnd(sw)
  y#=Rnd(sh)
  angle#=Rnd(360)
  
  
  Repeat
   ; clear the Screen to black (rgb(0,0,0)
     Cls RGB(0,0,0)
     
     Print FPS()
     
   ; draw and move our circle
     CircleC x#,y#,50,true,RGB(0,255,0)
     x#=x#+CosRadius(angle#,2)
     y#=y#+SinRadius(angle#,2)
     If X#<0 Then x#=0 : angle#=Rnd(360)
     If X#>sw Then x#=sw : angle#=Rnd(360)
     If Y#<0 Then Y#=0 : angle#=Rnd(360)
     If Y#>sh Then Y#=sh : angle#=Rnd(360)
     
     
   ; Call the Input Poll function to update
   ; and draw this input message
     Input(MyInput)
     
     
   ; refresh the display so the user can see it
     Sync
     
   ; Loop until the user hits Enter!
  Until GetInputActive(MyInput)=false
  
; wait until no keys are being pressed
  WaitNoKey
  
  Cls RGB(0,0,0)
  
; Display what the user typed
  Print GetInputText(MyInput)
  
; Refresh the screen and wait for a key to be pressed
  Sync
  WaitKey
  




This example would output.

  
  Example Async Input (Get Input While Your Game Updates
  

 
Related Info: DeleteInput | GetInputActive | GetInputText | Inkey$ | Input | InputFont | KeyState | Mouse | Scancode | StaticInput :
 


(c) Copyright 2002 - 2024 - Kevin Picone - PlayBASIC.com