Skip to content

Texture: Setting vertex UV coordinates doesn't take into account the potential frame of SubTextures #1089

@Adolio

Description

@Adolio

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions