• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GML Getting pixel-perfect part of a sprite's UV coordinates

IndirectY

Member
I'm trying to write a script that only draws a part of a sprite, using vertex only.

For example, there is a sprite with a size of 128x32 and I will run the script to draw only a half (0,0 to 64,32), or a quarter (0,0 to 32,32), but drawn as the same size of 128x32.

So I got the left value and the right value using sprite_get_uvs(), multiplied them by 0.5 (or 0.25), and passed the values to vertex_normal(). And the results does not look right.

test.png

If the script was done right, both cyan and blue should be visible. But as you see in the 50% one (64x32), only cyan is visible. for 25% (32x32), pink is taking 2 strokes and blue is not visible.

I tried ( uv[0] + uv[2] ) * x too, but it does not look right when x=1 or x=0.25.

So, what should I do to get the correct UV values for this?
 
Top