GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#1 2018-08-11 16:26:58

someone
Member
Registered: 2018-08-11
Posts: 1

9slice scaling for sprites

// 9slice_scaling(sprite ,x1 ,y1 ,x2 ,y2)
// this script creates a rectangle by using the 9 slice scaling method on a sprite
/// @arg0 sprite
/// @arg1 x1
/// @arg2 y1
/// @arg3 x2
/// @arg4 y2

var size = sprite_get_width(argument0) / 3;
var x1 = argument1;
var y1 = argument2;
var x2 = argument3;
var y2 = argument4;
var w = x2 - x1;
var h = y2 - y1;
var columns = w div size;
var rows = h div size;

//corners
//top left
draw_sprite_part(argument0, 0, 0, 0, size, size, x1, y1);
//top right
draw_sprite_part(argument0, 0, size*2, 0, size, size, x1+ w-size, y1);
//bottom left
draw_sprite_part(argument0, 0, 0, size*2, size, size, x1, y1+h-size);
//bottom right
draw_sprite_part(argument0, 0, size*2, size*2, size, size, x1+w-size, y1+h-size);

//edges
//left edge
draw_sprite_part_ext(argument0, 0, 0, size, size, 1, x1, y1+size, 1, h-(size*2), c_white, 1);
//right edge
draw_sprite_part_ext(argument0, 0, size*2, size, size, 1, x1+w-size, y1+size, 1, h-(size*2), c_white, 1);
//top edge
draw_sprite_part_ext(argument0, 0, size, 0, 1, size,  x1+size, y1, w-(size*2), 1, c_white, 1);
//bottom edge
draw_sprite_part_ext(argument0, 0, size, size*2, 1,size, x1+size, y1+h-size, w-(size*2), 1, c_white, 1);

//middle
draw_sprite_part_ext(argument0, 0, size, size, 1, 1, x1+size, y1+size, w-(size*2), h-(size*2), c_white, 1);

Offline

#2 2018-08-12 16:20:28

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

Re: 9slice scaling for sprites

Hi someone, thanks for the submission and welcome to the forums.

There is a script similar to this in the library, though anyone could be forgiven for not being able to find it. I named it before I knew of the term "9-slice scaling".

https://www.gmlscripts.com/script/draw_sprite_rectangle

I'll probably rename it in the future.


Abusing forum power since 1986.

Offline

Board footer

Powered by FluxBB