Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Dynamic Loading of Textures — Gideros Forum

Dynamic Loading of Textures

OZAppsOZApps Guru
edited May 2013 in General questions
Logically this should work, as the textures that are available in the resource directory should be available, however can images that are not added to the project but downloaded from the internet (or created dynamically as could be via render2Texture) be used to load them using the Bitmap.new?

Can put that to rest by trying it out, but if anyone has an idea, please chime in...
twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    @OZApps that is one of the default examples coming with Gideros
    local function onComplete(event)
    	info:setText("done")
     
    	local out = io.open("|D|image.png", "wb")
        out:write(event.data)
        out:close()
     
        local b = Bitmap.new(Texture.new("|D|image.png"))
    	b:setAnchorPoint(0.5, 0.5)
    	b:setPosition(160, 240)
        stage:addChild(b)
    end
     
    local loader = UrlLoader.new("<a href="http://www.giderosmobile.com/giderosmobile.png&quot" rel="nofollow">http://www.giderosmobile.com/giderosmobile.png&quot</a><img class="emoji" src="http://forum.gideros.rocks/resources/emoji/wink.png" title=";)" alt=";)" height="20" />

    Likes: OZApps

    +1 -1 (+1 / -0 )Share on Facebook
  • @ar2rsawseen, so If I use a 3rd party library to generate textures on the fly, they can be used.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • ar2rsawseenar2rsawseen Maintainer
    If you can receive raw bytes of image in lua, then yes, they can be used. As you will be able to save them to Documents or temporary folder and then read as normal image in Gideros
  • @ar2sawseen, I plan to create a plug-in (wrap it around GD libraries) and that will save the image to the device which could then be opened from Gideros.
    twitter: @ozapps | http://www.oz-apps.com | http://howto.oz-apps.com | http://reviewme.oz-apps.com
    Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
    Cool Vizify Profile at https://www.vizify.com/oz-apps
  • krisiskrisis Member
    I use similar code to the above to dynamically load in Facebook friend profile pics into a table view. I queue up all the relevant URLs, download and save the .png, then swap them in for the placeholder profile pic as they become available. They are then cached for the next load. Periodically I can flush the cache as needed to refresh the images.

    Make sure you're passing a valid image file (in a supported format) to Texture.new or it'll barf/crash. e.g. Facebook sometimes return profile pics as .gif files which aren't supported by Texture.new(), so I check image headers and ignore gifs:
    	-- first save data to disk as self.currentFilename then check
    	self.TYPE_MAP = {
    		["^GIF8[7,9]a"] = "gif",
    	}
    	local file, err = io.open(self.currentFilename, "rb")
    	local header = file:read(256)
    	local found = false
    	for pattern, format in pairs(self.TYPE_MAP) do
    		if header:find(pattern) then
    			found = true
    			file:close()
    			if format == "gif" then
    				print("GIF detected for "..self.currentFilename..". Unsupported image type.")
    				os.remove(self.currentFilename)
    				return false
    			end
    		end
    	end
    	if not found then
    		file:close()
    	end

    Likes: OZApps

    [ Twitter: pushpoke | Facebook: facebook.com/pushpoke | Web: pushpoke.com | Letter Stack iOS: letterstack.com ]
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.