• 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;
    };
  • 相关阅读:
    hdu4829 带权并查集(题目不错)
    hdu4829 带权并查集(题目不错)
    洛谷 P1076 寻宝(模拟 && 剪枝)
    洛谷 P1981 表达式求值(模拟)
    洛谷 P2239 螺旋矩阵(模拟 && 数学)
    洛谷 P2118 比例简化(枚举)
    洛谷 P3956 棋盘(记忆化搜索)
    洛谷 P5018 对称二叉树(搜索)
    洛谷 P5016 龙虎斗(模拟)
    洛谷 P1563 玩具谜题(模拟)
  • 原文地址:https://www.cnblogs.com/linn/p/3461855.html
Copyright © 2020-2023  润新知