• 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!

Legacy GM [SOLVED] Parallax scrolling problem - unsolvable?

Greetings all!

Currently (successfully) scrolling two tile-repeated starfield backgrounds (#0 far, #1 closer) only as and when the view moves (is panned by the player). However, a 3rd 'entity' -- a planet -- and this is not a background but a sprite, is located at fixed coordinates within the room.

I am stumped as to how I could achieve the effect of this planet scrolling with the view, at a "slower rate" than the screen scrolls---when the screen is being scrolling/panned by the player.

// Background #0 - furthest away
Code:
background_x[0] = view_xview[0] * 0.92;
background_y[0] = view_yview[0] * 0.92;
// Background #1 - closer
Code:
background_x[1] = view_xview[0] * 0.91;
background_y[1] = view_yview[0] * 0.91;
// Entity #3 -- Planet handling - stumped!
Code:
draw_sprite_ext(spr_planet, 0, 16000 , 9000, 1, 1, 0, c_white, 1);
 
Last edited:
I

InkSho

Guest
make the planet an object and just make it so that as you move, its x value changes to the speed that you like. so its more of an illusion than actual parallaxing
 
Inksho, I had considered moving the x/y coordinates like you mention--it may even be the only way.
However, unless I first check whether the object is within the view before moving the x/y, the object could end up a long way from it's original starting position in the room. (I would also need to return the object to it's original starting position once it is outside of the view).
This is all a somewhat messy solution. Perhaps there might be another way?
 

wamingo

Member
not played much with parallax, so take with grain of salt...
Code:
var vx=view_xview*0.7;   // multiplier should probably be lower than your star background
var vy=view_yview*0.7;
draw_sprite(spr_planet,0,x+vx,y+vy);
you may have to reduce the starting pos to account for this effect.
if the planet is an object you placed in the room editor, eg at x=16000,y=9000, you might give its create event:
Code:
x-=x*0.7;
y-=y*0.7;
edit: fixed bits
 
Last edited:
A

Argonaut14

Guest
You could make the planet a tile, and use the commands for shifting tiles to control the planet. You might need to do some messing around with the depth of the various backgrounds to enable you to have the planet as a single tile above the other two backgrounds.

Code:
if view_xview>0 && view_xview < (room_width-view_wview) &&view_hspeed !=0
{
  tile_layer_shift(1000001,0-view_hspeed,0);//change the tile layer you want to alter here,
}
something like this might work.

[edit] you'd need to put in a test to see if the player was moving left or right. The above code would work if the player was moving left. The planet (the tile layer) would move right as long as the view isn't at the edges of the room.
 
Last edited by a moderator:
Code:
///draw_planet(realx,realy,rate,radius)

var drawX = (view_xview[0]+(view_wview[0]/2)-argument0)*argument2+argument0;
var drawY = (view_yview[0]+(view_hview[0]/2)-argument1)*argument2+argument1;
if(rectangle_in_rectangle(drawX-argument3,drawY-argument3,drawX+argument3,drawY+argument3,
    view_xview[0],view_yview[0],view_xview[0]+view_wview[0],view_yview[0]+view_hview[0])>0){
   
    draw_sprite_ext(spr_planet, 0, drawX, drawY, 1, 1, 0, c_white, 1);
}
Code:
draw_planet(16000,9000,0.8,256);
When the middle of the view lines up with your planet's point at (16000,9000), the planet will be exactly at that point. Also added some checks to see if it is in view.
 
:eek: Well now, isn't that just ****ing legendary!?
I should probably change the thread title to "solvable".
Strawbry_jam, many, many thanks! The result is simply beautiful, perfect.
I'd also like to thank Inksho, wamingo and Argonaut14--thank you for taking your time to post on this topic.
 
Top