• Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Question - Code Changing a Background's Position

M

Mycomancer

Guest
In GMS1 parallax scrolling was very easy to do. You would just update the position of each background each frame like so.
Code:
background_x[0] = view_xview[0];
background_y[0] = view_yview[0];

background_x[1] = view_xview[0]/2;
background_y[1] = view_yview[0]/2;

background_x[2] = view_xview[0]/4;
background_y[2] = view_yview[0]/4;
In GMS2 I can't seem to find a way to do this. Looking over the documentation for background layers, most of the same functionality (such as changing the tiling or the alpha) has returned, but setting the x and y seems... absent. I can set the x and y offsets in the editor just like before, but I don't see a way to do this in code.

Am I missing something obvious or is that actually not here?
 

mMcFab

Member
In GMS1 parallax scrolling was very easy to do. You would just update the position of each background each frame like so.
Code:
background_x[0] = view_xview[0];
background_y[0] = view_yview[0];

background_x[1] = view_xview[0]/2;
background_y[1] = view_yview[0]/2;

background_x[2] = view_xview[0]/4;
background_y[2] = view_yview[0]/4;
In GMS2 I can't seem to find a way to do this. Looking over the documentation for background layers, most of the same functionality (such as changing the tiling or the alpha) has returned, but setting the x and y seems... absent. I can set the x and y offsets in the editor just like before, but I don't see a way to do this in code.

Am I missing something obvious or is that actually not here?
Currently, there is indeed no way to set background layer positions or speeds directly at runtime - I do hope methods get added.
I did devise a basic system to replace it using layer scripts and matrices though (I need to work on a proper detailed guide for it). Another option would be to draw sprites instead (annoying, I know)
 

rwkay

YoYo Games Staff
YYG Staff
But but you can do
  • layer_hspeed(layer_id,speed) - set the given layers horizontal speed value
  • layer_vspeed(layer_id,speed) - set the given layers vertical speed value
  • layer_get_hspeed(layer_id) - get the given layers horizontal speed value
  • layer_get_vspeed(layer_id) - set the given layers vertical speed value
It's right there in the documentation...

Russell
 

mMcFab

Member
But but you can do
  • layer_hspeed(layer_id,speed) - set the given layers horizontal speed value
  • layer_vspeed(layer_id,speed) - set the given layers vertical speed value
  • layer_get_hspeed(layer_id) - get the given layers horizontal speed value
  • layer_get_vspeed(layer_id) - set the given layers vertical speed value
It's right there in the documentation...

Russell
Are you sure about that? I can't see it anywhere in the index search or on this page: http://docs2.yoyogames.com/source/_build/3_scripting/4_gml_reference/rooms/layers/index.html
Perhaps you have an updated version of the documentation internally?
Though the syntax highlighting does show these functions up, including layer_x and layer_y (this saves the day!)
 

GMWolf

aka fel666
But but you can do
  • layer_hspeed(layer_id,speed) - set the given layers horizontal speed value
  • layer_vspeed(layer_id,speed) - set the given layers vertical speed value
  • layer_get_hspeed(layer_id) - get the given layers horizontal speed value
  • layer_get_vspeed(layer_id) - set the given layers vertical speed value
It's right there in the documentation...

Russell
I'm too lazy to bring up the docs, but I presume there is a way to get set the x and y pos too.?

Also, what happens if you offest an instance layer? Do the x, y positions of each instance get offset? Or is it only for rendering?
What about collisions?
 
M

Mycomancer

Guest
But but you can do
  • layer_hspeed(layer_id,speed) - set the given layers horizontal speed value
  • layer_vspeed(layer_id,speed) - set the given layers vertical speed value
  • layer_get_hspeed(layer_id) - get the given layers horizontal speed value
  • layer_get_vspeed(layer_id) - set the given layers vertical speed value
It's right there in the documentation...

Russell
Speed is not at all what I was asking for...

But layer_x() does indeed work! Thank you, MaddeMichael. It is absent in the documentation but show right up in the autocomplete.
 
Top