Game Maker Games, Articles, Tutorials & More

Game Maker Network


Howdy, Guest! Please sign in or register an account.

Print

tile_background_outside_room

By Daniel · December 24, 2008

GM contains something of an inconsistency, arguably a bug. In general, it does not limit you to the dimensions you choose to give to your room - it will handle instances that go outside of the boundaries, and it will allow you to draw outside of the room. But, while it does tile background images outside of the room in the positive direction, it does not do so in the negative direction. If you need to give your user the option of moving the view arbitrarily far in the negative direction, this becomes problematic, as any tiling backgrounds will be cut off in all areas where x<0 and y<0. This script is a simple remedy for this - it draws only what is necessary, without breaking seamless patterns and without leaving black nothingness around the edges of the view.

//This script will tile the background outside of the room in the negative direction, if appropriate
//No arguments used
//This script assumes that you are using view0 and background0. If not, simply add the indexes where appropriate.


var quad_1, quad_2, quad_3, current_x, current_y;


// First, determine which quadrants need background tiles drawn in them
quad_1 = (view_yview < 0);
quad_3 = (view_xview < 0);
quad_2 = (quad_1 && quad_3);


//Now draw the background where needed

if quad_1 {
for (current_x = max(floor(view_xview/background_width)*background_width,0); current_x < view_xview + view_wview; current_x += background_width) {
 for (current_y = ceil((view_yview+view_hview)/background_height)*background_height; current_y > view_yview; current_y -= background_height) {
  draw_background(background_index,current_x,current_y-background_height);
 }
}
}

if quad_2 {
for (current_x = min(ceil((view_xview+view_wview)/background_width)*background_width,0); current_x > view_xview; current_x -= background_width) {
 for (current_y = min(ceil((view_yview+view_hview)/background_height)*background_height,0); current_y > view_yview; current_y -= background_height) {
  draw_background(background_index,current_x-background_width,current_y-background_height);
 }
}
}

if quad_3 {
for (current_x = ceil((view_xview+view_wview)/background_width)*background_width; current_x > view_xview; current_x -= background_width) {
 for (current_y = max(floor(view_yview/background_height)*background_height,0); current_y < view_yview + view_hview; current_y += background_height) {
  draw_background(background_index,current_x-background_width,current_y);
 }
}
}

Categories: 2D graphics

Comments

There are no comments to display.

Post a Comment

You must be signed in to post comments.

Advertisement