Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Loading Sprites or Images in the Starting... — Gideros Forum

Loading Sprites or Images in the Starting...

DoradoLabDoradoLab Member
edited April 2014 in General questions
Hi ,

I am doing a game. I want to load all my sprites and Images in the beginning of a game like in a Class named AssetsLoader and then the loaded Images i need to access and add when ever i want it to display. Can you give me a proper example code snippet.

Thanks.

DoradoLab

Likes: DoradoLab

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    I would not suggest doing so, as it may consume too much memory on device and better divide images in scenes, but that is depending on the amount of images you have.

    But the class could easily look like that:
    AssetsLoader = Core.class()
     
    function AssetsLoader:init()
        self.textures = {}
    end
     
    function AssetsLoader:load(path)
        self.textures[path] = Texture.new(path, true)
    end
     
    function AssetsLoader:loadDir(path)
        if not lfs
            require "lfs"
        end
        for file in lfs.dir(path) do
            if file ~= "." and file ~= ".." then
                self:load(path..file)
            end
        end
    end
     
    function AssetsLoader:get(path)
        return self.textures[path]
    end
    using it:
    al = AssetsLoader.new()
     
    al:loadDir("images")
    al:load("icons/icon.png")
     
    Bitmap.new(al:get("icons/icon.png"))
Sign In or Register to comment.