Skip to content

Instantly share code, notes, and snippets.

Avatar

Poppy Works PoppyWorks

View GitHub Profile
@PoppyWorks
PoppyWorks / string_button()
Last active Apr 1, 2019
Replace common terms with special symbols for platform buttons
View string_button()
///string_button(string)
var str = argument0;
///XO - PlayStation Controller Keys
if os_type == (os_psvita || os_ps4)
{
str = string_replace_all(str,"CONFIRM","➀");
str = string_replace_all(str,"CANCEL","➁");
str = string_replace_all(str,"BUTTON3","➂");
str = string_replace_all(str,"BUTTON4","➃");
@PoppyWorks
PoppyWorks / button_ui_held
Last active Aug 22, 2018
GML Script. Should be run on an object that you wish to have the player click. Create an obj_cursor for console users and move it around via the gamepad to have this script work for both gamepad. mouse, and touchscreen users.
View button_ui_held
///button_ui_held(device number, button)
var me = id;
return position_meeting(mouse_x,mouse_y,me) && mouse_check_button(mb_left) || place_meeting(x,y,obj_cursor) && gamepad_button_check(argument0,argument1)
@PoppyWorks
PoppyWorks / button_check
Last active Aug 14, 2018
GML Script. Used in step after setup_inputs has been used. This is a generic input script that can change back and forth from keyboard/mouse to gamepad via the input_change swapper. Example: button_check(0,global.confirm);
View button_check
///button_check(device number, button)
return keyboard_check(argument1) || gamepad_button_check(argument0,argument1)
@PoppyWorks
PoppyWorks / gamepad_button_check_any
Created Aug 13, 2018
GML Script. Checks to see if the device number (argument0) was interacted with at all. Used in input_change() to know to swap inputs!
View gamepad_button_check_any
///gamepad_button_check_any(device)
device = argument0;
for ( var i = gp_face1; i < gp_axisrv; i++ )
{
if ( gamepad_button_check(device , i ) ) return i;
}
return false;
@PoppyWorks
PoppyWorks / input_change
Last active Aug 14, 2018
GML Script. Knows what OS you are using, and if you are using a gamepad or keyboard/mouse. Use bootstrap after input_change(). Bootstrapper ensures that a gamepad is connected before allowing the user to swap over to gamepad input from Keyboard/mouse.
View input_change
///PC users or PS4 Input
if os_type == os_windows || os_ps4 || os_xboxone
{
if gamepad_button_check_any(global.gpDevice)
{
global.KBMuser = false;
}
if keyboard_check(vk_anykey) || mouse_check_button(mb_any)
{
global.KBMuser = true;
@PoppyWorks
PoppyWorks / setup_input
Created Aug 13, 2018
GML script. Sets up our globals for all input functions in other scripts posted here.
View setup_input
///setup_input(run in a create event!)
//gamepads
var gp_num = gamepad_get_device_count();
for (var i = 0; i < gp_num; i++;)
{
if gamepad_is_connected(i)
{
alert("DEBUG: "+ string(gamepad_get_description(i)),0)
}
else
@PoppyWorks
PoppyWorks / alert
Last active Jul 27, 2018
GML Script. A basic multi-level wrapper for the debug/message system used in Gamemaker Studio. Alert will be seen throughout our samples here. When shipping, you can comment the entire script out easily!
View alert
///alert(level[0 to 3],message)
var level = argument0;
var text = argument1;
{
switch (argument0)
{
case 0: show_debug_message("DEBUG: "+text); break;
case 1: show_debug_message("ERROR: "+text); break;
case 2: show_message("ALERT: "+text); break;
@PoppyWorks
PoppyWorks / audio_play
Created Jul 23, 2018
GML Script. By using this after our setup_listeners(); gist, you can play audio on any listener, fade over time, and loop.
View audio_play
///audio_play(listener,snd_filename,fade in time[ms],loop?)
var listener = argument0;
var sfx = argument1;
var time = argument2;
var loop = argument3;
if gamepad_is_connected(listener)
{
sfx = audio_play_sound_on(listener, sfx, loop, 0);
}
else if listener == noone || listener == -1
@PoppyWorks
PoppyWorks / setup_audio
Last active Aug 14, 2018
GML Script. This sets up all listeners available on a target platform. In the case of PS4, you can use this to play audio on a DS4 speaker. Run before running anything using audio_play_sound_on();. In addition, this fixes GMS games being too quiet or low volume on consoles. Best run in a Create event.
View setup_audio
///setup_audio();
var lc = audio_get_listener_count();
var masks;
masks[0] = 0;
masks[1] = 0;
masks[2] = 0;
masks[3] = 0;
alert("Number of Audio Listeners: " + string(lc),0)
@PoppyWorks
PoppyWorks / draw_fade_color
Last active Jul 23, 2018
GML script. Will fade the screen to the chosen color. Returns true when done. This can be used to change rooms when it returns. Line 6 can be un-commented to do the fade to color in steps, to simulate old-school style color fading.
View draw_fade_color
///draw_fade_color(color,speed/alplha)
alert(0,"Fading..." + "(" + (string(color_fade_alpha)) +"). Cannot pause game." )
can_pause = false;
depth = -100000
var snapped = color_fade_alpha//= floor(color_fade_alpha * 10)/10
draw_set_colour(argument0)
draw_set_alpha(snapped);
draw_rectangle(0, 0, view_xview [0] + view_wview[0], view_yview[0] + view_hview[0], false);
draw_set_blend_mode_ext(bm_src_colour,bm_zero);
You can’t perform that action at this time.