public void initWithImageNamed(string imageName)
        {
            gameObject.name = imageName;
            CCSpriteFrame frame = CCSpriteFrameCache.sharedSpriteFrameCache.spriteFrameByName(imageName);

            if (frame == null)
            {
                CCDebug.Info("cocos2d:CC3Sprite: try to load '{0}' as a file.", imageName);
                string    path    = FileUtils.GetFilePathWithoutExtends(imageName);
                Texture2D texture = Resources.Load <Texture2D> (path);
                NSUtils.Assert(texture != null, "cocos2d:CC3Sprite: '{0}' not found.", path);
                frame = new CCSpriteFrame(texture, new Rect(Vector2.zero, new Vector2(texture.width, texture.height)));
                frame.semiTransparent = false;
            }
            initWithSpriteFrame(frame);
        }
Esempio n. 2
0
        // ------------------------------------------------------------------------------
        //  Adds multiple Sprite Frames from a plist file.
        // ------------------------------------------------------------------------------

        /** Adds multiple Sprite Frames from a plist file.
         * A texture will be loaded automatically. The texture name will composed by replacing the .plist suffix with .png .
         * If you want to use another texture, you should use the addSpriteFramesWithFile:texture method.
         */
        public void addSpriteFramesWithFile(string path)
        {
            path = FileUtils.GetFilePathWithoutExtends(path);
            if (_loadedFilenames.Contains(path))
            {
                CCDebug.Warning("cocos2d: CCSpriteFrameCache: file already loaded: {0}", path);
            }
            else
            {
                _loadedFilenames.Add(path);
                NSDictionary dict    = NSDictionary.DictionaryWithContentsOfFileFromResources(string.Concat(path, ".txt"));
                Texture2D    texture = Resources.Load <Texture2D> (path);
                if (texture != null)
                {
                    addSpriteFrames(dict, texture, path);
                }
                else
                {
                    CCDebug.Log("cocos2d: CCSpriteFrameCache: Couldn't load texture: {0}", path);
                }
            }
        }