Skip to content

Commit

Permalink
[as3][starling] Fixed StarlingAtlasAttachmentLoader. Thanks @vync79. C…
Browse files Browse the repository at this point in the history
…loses #939
  • Loading branch information
badlogic committed Jul 17, 2017
1 parent c113098 commit f2bd63c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 42 deletions.
Binary file modified spine-starling/spine-starling-example/lib/spine-starling.swc
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit f2bd63c

Please sign in to comment.