cocostudio 1.6 填坑小记

话说cocos官方在过年之际新出了cocos creator测试版,现在什么年代,还cocostudio 1.6?!在此暂不说,说说cocostudio1..6众所周知的锚点不齐bug!

但是,有bug总有解决的方法,我的办法就是取到当前对象的大小,你锚点不正对吧,我自已来!方法如下:

  1. 首先,还是先说一说cocostudio在cocos-js中的加载方式:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ctor: function(){
    this._super();
    this._root = ccs.uiReader.widgetFromJsonFile(FynnJsonPath+"NewFynnLobby.json");//加载json文件,cocostudio导出的UI文件
    this._root.setContentSize(cc.winSize);
    this.addChild(this._root);
    //取子节点下元素方法
    this._bg = ccui.helper.seekWidgetByName(this._root,"bg_all");//BG
    this._doustar = ccui.helper.seekWidgetByName(this._root,"_ico_ledou");//doustar
    this._jinbistar = ccui.helper.seekWidgetByName(this._root,"_ico_jinbi");//_ico_jinbi
    this._star = ccui.helper.seekWidgetByName(this._root,"_btn_enterico_1");//_btn_enterico
    }
  1. 接下来如果有一个需求是这样的,我需要在_ico_jinbi上添加一个动画效果,这就需要完全覆盖这个icon,这就需要对正锚点,可cocostudio锚点很有问题!
    没关系,可以这样做:
1
2
3
4
5
6
7
//cocostudio动画加载方法
ccs.armatureDataManager.addArmatureFileInfo(FynnFlashPath + "xxx.ExportJson");
var _armature = new ccs.Armature("xxxbutton");
_armature.getAnimation().play("startlight",-1,1);//1 loop play, 0 play once
this._jinbistar.addChild(_armature, 0);
_armature.x = _armature.x + this._jinbistar.getContentSize().width / 2;//方法的关键在于用getContentSize()获取子节点当前对象大小
_armature.y = _armature.y + this._jinbistar.getContentSize().height / 2;

当然,cocostudio的动画加载上面有提到,现在具体也记录下:
对于ExportJson动画文件的加载,其中如果美术只给你这个文件的话,要如何得知其文件中各骨骼动画的名称呢?步骤如下:
  1. 用文本编辑出版(如Nodepad++)打开ExportJson文件;
  2. 按ctrl + F 调出搜索框,
  • 关键词"mov_bone_data"得到Armature().name,也就是动画标签名,在 armature_data上面得到,用于play()。
  • 关键词"mov_data"得到的是Armature,用于cc.Armature()。

这全是踩坑踩出来的小心得,不用谢,请拿走,希君有用!哈哈~~~