Introducing Dragonfly Cloud! Learn More

Question: How do you flip a sprite in GameMaker?

Answer

Flipping a sprite in GameMaker can be done by adjusting the image_xscale and image_yscale properties of an instance. These properties can be set to -1 to flip a sprite horizontally or vertically.

Here's how you can flip a sprite:

Horizontally:

// This will flip the sprite horizontally image_xscale = -1;

Vertically:

// This will flip the sprite vertically image_yscale = -1;

When flipping sprites, consider the following points:

  • A value of 1 for image_xscale or image_yscale means no scaling is applied, and the sprite is drawn normally.
  • A negative value flips the sprite across the corresponding axis.
  • You can also apply these properties to stretch a sprite by setting them to a value other than -1 or 1.
  • If you want to flip the sprite back to its original state, set image_xscale and/or image_yscale back to 1.

Finally, if you need to flip the sprite for a specific drawing event rather than altering the instance itself, use the draw_sprite_ext function:

// Draw the sprite flipped horizontally without affecting the instance's actual image_xscale draw_sprite_ext(sprite_index, image_index, x, y, -1, 1, 0, c_white, 1); // Draw the sprite flipped vertically without affecting the instance's actual image_yscale draw_sprite_ext(sprite_index, image_index, x, y, 1, -1, 0, c_white, 1);

In this way, flipping is done on-the-fly during rendering and does not change the underlying properties of the instance.

Was this content helpful?

White Paper

Free System Design on AWS E-Book

Download this early release of O'Reilly's latest cloud infrastructure e-book: System Design on AWS.

Free System Design on AWS E-Book

Start building today 

Dragonfly is fully compatible with the Redis ecosystem and requires no code changes to implement.