• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Drawing A Sprite On A Layer

I'm attempting to draw a sprite on a specific low-layer to use as a background but I can't figure out how to draw on a specific layer in such a way that I can move the sprite around each step for scrolling
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
You want to create a sprite asset then store the element ID for it in a variable so you can move it. So, look at the functions:


Alternatively, simply assign the sprite to an object, create the object on the layer, then move the object. :)

PS: It's worth noting that a single layer can actually hold mixed assets, so if you have a background layer in your room (for example) you can create an instance on it, or add a sprite asset to it etc... The idea that there are "instance" layers and "tile" layers is purely a fiction for the room editor to make editing things easier. A single layer can actually hold anything...
 
You want to create a sprite asset then store the element ID for it in a variable so you can move it. So, look at the functions:


Alternatively, simply assign the sprite to an object, create the object on the layer, then move the object. :)

PS: It's worth noting that a single layer can actually hold mixed assets, so if you have a background layer in your room (for example) you can create an instance on it, or add a sprite asset to it etc... The idea that there are "instance" layers and "tile" layers is purely a fiction for the room editor to make editing things easier. A single layer can actually hold anything...
That's my mistake. I was trying to store an ID in from the layer_sprite_create and then do something like background_1.x so Game Maker was yelling at me about using a function as a variable. I didn't realize there was specific layer_sprite location functions.
 
Perfect. This setup gave me perfect scrolling with no jitter. I used room start since it's done a persistent game controller object.

Room start event (I'll add if statements to make it check the room to know which background to pull later on):

GML:
/// @description instalize background

background_1 = layer_get_id ("BG_1");
BG_1 = layer_sprite_create(background_1, 0, 0, Cemetary_Background);

End step event:

GML:
/// @description move background

//Move background
cam_x = camera_get_view_x(view_camera[0]);
cam_y = camera_get_view_y(view_camera[0]);

layer_sprite_x(BG_1, cam_x);
layer_sprite_y(BG_1, cam_y);
 
Last edited:
Top