巴拉巴拉
小魔仙

spine图集尺寸缩放

spine导出图集过大,例如4096 * 4096
要把图片压缩到2048 * 2048
所以我们要把贴图配置中的尺寸和位置都缩小一倍
打开atlas图集配置文件看了一下

Boss_HL_01_4X.png
size: 4096,4096
format: RGBA8888
filter: Linear,Linear
repeat: none
Monster/Body
    rotate: false
    xy: 2, 81
    size: 287, 414
    orig: 287, 414
    offset: 0, 0
    index: -1
Monster/Head
    rotate: false
    xy: 291, 163
    size: 307, 332
    orig: 307, 332
    offset: 0, 0
    index: -1

贴图配置atlas文件大致结构如上
分析了一下,大约需要吧size,xy,orig的两个数字都缩放一倍就好了

于是↓↓↓↓↓写了这个改图集配置的文件

改完之后的Atlas和图片导入到了cocos creator2.0.5中运行正常

package com.againfly.demo;

import java.io.*;

/**
 * Created by Jecced on 2018/11/17.
 * 缩放spine图集大小
 */
public class ScaleAtlas {

    public static void main(String[] args)throws Exception {
        String input = "/Users/jecced/Desktop/Spine/Boss_HL_01_4X.atlas";

        String out = "/Users/jecced/Desktop/Spine/Boss_HL_01_4X.atlas";

        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(input)));
        String line = null;
        int count = 0;
        StringBuilder sb = new StringBuilder();
        while(null != (line = br.readLine())){
            count ++;
            if(line.startsWith("  xy: ")){
                line = "  xy: " + scalc(line);
            }
            if(line.startsWith("  size: ")){
                line = "  size: " + scalc(line);
            }
            if(line.startsWith("  orig: ")){
                line = "  orig: " + scalc(line);
            }

            sb.append(line).append("\n");

        }
        out(sb.toString(), out);
    }

    public static void out(String text, String out){
        File fp = new File(out);
        PrintWriter pfp= null;
        try {
            pfp = new PrintWriter(fp);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        pfp.print(text);
        pfp.flush();
        pfp.close();
    }

    public static String scalc(String line){
        int start = line.indexOf(":") + 2;
        int end = line.indexOf(",");
        String firstStr = line.substring(start, end);
        start = end + 2;
        String endStr = line.substring(start);
        int a = Integer.valueOf(firstStr) / 2;
        int b = Integer.valueOf(endStr) / 2;
        return a + ", " + b;
    }
}

赞(0) 打赏
如果文章对你有帮助,欢迎你来评价反馈。AgainFly » spine图集尺寸缩放

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  • Q Q(选填)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏