您的位置:首页 > 产品设计 > UI/UE

jsb 实现简单的读取ui,ui里的动画,button按钮事件,执行动画代码

2014-03-31 16:57 691 查看
var MainScene = function(){};

MainScene.prototype.onDidLoadFromCCB = function()
{
    cc.log("加载成功");
    this._uiLayer = ccs.UILayer.create();
    this.rootNode.addChild(this._uiLayer);
    
    this._widget = ccs.GUIReader.getInstance().widgetFromJsonFile("res/MenuUI_1.json");
    
    this._uiLayer.addWidget(this._widget);
    
    
    //获取点击按钮
    var button = this._uiLayer.getWidgetByName("Button_23");
    //设置按钮点击事件响应
    button.addTouchEventListener(this.touchEvent,this);
    

};
// 点击button事件
MainScene.prototype.touchEvent = function (sender, type) {
    switch (type) {
        case ccs.TouchEventType.began:
            ccs.ActionManager.getInstance().playActionByName("MenuUI_1.json","Animation0");
            break;
        default:
            break;
    }
}
MainScene.prototype.next = function()
{
    var sp = cc.Sprite.create("01.png");
    sp.setPosition(300,300);
    
    this.rootNode.addChild(sp);
    
    cc.log("按住nextbtn");
    
    this.ttt();
    // 启动定时器
    //this.rootNode.schedule(this.ttt,1)
    
};
MainScene.prototype.ttt = function()
{
    //cc.log("定时器1")

    ccs.ActionManager.getInstance().playActionByName("MenuUI_1.json","Animation0");
    

};

-----------------------------------------————————————————执行动画——————————————————————————————————————————

var s_Dragon_plist = "res/Dragon.plist";
var s_Dragon_png = "res/Dragon.png";
var s_Dragon_xml = "res/Dragon.xml";

var s_Cowboy_json =
"res/Cowboy.ExportJson";
var s_Cowboy_plist = "res/Cowboy0.plist";
var s_Cowboy_png = "res/Cowboy0.png";

var ArmatureTestLayer = cc.Layer.extend({
     ctor:function () {
                                        this._super();
                                        cc.associateWithNative(
this, cc.Layer );
                                        
                                        
                                        
                                        
                                        
                                        
                                        ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_Cowboy_json);
                                        var armature = ccs.Armature.create("Cowboy");
                                        //armature.getAnimation().playWithIndex(0);
                                        armature.getAnimation().play("FireWithoutBullet");
                                        armature.getAnimation().setSpeedScale(0.4);
                                        armature.setScale(0.6);
                                        armature.setAnchorPoint(0.5,
0.5);
                                        armature.setPosition(300,
300);
                                        this.addChild(armature);
                                        
                                        
                                        
                                        
//                                        ccs.ArmatureDataManager.getInstance().addArmatureFileInfo(s_Dragon_png, s_Dragon_plist, s_Dragon_xml);
//                                        var armature = ccs.Armature.create("Dragon");
//                                        armature.getAnimation().playWithIndex(0);
//                                        //armature.getAnimation().play("Dragon");
//                                        armature.getAnimation().setSpeedScale(0.4);
//                                        armature.setScale(0.6);
//                                        armature.setAnchorPoint(0.5, 0.5);
//                                        armature.setPosition(300, 300);
//                                        this.addChild(armature);

     }
     
    
 });
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: