Is Background Padding possible? [Solved with 2 solutions to 1 problem]

Hey all I'm sorting out some parallax backgrounds.

I wish to place individual images in my background and select repeat horizontally but need some padding.
I am trying to avoid setting the texture page size higher so is it possible to repeat an image but space them out without altering the image?

I am using the inbuilt background settings atm



Edit: Solved by simply increasing sprite canvas size
 
Last edited:

Pixel-Team

Master of Pixel-Fu
It's possible to draw your background image sprite to a surface that has the padding you want, then create a background from that surface.
 
It's possible to draw your background image sprite to a surface that has the padding you want, then create a background from that surface.
That's exactly what I'm looking for, thankyou. can you go a little more in depth or tell me the terms or keywords I could use to research that.
 

Pixel-Team

Master of Pixel-Fu
Something like the following can help.

Assign the background sprite to the background layer and check Horizontal and Vertical tiling.
Make a new object, and assign the background sprite to it, and drop it in your level. This will add the padding to the tiled background

On the create event, put this:

GML:
//define your padding
pad_x = 5;
pad_y = 5;

//create a temporary surface
var surf = surface_create(sprite_width + (pad_x * 2), sprite_height + (pad_y * 2));
surface_set_target(surf);

//draw the background sprite to the surface
draw_sprite(sprite_index, -1, pad_x, pad_y);

//finished using surface
surface_reset_target();

//create new sprite from surface
var sprite = sprite_create_from_surface(surf, 0, 0, sprite_width + (pad_x * 2), sprite_height + pad_y * 2, false, false, 0,0);

surface_free(surf);//dispose of surface memory

//retrieve background in level
var bkg = layer_background_get_id("Background");

//update background image
layer_background_change(bkg, sprite);

instance_destroy();//kill this object.
 
Something like the following can help.

Assign the background sprite to the background layer and check Horizontal and Vertical tiling.
Make a new object, and assign the background sprite to it, and drop it in your level. This will add the padding to the tiled background

On the create event, put this:

GML:
//define your padding
pad_x = 5;
pad_y = 5;

//create a temporary surface
var surf = surface_create(sprite_width + (pad_x * 2), sprite_height + (pad_y * 2));
surface_set_target(surf);

//draw the background sprite to the surface
draw_sprite(sprite_index, -1, pad_x, pad_y);

//finished using surface
surface_reset_target();

//create new sprite from surface
var sprite = sprite_create_from_surface(surf, 0, 0, sprite_width + (pad_x * 2), sprite_height + pad_y * 2, false, false, 0,0);

surface_free(surf);//dispose of surface memory

//retrieve background in level
var bkg = layer_background_get_id("Background");

//update background image
layer_background_change(bkg, sprite);

instance_destroy();//kill this object.
Thank you for this detailed response its going to help the next person to search this however I solved it a different way, I simply increased my sprite canvas width. this added padding and as it turns out the canvas doesent appear on /affect the texture page.

I increased the canvas width by 5k and it still fits like a normal sprite on the texture page regardless of the texture page size as it ignores transparent backgrounds, how awsome is that :)
 
Top