[as3][starling] Fixed StarlingAtlasAttachmentLoader. Thanks @vync79. Closes #939

This commit is contained in:
badlogic 2017-07-17 14:18:26 +02:00
parent c11309893f
commit f2bd63ce6c
3 changed files with 22 additions and 42 deletions

View File

@ -66,7 +66,7 @@ package spine.examples {
private var skinChangeCount: Number = 0; private var skinChangeCount: Number = 0;
public function GoblinsExample() { public function GoblinsExample() {
var useStarlingAtlas : Boolean = false; var useStarlingAtlas : Boolean = true;
var attachmentLoader : AttachmentLoader; var attachmentLoader : AttachmentLoader;
if (useStarlingAtlas) { if (useStarlingAtlas) {

View File

@ -27,21 +27,18 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE. * POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/ *****************************************************************************/
package spine.starling { package spine.starling {
import spine.attachments.ClippingAttachment;
import spine.attachments.PointAttachment;
import spine.attachments.PathAttachment;
import starling.display.Image;
import spine.Bone; import spine.Bone;
import spine.Skin; import spine.Skin;
import spine.attachments.AttachmentLoader; import spine.attachments.AttachmentLoader;
import spine.attachments.BoundingBoxAttachment; import spine.attachments.BoundingBoxAttachment;
import spine.attachments.ClippingAttachment;
import spine.attachments.MeshAttachment; import spine.attachments.MeshAttachment;
import spine.attachments.PathAttachment;
import spine.attachments.PointAttachment;
import spine.attachments.RegionAttachment; import spine.attachments.RegionAttachment;
import starling.display.Image;
import starling.textures.SubTexture; import starling.textures.SubTexture;
import starling.textures.Texture; import starling.textures.Texture;
import starling.textures.TextureAtlas; import starling.textures.TextureAtlas;
@ -57,9 +54,9 @@ package spine.starling {
Bone.yDown = true; Bone.yDown = true;
} }
protected function getTexture(path:String):Texture { protected function getTexture(path : String) : Texture {
return atlas.getTexture(path); return atlas.getTexture(path);
} }
public function newRegionAttachment(skin : Skin, name : String, path : String) : RegionAttachment { public function newRegionAttachment(skin : Skin, name : String, path : String) : RegionAttachment {
var texture : Texture = atlas.getTexture(path); var texture : Texture = atlas.getTexture(path);
@ -83,35 +80,18 @@ package spine.starling {
attachment.regionWidth = attachment.regionHeight; attachment.regionWidth = attachment.regionHeight;
attachment.regionHeight = tmp; attachment.regionHeight = tmp;
} }
var subTexture : SubTexture = texture as SubTexture; if (!rotated) {
if (subTexture) { attachment["regionU"] = 0;
var root : Texture = subTexture.root; attachment["regionV"] = 0;
var rectRegion : Rectangle = atlas.getRegion(path); attachment["regionU2"] = 1;
if (!rotated) { attachment["regionV2"] = 1;
attachment["regionU"] = rectRegion.x / root.width;
attachment["regionV"] = rectRegion.y / root.height;
attachment["regionU2"] = (rectRegion.x + subTexture.width) / root.width;
attachment["regionV2"] = (rectRegion.y + subTexture.height) / root.height;
} else {
attachment["regionU2"] = rectRegion.x / root.width;
attachment["regionV2"] = rectRegion.y / root.height;
attachment["regionU"] = (rectRegion.x + subTexture.width) / root.width;
attachment["regionV"] = (rectRegion.y + subTexture.height) / root.height;
}
attachment.setUVs(attachment["regionU"], attachment["regionV"], attachment["regionU2"], attachment["regionV2"], atlas.getRotation(path));
} else { } else {
if (!rotated) { attachment["regionU2"] = 0;
attachment["regionU"] = 0; attachment["regionV2"] = 1;
attachment["regionV"] = 1; attachment["regionU"] = 1;
attachment["regionU2"] = 1; attachment["regionV"] = 0;
attachment["regionV2"] = 0;
} else {
attachment["regionU2"] = 0;
attachment["regionV2"] = 1;
attachment["regionU"] = 1;
attachment["regionV"] = 0;
}
} }
attachment.setUVs(attachment["regionU"], attachment["regionV"], attachment["regionU2"], attachment["regionV2"], atlas.getRotation(path));
return attachment; return attachment;
} }