Fangames > Game Design

How to save the kid's xscale?

(1/1)

l3agu32:
In the fangame I'm creating, when I press R the kid is always created facing the right (xscale=1), even if I shoot the save point facing the left (xscale=-1), how do I fix this? Thank you!

Kyir:
just include player.image_xscale in the save and load scripts I'd guess? I think that would work at least.

patrickgh3:
I like to do this in my games as well. You'll need to modify the save file code to save and load an extra variable of whether the player's facing left or right.

--- Code: ---Save script
/*save player x, y, room, etc */
file_bin_write_real(player.image_xscale+1)


Load Script
/* create player, load x, y, etc */
player.image_xscale = file_bin_read_real(file)-1

--- End code ---

Simple enough. Be sure you add those lines in the same position relative to the other read and write functions. For simplicity it's probably best to add them at the end, after all the other reads / writes. And of course they belong before the file_bin_close lines; use common sense!

But wait, what are those mysterious "+1" and "-1"s doing there? Well, the player's xscale is going to be either 1 or -1, and the file_bin functions only write and read positive numbers. So, we add 1 so that the number we save is either 0 or 2, and when we load it we subtract back that 1.

So yeah, it's pretty simple to save extra stuff in save files. But xscale can be tricky because of that negative thing.

Edit: get rekt Kyir

Kyir:
Hey, I didn't specify how to include it, so my advice is perfectly valid.

Navigation

[0] Message Index

Go to full version