Wednesday, March 20, 2013

Sprite Bending

So interesting issue I'm having at the moment. I'm learning this game engine Moai and trying to figure out a good way to bend sprites. I know I'm making this more difficult than it needs to be. But I'm really determined to figure this out.
So here's my issue. I'm trying to bend a sprite along a curve. I've got a single sprite for the body of snake and I'd rather not make multiple sprites for every snake bend and angle. My first idea was to break it into multiple, skewed polygons and mess with the uv texure mapping. Eg here's my texture:

Image

And to get a 90 degree turn I'm mapping it onto a number of polygons like this:

Image
Image

(note p0 is actually four different points with the same coordinates)

The thing is, the texture mapping doesn't work exactly like I want.

Image

The issue is easier to see with just two segments:

Image

I believe the reason for this is that each of the two polygons that make up each quad are mapped separately.  I looked into shear transforms instead of weird uv mapping, but that doesn't seem to be exactly what I'm looking for either.  Quite frustrating.  I may end up needing to go so far as to modify the moai game engine myself to get this working like I want it to.

Update 12/1/13: I gave up.  I ended up going with the multi-sprite solution.  It was a rabbit hole that would not have been worth the trouble.  Turns out to do what I wanted, I really needed a 3D transform which Moai does not support yet.  Something called a non-affine transform.  I had started digging into the engine, but after wasting some time, I had to remind myself I set out to make a game here, not a game engine.

No comments:

Post a Comment