GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2014-05-27 01:37:48

CatezeeY
Member
Registered: 2013-11-02
Posts: 6

Troubles with draw_background_tiled_area_ext()

Hello, I used the draw_background_tiled_area_ext script from this site on a engine I'm working on.

Expand/*
**  Usage:
**      draw_background_tiled_area_ext(background,x,y,x1,y2,x2,y2,color,alpha,index)
**
**  Arguments:
**      background  the background to be drawn
**      x,y         the offset of the tiled area, as defined by a point
**                  the background will/would be drawn
**      x1,y1       top left corner of the rectangle defining the area
**      x2,y2       bottom right corner of the area
**      color       the color mask that you want to blend the background with
**      alpha       the alpha value to draw it at
**
**  Notes:
**      x1 MUST be less than x2, and y1 less than y2
**      (x,y) doesn't have to be in the area, but if it is, then some
**      drawn background will have it's origin at this point
**
**  GMLscripts.com
*/
{
    var bg,xx,yy,x1,y1,x2,y2;
    bg = argument0;
    xx = argument1;
    yy = argument2;
    x1 = argument3;
    y1 = argument4;
    x2 = argument5;
    y2 = argument6;
    index = argument9;

    var bw,bh,i,j,jj,left,top,width,height,X,Y;
    bw = background_get_width(bg);
    bh = background_get_height(bg);

    i = x1-((x1 mod bw) - (xx mod bw)) - bw*((x1 mod bw)<(xx mod bw));
    j = y1-((y1 mod bh) - (yy mod bh)) - bh*((y1 mod bh)<(yy mod bh));
    jj = j;

    for(i=i; i<=x2; i+=bw) {
        for(j=j; j<=y2; j+=bh) {

            if(i <= x1) left = x1-i;
            else left = 0;
            X = i+left;

            if(j <= y1) top = y1-j;
            else top = 0;
            Y = j+top;

            if(x2 <= i+bw) width = ((bw)-(i+bw-x2)+1)-left;
            else width = bw-left;
            if (background_vtiled[index] == true) {
                if(y2 <= j+bh) height = ((bh)-(j+bh-y2)+1)-top;
                else height = bh-top;
            }
            else height = 0;
            draw_background_part_ext(bg,left,top,width,height,X,Y,1,1,argument7,argument8);
        }
        j = jj;
    }
}

NOTE: This is a modified version of the script. the original one can be found Here

I want to make the background move along with the view but everytime I test it. The backgrounds stay on the start position.

I'll provide the code of the object that draws the backgrounds.

Create Event:

Expandfor (i=0; i<7; i+=1) {
    bgindex[i] = background_index[i];
    bgyy[i] = background_y[i];
    //Sets the background hspeed...
        bghsp[i] = background_hspeed[i];
}
bgfx[0] = 1
bgfx[1] = 1.2
bgfx[2] = 1.4
bgfx[3] = 1.6
bgfx[4] = 1.8
bgfx[5] = 2.0
bgfx[6] = 2.2
bgfx[7] = 2.4
if (instance_number(obj_parallax) > 1)
    instance_destroy();

Draw Event:

Expandfor (i=0; i<8; i+=1) {
    if (background_index[i] == -1)
    exit;
        draw_background_tiled_area_ext(bgindex[i],view_xview[0]/bgfx[i]+bghsp[i],bgyy[i],0,0,room_width,room_height,background_blend[i],background_alpha[i],i);
}

I'm doing anything wrong?

Last edited by CatezeeY (2014-05-27 01:38:28)

Offline

#2 2014-05-27 01:56:26

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Troubles with draw_background_tiled_area_ext()

Hmmm. Kind of confusing.

It looks like you have set-up automatic background drawing for your room making this code sort of redundant. If you have background_vtiled[] set to false on these backgrounds, I think that's going to invoke a bug: height will be set to 0 and I don't think anything will be drawn. Your intentions aren't clear there. Perhaps nothing is being drawn and you are only seeing the automatic background drawing.


Abusing forum power since 1986.

Offline

#3 2014-05-27 02:07:04

CatezeeY
Member
Registered: 2013-11-02
Posts: 6

Re: Troubles with draw_background_tiled_area_ext()

xot wrote:

Hmmm. Kind of confusing.

It looks like you have set-up automatic background drawing for your room making this code sort of redundant. If you have background_vtiled[] set to false on these backgrounds, I think that's going to invoke a bug: height will be set to 0 and I don't think anything will be drawn. Your intentions aren't clear there. Perhaps nothing is being drawn and you are only seeing the automatic background drawing.

Some of the backgrounds I use have alpha transparency on certain areas.

I just want to make all the active backgrounds move along with the view.

Expandbackground_x[i] = view_xview[i]/bgfx[i]

Last edited by CatezeeY (2014-05-27 02:08:31)

Offline

#4 2014-05-27 02:19:01

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Troubles with draw_background_tiled_area_ext()

You've succeeded in making things even more confusing. laugh

Doesn't really explain why you would ever what height to be zero (thus drawing nothing) or if you have background_vtiled[] set to false anywhere.

It's not even clear why you need this code at all if you are simply drawing a background over the entire view. Actually, more than the entire view since you are using 0,0 to room_width,room_height instead of view_xview[],view_yview[] to view_wview[],view_hview[]. That could be extremely inefficient depending on the size of the room.

One other odd thing that probably isn't an issue but is worth pointing out is your use of exit. If you just want to terminate the loop, use break. Using exit in a code action will immediately end the entire event skipping all following code, code actions, and scripts in the event. Using exit in a script will immediately terminate the script but will continue the event.

Also, in the create event, you are only initializing the first seven backgrounds, not all eight. In the draw event you loop through all eight. A separate issue to the main problem, but a potential problem in any case.

Last edited by xot (2014-05-27 02:24:56)


Abusing forum power since 1986.

Offline

#5 2014-05-27 02:37:24

CatezeeY
Member
Registered: 2013-11-02
Posts: 6

Re: Troubles with draw_background_tiled_area_ext()

Like I said, I added background_vtiled on the script for those backgrounds that doesn't have alpha transparency, Like the one at the image below.

09b806cb26.png

And the 8 on the draw event is a typo, it's supposed to be 7. My fault whistle

Last edited by CatezeeY (2014-05-27 02:39:46)

Offline

#6 2014-05-27 02:59:12

xot
Administrator
Registered: 2007-08-18
Posts: 1,239

Re: Troubles with draw_background_tiled_area_ext()

Is "8" the typo? Your intention seems to be to use the 8th background with "bgfx[7] = 2.4".

Anyway, I think maybe you have your arguments mixed up.

Expanddraw_background_tiled_area_ext(bgindex[i], view_xview[0]/bgfx[i]+bghsp[i], bgyy[i], view_xview[0], view_yview[0], view_wview[0], view_hview[0], background_blend[i], background_alpha[i], i);

I don't know what else to suggest. You're not giving me much to work with and you're not being very responsive or clear.


Abusing forum power since 1986.

Offline

#7 2014-05-27 15:28:48

CatezeeY
Member
Registered: 2013-11-02
Posts: 6

Re: Troubles with draw_background_tiled_area_ext()

I finally managed to fix the bug. but I had to use another script. I'll add it to let everyone use it.

Last edited by CatezeeY (2014-05-27 15:33:28)

Offline

Board footer

Powered by FluxBB