Parallax using Objects, not Backgrounds?

A

Anomaly

Guest
Hi, new here.
I've been using this script from this guy's Youtube Tutorial on Parallax Backgrounds.

I have it working great.
But I want to have one of my parallax layers be an actual object(s)... NOT a background.

script:
Code:
var layer_id1 = layer_get_id("Backgrounds_1");
var layer_id2 = layer_get_id("Backgrounds_2");
var layer_id3 = layer_get_id("Backgrounds_3");

// lerp the layer coordinates to your camera view
layer_x(layer_id1, lerp(0,camera_get_view_x(view_camera[0]),.5));
layer_x(layer_id2, lerp(0,camera_get_view_x(view_camera[0]),.75));
layer_x(layer_id3, lerp(0,camera_get_view_x(view_camera[0]),.85));
is there a way to make this kind of thing work? (in between ?'s is my note obvs)
Code:
var layer_id4 = ???get this object's instance name??  ("Backgrounds_OBJECT_4");
THANKS!!
 
D

Deleted member 13992

Guest
There are always ways, but not always simple. I do it by drawing my background objects to view surface, then in my main draw event, scale the surface smaller around the center of the view.

I also thought of adding position offset code to the background objects individually that would just keep track of where they were in the view relative to the center. Though I haven't actually tried this.

I don't like the layer_x idea since you can't offset objects individually, so you can't get a sense of perspective. Personal preference though, I'm sure others could make it work.
 
A

Anomaly

Guest
yeah the type im using doesnt let me get vertical parallax.
any basic examples of how you would parallax two objects as "background objects" (but not background layers) would be great!
 

obscene

Member
Here's part of my code for it... this goes in the camera object. It uses each object's depth to calculate it's parallax amount each step.

Code:
xmoved=x-xprevious;
ymoved=y-yprevious;
xview_previous=view_xview
yview_previous=view_yview

if xmoved!=0 || ymoved!=0
    {
   
    var d=depthfactor;  // In my game this is .003 for most rooms
    var xm=xmoved;
    var ym=ymoved;
       
    with all
         {        
                 // Multiply objects's depth by depthfactor 
                 var depthoffset=(depth*d);    
                 
                 // Recalculate positions    
                 x=x+xm*depthoffset        
                 y=y+ym*depthoffset

          }
 

RangerX

Member
For someone using such a system, do you guys know if using "draw_sprite" series or "draw_background" series of functions would make any difference?
 
A

Anomaly

Guest
Here's part of my code for it... this goes in the camera object. It uses each object's depth to calculate it's parallax amount each step.

Code:
xmoved=x-xprevious;
ymoved=y-yprevious;
xview_previous=view_xview
yview_previous=view_yview

if xmoved!=0 || ymoved!=0
    {
  
    var d=depthfactor;  // In my game this is .003 for most rooms
    var xm=xmoved;
    var ym=ymoved;
      
    with all
         {       
                 // Multiply objects's depth by depthfactor
                 var depthoffset=(depth*d);   
                
                 // Recalculate positions   
                 x=x+xm*depthoffset       
                 y=y+ym*depthoffset

          }
I'd like to try your code.
I made an object and put the camera info in the step of it. then put the object on the top layer.
i have to use the create camera command though hmm..?

I've just been using the built in cameras and viewports in the room.
very very new to all this srry.
 

obscene

Member
Oooh... sorry I'm using GM 1.4. My camera is a custom camera object, I'm not 100% sure how you would adapt that to 2.0.

I should explain more too. This code treats a depth of 0 as "middle" meaning no parallax is done to depth 0. I also in my original code don't parallax anything with an absolute depth of 20 or less, so nothing in those depths is affected.
 
Top