Another sprite masking question

It seems there have been a few new threads about sprite masking since the last time I was researching the subject, but after hitting a wall trying to copy one of them, I’m not sure whether my needs are unique enough to warrant a new topic.

I’m making a game with a core match-3 mechanic, where there will be times when multiple individual tiles will need to clip their contents to their bounds (and sometimes to the bounds of an arbitrary one of their neighbors, separately). Is there a technique to clip the sprites in the tiles that would be optimal for this situation? I think It would be preferred if I didn’t have to replace the GOs of the tiles with collections, if that is possible (that’s where I’m running into trouble with my current attempt, at the moment), but just clip the sprites in the current GO.

1 Like

Let’s say I want to specify that a given tile should only render its top half. Is there any way to pass information about a given sprite to the fragment program that would enable that (tile size / location, variables saying direction and percent, etc.)?

I figured out that Fragment Constants are only constants to the fragment program; I can actually set them with go.set(), so I came up with scheme using a constant like: { x=x percent, y=y percent, z=x direction, w=y direction }.

The only problem is, as near as I can tell, it looks like var_texcoord0 gives me UV coordinates in terms of the atlas, not the current animation. Is there any way to get this value in terms of the current animation (or just coordinates within the sprite), or do I have to figure out how I can get all the associated dimensions and crunch the numbers myself to tell where in the sprite I am?

Currently not possible but something we want to provide.

Are the values available to crunch the numbers myself, at least? I’m about to start looking for them, but if you have any chance of answering before I find them myself, that would be helpful.

Yeah, I’m not finding anything. Perhaps I can use the bounds of the sprite on the screen instead, since I’m pretty sure I know that. I think it looks like position gl_FragCoord will give me the current window coordinate, right?

The numbers are in the .atlas file. You could include it in your game and load it via sys.load_resource() and parse it. Quite hackish but it will work. Or process the .atlas file as a pre-build setp and generate a .lua file with the values.