GameMaker [Solved] image_angle resets to 0

Bawat

Member
Create event of ClawTest
Code:
var ii = instance_create_deformable(player.x, player.y, spriteID);
ii.image_angle = 180;
Space Bar press event
Code:
image_angle = 180;
The above code runs fine, and I can see through the debugger, that the instance's image_angle has been set to 180. However somewhere before the Draw event, it gets repeatedly set back to 0.

I have used Find & Replace to find all references of image_angle in the project, and have placed a breakpoint at them. However image_angle gets reset to 0 again before any of those breakpoints get hit. Stepping over code until it changes to tell me that whatever is going on is happening between the Step Begin events and the Draw events.

I tested if changing sprite_index could cause this, but it doesn't.

Is this reset to 0 by design?
Anyone have any ideas as to what's going on?
Bawat

Images of image_angle being set, and a video of it getting reset. (You can see image_angle in the debugger)
https://imgur.com/a/cE2jYoM
https://i.gyazo.com/797df24ce2a0e1a083f609eca2c8d297.mp4
 
Last edited by a moderator:
H

Homunculus

Guest
If you draw the sprite manually with draw_sprite for example, built in variables are ignored.

Also, I don’t know how instance_create_deformable works since it’s not built-in, but should you really pass a sprite there instead of an object?
 

Yal

🐧 *penguin noises*
GMC Elder
Add a show_debug_message(image_angle) in the draw event. If the value still is 180, you're drawing the sprite in some way that doesn't preserve it, and if it's NOT 180, you can add debug messages in more places (every time you modify the sprite or other built-in variables) to try to find where it's changed.
 

JaimitoEs

Member
What is the bone declaration? Are you using Spine? This issue is cleary dependent of another factor of your game!
 

Bawat

Member
If you draw the sprite manually with draw_sprite for example, built in variables are ignored.

Also, I don’t know how instance_create_deformable works since it’s not built-in, but should you really pass a sprite there instead of an object?
I am explicitly using image_angle in the draw event, swapping image_angle out for a replacement variable named imageAngle makes everything work fine, but changing it back to image_angle shows that it gets reset to 0.
 
Last edited:
H

Homunculus

Guest
image_index is not image_angle. Can you post the draw code?
 

Bawat

Member
What is the bone declaration? Are you using Spine? This issue is cleary dependent of another factor of your game!
It's a custom bone system, I'm not using Spine. I agree with you, however when I step through to find the line that causes this reset, the reset happens between two different sections of code running.
 

Bawat

Member
image_index is not image_angle. Can you post the draw code?
I meant image_angle, my mistake.
Code:
draw_surface_from_center_begin(image_angle, surface);

    draw_surface_ext(surface, x, y, image_xscale, image_yscale, 0, c_white, 1);

draw_surface_from_center_end();
Code:
///@desc draw_surface_from_center_begin(rotation_angle, surface)
///@param rotation_angle
///@param surface

var c = dcos(argument0);
var s = dsin(argument0);
var surf = argument1;
var imageWidth = surface_get_width(surf) * image_xscale;
var imageHeight = surface_get_height(surf) * image_yscale;

oldX = x;
oldY = y;
x = -imageWidth/2;
y = -imageHeight/2;
var rotateMatrix = matrix_build_identity();
rotateMatrix[0] = c;
rotateMatrix[1] = -s;

rotateMatrix[4] = s;
rotateMatrix[5] = c;

rotateMatrix[12] = oldX;
rotateMatrix[13] = oldY;
rotateMatrix[14] = 0;

matrix_set(matrix_world, rotateMatrix);
Code:
///@desc draw_from_center_end()

matrix_set(matrix_world, matrix_build_identity());
x = oldX;
y = oldY;
 

Bawat

Member
I've found what is causing the image_angle to be reset to 0.
My game uses Game Maker's inbuilt physics engine.
Commenting
Code:
physics_fixture_bind(fixture, id);
Out of the instance's Creation Event stops image_angle being constantly reset to 0 before the draw event.
Any idea why this is?
 
C

Catastrophe

Guest
I don't know, do you set "image angle = -phy_rotation" as you typically do in physics?

We really need all your relevant code, so far it seems like every post you're mentioning more stuff xD
 

Bawat

Member
It seems that binding a fixture will lock image_angle to whatever value it held before the fixture was bound.
So if you change it, it will only remain changed for a short while before being reverted back.

Thank you all for the helpful comments, wish I could have been clearer with all the information.
I will have to use phy_rotation as @JaimitoEs says.
Thanks again everyone!
 
Top