Stick – Giavapps Controller

 

Giavapps Controller Stick Initialization

 

gc_stick_init(X, Y, Radius, RadiusDeadZone, SpriteBack, SpriteFront) Initializes all local variables for the stick controller.

X: x position of the stick controller.
Y: y position of the stick controller.
Radius: radius of the stick controller (this value should be the radius of your SpriteBack image).
RadiusDeadZone: radius of the dead zone of the stick controller. If the input amount is lower than the given value the stick controller value is considered to be at 0.
SpriteBack: back sprite image of the stick controller. This image will be also used as mask_index for collision checking.
SpriteFront: front sprite image of the stick controller.

Once you’ve initialized a GameMaker: Studio Object with this function you gain access to the following local variables:

visible Indicates if the stick controller should be visible or not. Mouse Clicks and Touch Inputs will be ignored when the stick controller is invisible but Keyboard Keys and Gamepad Inputs will be still detected.

x x position of the stick controller.

y y position of the stick controller.

radius radius of the stick controller.

radius_deadzone radius of the dead zone of the stick controller.

sprite_back back sprite image of the stick controller.

sprite_front front sprite image of the stick controller.

mask_index collision mask. This should be the same as sprite_back image usually.

direction Indicates the direction of the stick controller. (Value from 0 to 359)

value Indicates the pressure level of the stick controller. (Value from 0 to 1)

value_h Indicates the value of the horizontal axis of the stick controller. (Value from -1 to 1)

value_v Indicates the value of the vertical axis of the stick controller. (Value from -1 to 1)

keyboard_left Indicates the keyboard key used for the left direction. (Default Value: vk_left)

keyboard_right Indicates the keyboard key used for the right direction. (Default Value: vk_right)

keyboard_up Indicates the keyboard key used for the up direction. (Default Value: vk_up)

keyboard_down Indicates the keyboard key used for the down direction. (Default Value: vk_down)

gamepad_device Indicates the gamepad device "slot". (Default Value: 0)

gamepad_left Indicates the gamepad button used for the left direction. (Default Value: gp_padl)

gamepad_right Indicates the gamepad button used for the right direction. (Default Value: gp_padr)

gamepad_up Indicates the gamepad button used for the up direction. (Default Value: gp_padu)

gamepad_down Indicates the gamepad button used for the down direction. (Default Value: gp_padd)

gamepad_axish Indicates the horizontal gamepad axis used for the stick controller. (Default Value: gp_axislh)

gamepad_axisv Indicates the vertical gamepad axis used for the stick controller. (Default Value: gp_axislv)

tweening_speed Indicates the speed of the interpolation used for moving the stick to its original position. This value can be a number from 1 (no tweening) to an higher value. (Default Value: 4)

 

Giavapps Controller Stick Functions

 

gc_stick_step() Updates the stick controller. This function must be called inside the Step Event of the stick controller.

 

gc_stick_draw_gui() Draws the stick controller on the GUI Layer. This function must be called inside the Draw GUI Event of the stick controller.

 

Giavapps Controller Stick Sprites

 

giavapps-controller-stick-sprite

 

Giavapps Controller Stick Sprites can be any size of your choice (we used a 160×160 pixels for SpriteBack image and 128×128 pixels for SpriteFront image) but you should remember centering the origin of the sprite and marking Precise Collision Checking box for precise circle collision checking. The SpriteBack argument of gc_stick_init() function also defines the mask_index used for collision checking. Radius argument should be the radius of your SpriteBack image (we used a 160×160 pixels circle so our radius is 80).

 

Code Examples

 

Creating a Giavapps Controller Stick

 

Create Event

 

gc_stick_init(160, view_hview[0]-160, 80, 0, sprite_giavapps_controller_stick_back, sprite_giavapps_controller_stick_front);//initializes all local variables for the stick controller
gamepad_set_axis_deadzone(gamepad_device,0.15);//sets a dead zone for the specified gamepad controller otherwise the stick could be controlled by the gamepad only
display_set_gui_size(view_wview[0], view_hview[0]);//sets the GUI size since it may vary on different devices

 

Step Event

 

gc_stick_step();//updates the stick controller

 

Draw GUI Event

 

gc_stick_draw_gui();//draws the stick controller

 

Remapping Keyboard Keys and Gamepad Inputs

 

gamepad_axish = gp_axisrh;//sets the horizontal gamepad axis used for the stick controller
gamepad_axisv = gp_axisrv;//sets the vertical gamepad axis used for the stick controller

keyboard_up = ord(‘W’);//sets the keyboard key used for the up direction
keyboard_left = ord(‘A’);//sets the keyboard key used for the left direction
keyboard_down = ord(‘S’);//sets the keyboard key used for the down direction
keyboard_right = ord(‘D’); //sets the keyboard key used for the right direction

 

Moving the Player Object with a Giavapps Controller Stick

 

Step Event

 

var stick = GiavappsControllerStick;//sets a temporary variable to the stick controller object
speed = stick.value;//sets the speed of the player
direction = stick.direction;//sets the direction of the player
image_angle = stick.direction;//sets the rotation of the player

 

I am Luigi Piscopo, also known as DJ GiDeejay / Producer / Remixer in the music world. I am a Producer with a lot of experience in photo editing, video editing, audio editing, graphic design, web design, programming and promotion.

Comments are closed.