Gamemaker Studio 2 Gml ◉ < UPDATED >
Changing Sprites:
sprite_index = spr_player_run;
image_speed = 0.2; // Frames per game step (0.2 = slow, 1 = normal)
image_index = 0; // Reset animation
Manual Animation Control:
// Only animate if moving if (hsp != 0 || vsp != 0) sprite_index = spr_player_run; else sprite_index = spr_player_idle;
// Sprite flipping image_xscale = sign(hsp); // Flips left/right (if hsp is -1 or 1)gamemaker studio 2 gml
Sprite Functions:
function Enemy(_name, _hp) constructor name = _name; hp = _hp;static take_damage = function(amount) this.hp -= amount; if (this.hp <= 0) show_debug_message(this.name + " dies!");
// Usage: var goblin = new Enemy("Goblin", 50); var troll = new Enemy("Troll", 120); goblin.take_damage(30);Manual Animation Control: // Only animate if moving
GML uses a prototype-based inheritance model via Objects. You don't write code in a vacuum; you attach scripts to Events inside Objects. Sprite Functions: