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;
    };
  • 相关阅读:
    关于几种滤波的对比
    学习笔记深入理解Java中的HashMap数据结构
    学习笔记Redis基础常识
    学习笔记Java内存模型
    学习笔记理解GC
    工作中的点点滴滴单例的使用
    工作中的点点滴滴学习一下门面模式
    工作中的点点滴滴接口幂等的问题
    【转载】WCF、WebAPI、WCFREST、WebService之间的区别
    【转载】工具分享——将C#文档注释生成.chm帮助文档
  • 原文地址:https://www.cnblogs.com/linn/p/3461855.html
Copyright © 2011-2022 走看看