samples/05_mouse/04_coordinate_systems/app/main.rb
# This sample app shows a coordinate system or grid. The user can move their mouse around the screen and the
# coordinates of their position on the screen will be displayed. Users can choose to view one quadrant or
# four quadrants by pressing the button.
This sample app shows a coordinate system or grid. The user can move their mouse around the screen and the
coordinates of their position on the screen will be displayed. Users can choose to view one quadrant or
four quadrants by pressing the button.
This sample app shows a coordinate system or grid . The user can move their mouse around the screen and the coordinates of their position on the screen will be displayed . Users can choose to view one quadrant or four quadrants by pressing the button .
def tick args
  pos = args.inputs.mouse.position 
  args.outputs.labels << [pos.x + 10, pos.y + 10, "#{pos}"] 
  args.outputs.solids << [pos.x -  2, pos.y - 2, 5, 5] 
  button = [0, 0, 370, 50] 
  args.outputs.borders << button 
  args.outputs.labels << [10, 35, "click here toggle coordinate system"] 
  args.outputs.lines << [    0, -720,    0, 720] 
  args.outputs.lines << [-1280,    0, 1280,   0] 
  if args.inputs.mouse.click 
    pos = args.inputs.mouse.click.point 
    if pos.inside_rect? button 
      if args.grid.name == :bottom_left 
        args.grid.origin_center! 
      else
        args.grid.origin_bottom_left! 
      end
    end
  end
  tick_instructions args, "Sample app shows the two supported coordinate systems in Game Toolkit."
end
def tick args pos = args . inputs . mouse . position args . outputs . labels << [ pos . x + 10 , pos . y + 10 , "#{pos}" ] args . outputs . solids << [ pos . x - 2 , pos . y - 2 , 5 , 5 ] button = [ 0 , 0 , 370 , 50 ] args . outputs . borders << button args . outputs . labels << [ 10 , 35 , "click here toggle coordinate system" ] args . outputs . lines << [ 0 , - 720 , 0 , 720 ] args . outputs . lines << [ - 1280 , 0 , 1280 , 0 ] if args . inputs . mouse . click pos = args . inputs . mouse . click . point if pos . inside_rect? button if args . grid . name == :bottom_left args . grid . origin_center! else args . grid . origin_bottom_left! end end end tick_instructions args , "Sample app shows the two supported coordinate systems in Game Toolkit." end
This sample app shows a coordinate system or grid.
This sample app shows a coordinate system or grid .
# The addition and subtraction in the first two parameters of the label and solid # ensure that the outputs don't overlap each other. Try removing them and see what happens. # stores coordinates of mouse's position # outputs label of coordinates # outputs small blackk box placed where mouse is hovering # sets definition of toggle button # outputs button as border (not filled in) # label of button # vertical line dividing quadrants # horizontal line dividing quadrants # if the user clicks the mouse # pos's value is point where user clicked (coordinates) # if the click occurred inside the button # if the grid shows bottom left as origin # origin will be shown in center # otherwise, the view will change to show bottom left as origin
args