-
Notifications
You must be signed in to change notification settings - Fork 823
Description
Hey Daniel,
I recently discovered that the UV mapping of textures part of an atlas (with frame mode active) doesn't fully natively work. I noticed that while trying to implement a missing feature in DragonBonesAS
: DragonBones/DragonBonesAS#94 - this might have been the issue the team faced when trying to implement it back then.
Please tell me if you think it's worth integrating in vanilla Starling - I can try to do a pull request then.
Workaround
Here is an utility method that supports SubTexture
with the framing capability:
/**
* Sets the texture coordinates of the vertex at the specified index to the given values.
*
* <p>Note: This method also supports `SubTexture` with framing.</p>
*/
public static function setTexCoords(image:Image, vertexID:int, u:Number, v:Number):void
{
// adjust uv when the texture is a `SubTexture` and contains a frame
if (image.texture is SubTexture)
{
var subTex:SubTexture = image.texture as SubTexture;
if (subTex.frame != null)
{
u = (u * subTex.frame.width + subTex.frame.x) / subTex.region.width;
v = (v * subTex.frame.height + subTex.frame.y) / subTex.region.height;
}
}
// update vertex uv
image.setTexCoords(vertexID, u, v);
}
Note: the problem with this method is the fact that if you get the coordinates afterwards you won't get the value you have set at the first place. This might be confusing... Another option would be to fix this even deeper in the rendering logic or implement the reversed logic in the getter.