test3.nim 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # --- Test 3. Window events handling. --- #
  2. import nodesnim
  3. Window("newwindow")
  4. var
  5. mainobj: SceneObj
  6. main = Scene("Main", mainobj)
  7. nodeobj: NodeObj
  8. node = Node("My node", nodeobj)
  9. main.addChild(node)
  10. # Bind actions:
  11. Input.addKeyAction("forward", "w")
  12. Input.addKeyAction("backward", "s")
  13. Input.addKeyAction("left", "a")
  14. Input.addKeyAction("right", "d")
  15. Input.addButtonAction("click", BUTTON_LEFT)
  16. Input.addButtonAction("release", BUTTON_RIGHT)
  17. node.process =
  18. proc() = # This called every frame.
  19. if Input.isActionPressed("forward"): # returns true, when user press "w"
  20. echo "forward"
  21. if Input.isActionPressed("backward"): # returns true, when user press "s"
  22. echo "backward"
  23. if Input.isActionPressed("left"): # returns true, when user press "a"
  24. echo "left"
  25. if Input.isActionPressed("right"): # returns true, when user press "d"
  26. echo "right"
  27. if Input.isActionJustPressed("click"): # returns true, when the user clicks the left button one time.
  28. echo "clicked!"
  29. if Input.isActionReleased("release"): # returns true, when the user no more press on the right button.
  30. echo "release!"
  31. node.input =
  32. proc(event: InputEvent) = # This called only on user input.
  33. if event.isInputEventMouseButton() and event.pressed:
  34. echo "hi"
  35. addScene(main)
  36. setMainScene("Main")
  37. windowLauch()