[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;
@ -56,17 +53,17 @@ 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);
if (texture == null) if (texture == null)
throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + name + ")"); throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + name + ")");
var attachment : RegionAttachment = new RegionAttachment(name); var attachment : RegionAttachment = new RegionAttachment(name);
var rotated : Boolean = atlas.getRotation(path); var rotated : Boolean = atlas.getRotation(path);
attachment.rendererObject = new Image(Texture.fromTexture(texture)); // Discard frame. attachment.rendererObject = new Image(Texture.fromTexture(texture)); // Discard frame.
var frame : Rectangle = texture.frame; var frame : Rectangle = texture.frame;
attachment.regionOffsetX = frame ? -frame.x : 0; attachment.regionOffsetX = frame ? -frame.x : 0;
@ -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;
} }
@ -181,7 +161,7 @@ package spine.starling {
public function newPointAttachment(skin : Skin, name : String) : PointAttachment { public function newPointAttachment(skin : Skin, name : String) : PointAttachment {
return new PointAttachment(name); return new PointAttachment(name);
} }
public function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment { public function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment {
return new ClippingAttachment(name); return new ClippingAttachment(name);
} }