zoukankan      html  css  js  c++  java
  • initWithSpriteFrameName和createWithSpriteFrameName

    /**
         * Initializes a sprite with a sprite frame name. <br/>
         * A cc.SpriteFrame will be fetched from the cc.SpriteFrameCache by name.  <br/>
         * If the cc.SpriteFrame doesn't exist it will raise an exception. <br/>
         * @param {String} spriteFrameName A key string that can fected a volid cc.SpriteFrame from cc.SpriteFrameCache
         * @return {Boolean} true if the sprite is initialized properly, false otherwise.
         * @example
         * var sprite = new cc.Sprite();
         * sprite.initWithSpriteFrameName("grossini_dance_01.png");
         */
        initWithSpriteFrameName:function (spriteFrameName) {
            cc.Assert(spriteFrameName != null, "");
            var frame = cc.SpriteFrameCache.getInstance().getSpriteFrame(spriteFrameName);
            return this.initWithSpriteFrame(frame);
        },
    /**
     * <p>
     *     Creates a sprite with a sprite frame.                                                                  <br/>
     *                                                                                                            <br/>
     *    A CCSpriteFrame will be fetched from the CCSpriteFrameCache by pszSpriteFrameName param.                <br/>
     *    If the CCSpriteFrame doesn't exist it will raise an exception.
     * </p>
     * @param {String} spriteFrameName A sprite frame which involves a texture and a rect
     * @return {cc.Sprite} A valid sprite object
     * @example
     *
     * //create a sprite with a sprite frame
     * var sprite = cc.Sprite.createWithSpriteFrameName('grossini_dance_01.png');
     */
    cc.Sprite.createWithSpriteFrameName = function (spriteFrameName) {
        var spriteFrame = null;
        if (typeof(spriteFrameName) == 'string') {
            spriteFrame = cc.SpriteFrameCache.getInstance().getSpriteFrame(spriteFrameName);
            if (!spriteFrame) {
                cc.log("Invalid spriteFrameName: " + spriteFrameName);
                return null;
            }
        } else {
            cc.log("Invalid argument. Expecting string.");
            return null;
        }
        var sprite = new cc.Sprite();
        if (sprite && sprite.initWithSpriteFrame(spriteFrame)) {
            return sprite;
        }
        return null;
    };
  • 相关阅读:
    吐血巨献:VB网络编程(webbrowser+Inet+抓包封包+经验)
    亦思验证码识别系统3.1详解
    开机自动连接宽带程序
    轻松报选修智能报选修程序(适用于正方教学管理系统)
    低调发布一个百度谷歌关键字搜索工具
    解惑:Postmessage函数模拟鼠标单击指定坐标
    分享一些经典资源
    英文单词缩写查询
    css控制的个性导航栏
    导航栏中加入自动弹出下拉菜单
  • 原文地址:https://www.cnblogs.com/linn/p/3461855.html
Copyright © 2011-2022 走看看