Exemplo n.º 1
0
        /// <summary>
        /// Adds a sprite (from a resource) to a collection
        /// </summary>
        /// <returns>The spriteID of the defintion in the collection</returns>
        public static int AddSpriteToCollection(string resourcePath, tk2dSpriteCollectionData collection)
        {
            string extension = !resourcePath.EndsWith(".png") ? ".png" : "";

            resourcePath += extension;
            var texture = ResourceExtractor.GetTextureFromResource(resourcePath); //Get Texture

            var definition = ConstructDefinition(texture);                        //Generate definition

            definition.name = texture.name;                                       //naming the definition is actually extremely important

            return(AddSpriteToCollection(definition, collection));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns an object with a tk2dSprite component with the
        /// texture of an embedded resource
        /// </summary>
        public static GameObject SpriteFromResource(string spriteName, GameObject obj = null, bool copyFromExisting = true)
        {
            string extension    = !spriteName.EndsWith(".png") ? ".png" : "";
            string resourcePath = spriteName + extension;

            var texture = ResourceExtractor.GetTextureFromResource(resourcePath);

            if (texture == null)
            {
                return(null);
            }

            return(SpriteFromTexture(texture, resourcePath, obj, copyFromExisting));
        }