Help with my background system

N

Neiel

Guest
I'm trying to make a parallax scrolling background and I'm having some trouble with it. It draws above every tile even though the BG object's depth is set to 1000000 and tiles' depth is 10000. The objects are still visible too.
This is the code:
Code:
///Create Event
Image      = 0;
xSpeed    = 1;
ySpeed    = 2;
xviewPos = 3;
yviewPos = 4;
xTiled       = 5;
yTiled       = 6;
xAbsPos  = 7;
yAbsPos  = 8;
Depth       = 9;

bg_background = 10000000;
bg_foreground  = -10000000;

bg = ds_grid_create(10, 10);

//bg[# Layer, Property]
bg[# 0, Image] = -1;
bg[# 0, xSpeed] = 0;
bg[# 0, ySpeed] = 0;
bg[# 0, xAbsPos] = -1;
bg[# 0, yAbsPos] = -1;
bg[# 0, xviewPos] = -1;
bg[# 0, yviewPos] = -1;
bg[# 0, xTiled] = false;
bg[# 0, yTiled] = false;
bg[# 0, Depth]  = bg_background;
Code:
///Draw Event
if(bg[# 0, Image] == -1) exit;

var bg_num = ds_grid_width(bg);

for(i = 0; i < bg_num; i++)
    {
    var xPos = (bg[# i, xAbsPos]+(view_xview+bg[# i, xviewPos])*(bg[# i, xviewPos] != -1))*bg[# i, xSpeed],
        yPos = (bg[# i, yAbsPos]+(view_yview+bg[# i, yviewPos])*(bg[# i, yviewPos] != -1))*bg[# i, ySpeed];
   
    depth = bg[# i, Depth];
       
    if(bg[# i, xTiled] == false) && (bg[# i, yTiled] == false)
        draw_background(bg[# i, Image], xPos, yPos);
       
    if(bg[# i, xTiled] == true) && (bg[# i, yTiled] == false)
        scrDrawBackgroundTiledHorizontal(bg[# i, Image], xPos, yPos);
       
    if(bg[# i, xTiled] == false) && (bg[# i, yTiled] == true)
        scrDrawBackgroundTiledVertical(bg[# i, Image], xPos, yPos);
       
    if(bg[# i, xTiled] == true) && (bg[# i, yTiled] == true)
        draw_background_tiled(bg[# i, Image], xPos, yPos);
    }
Code:
///Instance Creation
//bg[# Layer, Property]
bg[# 0, Image] = bgCave1;
bg[# 0, xSpeed] = -0.1;
bg[# 0, ySpeed] = -0.1;
bg[# 0, xAbsPos] = 0;
bg[# 0, yAbsPos] = 0;
bg[# 0, xviewPos] = 0;
bg[# 0, yviewPos] = 0;
bg[# 0, xTiled] = true;
bg[# 0, yTiled] = true;
bg[# 0, Depth]  = bg_background;
BTW, scrDrawBackgroundTiledHorizontal and scrDrawBackgroundTiledVertical are some scripts for doing what they mark, and they were based off a Sonic engine which used something similar. They do work as I could see in that engine, and they do not affect on the type of background I tested this with.
 
Last edited by a moderator:

TheouAegis

Member
you cannot change depth in the draw events. Once the draw event runs, the depth is set. You can only change depth in the step events.
 
Top