In Game Maker Studio, why does the image rotation have to be performed every step?

I'm a software developer who's trying to get into game development casually on the side. I picked up Game Maker Studio a while ago on a Steam Sale, and I'm finally getting into using it, especially after hearing that games like Undertale and Hotline Miami were products of said studio. I'm going through Shaun Spalding's Game Maker tutorials to familiarize myself with some of Game Maker's features and GML's coding syntax.

Following this tutorial, I rolled my eyes a little when he said to put the image_angle = direction; in the step event for my object rather than the creation event to rotate my object's sprite. "Why would you want to set a variable to the same value every frame when you could just set it once upon creation?" I thought to myself in my apparent naivety. But lo and behold, when running my project, the images aren't rotated if the image_angle = direction; is in the create event, and not the step event. Why? If image_angle is a member of my bullet object, shouldn't I be able to set it once upon creation? Or does it somehow reset on every frame?

Naivety indeed! My image_angle = direction; code was on my bullet creation event. An alarm on my ship object is what creates the bullets, then sets their direction. The creation code on my bullet object was being called before the new direction had been set. I removed the creation code from my bullet and added the following code to my ship's alarm.

bullet1 = instance_create(x, y - 16, obj_bullet);
bullet2 = instance_create(x, y - 16, obj_bullet);
bullet3 = instance_create(x, y - 16, obj_bullet);

bullet1.direction = 90;
bullet2.direction = 80;
bullet3.direction = 100;

bullet1.image_angle = bullet1.direction;
bullet2.image_angle = bullet2.direction;
bullet3.image_angle = bullet3.direction;


Which allows the bullets to be created, sets their directions, and then re-angles their images.

A resounding "duh" is in order.

• If this answer was helpful please use the green checkmark to mark as accepted. – user64742 Dec 28 '18 at 7:45