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.

6 Responses to “Stick – Giavapps Controller”

  1. Luis Napoleon Malpica Gonzalez says:

    i just payed for this but i dont know how to add it on my game. there is no clear explanation

    • Hi, just look to the code examples at the end of this page. The first example shows you how to create the Stick. Basically you need to create a new object (you can name it as you prefer), as you can see in these examples I named it GiavappsControllerStick. You can copy and paste the code you find on this website on the specified events but you need to tweak the code a little bit for setting your own sprites… just read the “Giavapps Controller Stick Sprites” paragraph for more info about that. Greetings, Luigi.

      • Luis Napoleon Malpica Gonzalez says:

        i´m sorry but it is not clear… you should create an object on your package in order just to modify parameters and understand much better.

        i dont know where to place: Remapping Keyboard Keys and Gamepad Inputs and Moving the Player Object with a Giavapps Controller Stick / Step Event

        it is just not clear at all…

        also… code examples is just for the object? where to place?… this is why i ask

        • I’ve just released a new version of this Extension which includes objects, sprites and one testing room in order you can easily test it, check scripts and see how this works! 😉 I hope this helps! 🙂 Greetings, Luigi.

          • Luis Napoleon Malpica Gonzalez says:

            hi again! i tryed out on my project and now the game crashes 🙁 can i send the project to you so you can check what is wrong? if so please give me an email. thank you

          • Hi, I’ve tested the new version on an empty and new GameMaker: Studio Project and everything works fine as expected. I also use this in one of my games and it works just fine, I assume you’re doing something wrong within your own Project and this is not related to the usage of this Extension. Try experimenting with very minimalistic Projects first in order you master how this Extension works. I could check some screenshots of relevant code through Facebook: http://m.me/giavapps if I notice something wrong I will let you know.

Leave a Reply

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *

*