SOLVED draw_sprite_general weird behavior

sv3nxd

Member
I draw a sprite rotated and horizontally flipped.
I do it with draw_sprite_ext and with draw_sprite_general, but I get a different outcome with each, despite having the same variables.
With draw_sprite_general, flipping the sprite seems to set the origin to center? I don't know and I can't really figure it out.
Anyways, the drawn sprite is offset by about half it's height. Really weird.

Code:
GML:
//BOTTOM BORDER
//_tile = sprite with a size of 24x24 pixels
//spr_w = 24
//spr_h = 24

for(var i = 0; i < width - spr_h; i+=spr_h) {
    draw_sprite_ext(_tile, image_index, x + i, y + height - spr_w + 1, -1, 1, 90, c_white, 1);
}
var h = width mod spr_h;
draw_sprite_general(_tile, image_index, 0, 0, spr_w, spr_h - h, x + i, y + height - spr_w + 1, -1, 1, 90, c_white, c_white, c_white, c_white, 1);

Outcome:
1585523359343.png


[SOLVED]

For anyone running into this problem:
Apparently draw_sprite_general uses the bounding-box to scale/flip the image, not the whole image.

If your image has it's bounding-box not set to "full" and got some free-space, then it's gonna deform like it did in my case.

Use sprite_duplicate(_sprite) and sprite_collision_mask(_sprite, false, 1, 0, 0, 0, 0, 1, 0) to ensure that the bbox is set to full.
Also remember to delete the duplicate again with sprite_delete(_sprite)
 
Last edited:
The docs for draw_sprite_general don't state this explicitly, but if I recall correctly, and from interpreting the docs just now, it seems draw_sprite_general() doesn't take in to account the sprites origin setting. So where you specify the x an y draw position in draw_sprite_general, this will the where the top left corner of the sprite will be drawn.

Because you've flipped the scale, the sprite is upside down, so I believe what you need to do is add the sprite_width (spr_w in your code) to the y coordinate, rather than subtract it.
 

sv3nxd

Member
The docs for draw_sprite_general don't state this explicitly, but if I recall correctly, and from interpreting the docs just now, it seems draw_sprite_general() doesn't take in to account the sprites origin setting. So where you specify the x an y draw position in draw_sprite_general, this will the where the top left corner of the sprite will be drawn.

Because you've flipped the scale, the sprite is upside down, so I believe what you need to do is add the sprite_width (spr_w in your code) to the y coordinate, rather than subtract it.
Thanks for the answer.
Specifying x and y doesn't seem to affect the origin, if I tested correctly. The only thing that really seems to change the whole thing is flipping the x-scale or the y-scale.
For now I just rotate it rather than flipping it, but this way the tiled-effect doesn't work.

I'm really confused about all of this.

Flipped x_scale:

1585567990338.png

Not flipped:

1585568035763.png

GML:
//BOTTOM


for(var i = 0; i < width - spr_h; i+=spr_h) {
    draw_sprite_ext(_tile, image_index, x + i, y + height - spr_w + 1, -1, 1, 90, c_white, 1);
}
var h = width mod spr_h;
draw_sprite_general(spr_pokemon_border_test, image_index, 0, 0, spr_w, spr_h - h, x + i + spr_h - h, y + height - spr_w - h + 1, 1, 1, 270, c_white, c_white, c_white, c_white, 1);
 

sv3nxd

Member
WAIT
I am even more confused.

The images I sent above ... those are correct for some reason.
The difference is that I duplicated the border-tile in the ressource tree and added a red border, so you guys could better see it.

So using the duplicate gives me the desired result ... but using the same tile ... doesn't work? What the actual is going on here.
They both have the very same dimensions and origin.


WHAT SHOULD HAPPEN (works with duplicate)
1585569940217.png

WHAT HAPPENS (with the original)

1585569976755.png


GML:
var _tile = border_tile;
var spr_w = sprite_get_width(border_tile);
var spr_h = sprite_get_height(border_tile);
draw_sprite(_tile, 0, 50, 50);

//RIGHT
for(var i = 0; i < height - spr_h; i+=spr_h) {
    draw_sprite(_tile, image_index, x + width - spr_w, y + i);
}
var h = height mod spr_h;
draw_sprite_part(_tile, image_index, 0, 0, spr_w, h + 1, x + width - spr_w, y + height - h);


//LEFT

for(var i = 0; i < height - spr_h; i+=spr_h) {
    draw_sprite_ext(_tile, image_index, x + spr_w, y + i, -1, 1, 0, c_white, 1);
}
var h = height mod spr_h;
draw_sprite_part_ext(_tile, image_index, 0, 0, spr_w, h + 1, x + spr_w, y + height - h, -1, 1, c_white, 1);

//TOP

for(var i = 0; i < width - spr_h; i+=spr_h) {
    draw_sprite_ext(_tile, image_index, x + i, y + spr_w, 1, 1, 90, c_white, 1);
}
var h = width mod spr_h;
draw_sprite_general(_tile, image_index, 0, 0, spr_w, spr_h - h, x + i, y + spr_w, 1, 1, 90, c_white, c_white, c_white, c_white, 1);

//BOTTOM

for(var i = 0; i < width - spr_h; i+=spr_h) {
    draw_sprite_ext(_tile, image_index, x + i, y + height - spr_w + 1, -1, 1, 90, c_white, 1);
}
var h = width mod spr_h;

//DOESNT WORK
draw_sprite_general(_tile, image_index, 0, 0, spr_w, spr_h - h, x + i + spr_h - h, y + height - spr_w - h + 1, 1,-1, 270, c_white, c_white, c_white, c_white, 1);
//DOESNT WORK
draw_sprite_general(border_tile, image_index, 0, 0, spr_w, spr_h - h, x + i + spr_h - h, y + height - spr_w - h + 1, 1,-1, 270, c_white, c_white, c_white, c_white, 1);
//DOESNT WORK
draw_sprite_general(spr_border, image_index, 0, 0, spr_w, spr_h - h, x + i + spr_h - h, y + height - spr_w - h + 1, 1,-1, 270, c_white, c_white, c_white, c_white, 1);
//WORKS
draw_sprite_general(spr_border_duplicate, image_index, 0, 0, spr_w, spr_h - h, x + i + spr_h - h, y + height - spr_w - h + 1, 1,-1, 270, c_white, c_white, c_white, c_white, 1);
 
Last edited:

sv3nxd

Member
draw_sprite_general has a bug which is never solved since GM Studio v1.4. if you draw a sprite in negative scales like -image_xscale or -image_yscale and then if their x and y position is like half outside the view they disappear. Let me be more specific with exact example-

draw a sprite with -image_xscale and shift it's x to the right so that half of the sprite fall outside the view. It will disappear suddenly.
draw a sprite with -image_yscale and shift it's y to the bottom so that half of the sprite fall outside the view. It will disappear suddenly.
 
Top