gamnit :: VirtualGamepad :: add_button
Fired events use name
, it should usually correspond to a
keyboard key like "space" or "a".
texture
is displayed at the button position, it also sets the
touchable surface of the button.
If this method is called, it should be after add_dpad
to
avoid overlapping controls.
A maximum of 6 buttons may be added using this method when
there is less than 2 DPad
. Otherwise, only 2 buttons can be added.
# Add and return a round button to a default location
#
# Fired events use `name`, it should usually correspond to a
# keyboard key like "space" or "a".
# `texture` is displayed at the button position, it also sets the
# touchable surface of the button.
#
# If this method is called, it should be after `add_dpad` to
# avoid overlapping controls.
#
# A maximum of 6 buttons may be added using this method when
# there is less than 2 `DPad`. Otherwise, only 2 buttons can be added.
fun add_button(name: String, texture: Texture): nullable RoundButton
do
if n_dpads == 2 and button_positions.length == 6 then
# Drop the bottom 4 buttons
button_positions.remove_at 4
button_positions.remove_at 3
button_positions.remove_at 1
button_positions.remove_at 0
end
assert button_positions.not_empty else print_error "Too many buttons in {self}"
var pos = button_positions.shift
var but = new RoundButton(
app.ui_camera.bottom_right.offset(pos.x, pos.y, 0.0), name, texture)
controls.add but
return but
end
lib/gamnit/virtual_gamepad/virtual_gamepad.nit:140,2--168,4