[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;
public function GoblinsExample() {
var useStarlingAtlas : Boolean = false;
var useStarlingAtlas : Boolean = true;
var attachmentLoader : AttachmentLoader;
if (useStarlingAtlas) {

View File

@ -27,21 +27,18 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
package spine.starling {
import spine.attachments.ClippingAttachment;
import spine.attachments.PointAttachment;
import spine.attachments.PathAttachment;
import starling.display.Image;
import spine.Bone;
import spine.Skin;
import spine.attachments.AttachmentLoader;
import spine.attachments.BoundingBoxAttachment;
import spine.attachments.ClippingAttachment;
import spine.attachments.MeshAttachment;
import spine.attachments.PathAttachment;
import spine.attachments.PointAttachment;
import spine.attachments.RegionAttachment;
import starling.display.Image;
import starling.textures.SubTexture;
import starling.textures.Texture;
import starling.textures.TextureAtlas;
@ -56,17 +53,17 @@ package spine.starling {
Bone.yDown = true;
}
protected function getTexture(path:String):Texture {
return atlas.getTexture(path);
}
protected function getTexture(path : String) : Texture {
return atlas.getTexture(path);
}
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)
throw new Error("Region not found in Starling atlas: " + path + " (region attachment: " + 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.
var frame : Rectangle = texture.frame;
attachment.regionOffsetX = frame ? -frame.x : 0;
@ -83,35 +80,18 @@ package spine.starling {
attachment.regionWidth = attachment.regionHeight;
attachment.regionHeight = tmp;
}
var subTexture : SubTexture = texture as SubTexture;
if (subTexture) {
var root : Texture = subTexture.root;
var rectRegion : Rectangle = atlas.getRegion(path);
if (!rotated) {
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));
if (!rotated) {
attachment["regionU"] = 0;
attachment["regionV"] = 0;
attachment["regionU2"] = 1;
attachment["regionV2"] = 1;
} else {
if (!rotated) {
attachment["regionU"] = 0;
attachment["regionV"] = 1;
attachment["regionU2"] = 1;
attachment["regionV2"] = 0;
} else {
attachment["regionU2"] = 0;
attachment["regionV2"] = 1;
attachment["regionU"] = 1;
attachment["regionV"] = 0;
}
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;
}
@ -181,7 +161,7 @@ package spine.starling {
public function newPointAttachment(skin : Skin, name : String) : PointAttachment {
return new PointAttachment(name);
}
public function newClippingAttachment(skin : Skin, name : String) : ClippingAttachment {
return new ClippingAttachment(name);
}