Skip to content

Instantly share code, notes, and snippets.

View harpwood's full-sized avatar
💪
HaxeFlixel power

Harpwood Studio harpwood

💪
HaxeFlixel power
View GitHub Profile
@harpwood
harpwood / Kill <as3 Snippet>
Last active October 9, 2019 09:25
Simple function that removes from stage and "kills"(nullify) any given movieclip.
private function kill(childObj:String, parentObj:String = ""):void
{
if (this[childObj] != null)
{
if (stage.contains(this[childObj]))
{
if (parentObj != "") this[parentObj].removeChild(this[childObj]);
else removeChild(this[childObj]);
}
@harpwood
harpwood / SoundManager.as
Created November 9, 2019 20:22 — forked from FrancescoMaisto/SoundManager.as
This ActionScript class makes dealing with sounds in Starling very easy and intuitive: once you add a sound to the SoundManager you can easily play it, stop it, change its volume, fade it in, fade it out or cross-fade it with another sound.See more details and usage examples below, in the first comment.
package starling.extensions {
import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.utils.Dictionary;
import starling.core.Starling;
public class SoundManager {
@harpwood
harpwood / approach.gml
Created September 14, 2020 07:46
Move target to endpoint by given amount
/// @func approach(target, endpoint, amount);
/// @description move target to endpoint by given amount
/// @arg target
/// @arg endpoint
/// @arg amount
if(argument0 < argument1) return min(argument0 + argument2, argument1);
else return max(argument0 - argument2, argument1);
@harpwood
harpwood / color_fix.gml
Created January 22, 2022 21:27
Converts RGB hex color to BGR
///@description Converts RGB hex color to BGR
///@arg color RGB hex color to be converted
///@returns BGR hex color
///@example draw_set_color(color_fix($FF0000))
function color_fix(color) {
return ((argument0 & $FF) << 16) | (argument0 & $FF00) | ((argument0 >> 16) & $FF);
}
@harpwood
harpwood / draw_boundbox.gml
Created January 23, 2022 11:44
@description Draws a rectangle around the mask_index
/// @func draw_boundbox(color)
/// @param color
/// @description Draws a rectangle around the mask_index
function draw_boundbox(color, outline) {
draw_set_color(color);
draw_rectangle(bbox_left, bbox_top, bbox_right, bbox_bottom, outline);
draw_set_color(c_white);
}
@harpwood
harpwood / display_get_diagonal_inches.gml
Last active March 8, 2023 15:21
Returns the diagonal screen size in inches
/**
* Calculates the diagonal length of the display in inches based on the display's width, height, and DPI values.
*
* @returns {number} The diagonal length of the display in inches.
*/
function display_get_diagonal_inches()
{
return sqrt(sqr(display_get_width()) + sqr(display_get_height())) / max(display_get_dpi_x(), display_get_dpi_y());
}
@harpwood
harpwood / display_inches_to_pixel.gml
Last active March 8, 2023 15:22
Converts inches into pixels based the current screen
/**
* Converts a length in inches to the equivalent length in pixels, based on the current display's DPI.
* @param {number} inches - The length in inches to convert to pixels.
* @returns {number} The equivalent length in pixels.
*
* @author Written by Gkri (Harpwood studio)
* @license MIT License https://opensource.org/licenses/MIT
*/
function display_inches_to_pixel(inches) {
return max(display_get_dpi_x(), display_get_dpi_y()) * inches;
@harpwood
harpwood / draw_debug_mouse.gml
Last active February 22, 2022 10:04
draw_debug_mouse v0.1.1
///====================================
/// How to use with constructor
///====================================
/// Create event
/// d_mouse = new draw_debug_mouse();
///-----------------------------------
/// Draw event to get room x,y
/// d_mouse.room_xy();
///-----------------------------------
/// Draw GUI event to get GUI x,y
@harpwood
harpwood / audio_queue_manager.gml
Created March 13, 2022 08:05
audio queue manager for GMS2.3.7+
/// @description audio queue manager 0.1.0 alpha
/// Very early version tailored to my needs. It might get
/// heavy changes in the future. I might improve it in the
/// future. Any contribution or suggestions are welcome!
/// Consider each instance as a seperate audio channel
/// You can use more that one instance for multi-channel
/** @Instructions
* Create an empty wav file with your desired duration and name it snd_space
* This wav file will be used as a spacer between the sounds in the queue.
@harpwood
harpwood / display_centimeters_to_pixel.gml
Created March 8, 2023 15:24
Converts a length in centimeters to the equivalent length in pixels, based on the current display's DPI.
/**
* Converts a length in centimeters to the equivalent length in pixels, based on the current display's DPI.
* @param {number} cm - The length in centimeters to convert to pixels.
* @returns {number} The equivalent length in pixels.
*
* @author Written by Gkri (Harpwood studio)
* @license MIT License https://opensource.org/licenses/MIT
*/
function display_centimeters_to_pixel(cm) {
return max(display_get_dpi_x(), display_get_dpi_y()) * cm / 2.54;