Skip to content
Screenshot extension for the Defold game engine
C C++ Other
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
assets
example
input
screenshot
.clang_complete
.gitignore
LICENSE.md
README.md
game.project
logo.png

README.md

Defold-Screenshot

Screenshot extension for the Defold game engine

Installation

You can use Defold-Screenshot in your own project by adding this project as a Defold library dependency. Open your game.project file and in the dependencies field under project add:

https://github.com/britzl/defold-screenshot/archive/master.zip

Or point to the ZIP file of a specific release.

Usage

The extensions will declare a new module, exposed to Lua as screenshot. The extension has the following functionality:

	-- The extension has an alternative implementation for HTML5
	-- On HTML5 screenshot will return as base64 encoded image in a callback
	--
	if screenshot.html5 then
		screenshot.html5(function(self, base64_img)
			-- share your base64 png
		end)
		-- Capture screenshots of a portion of the screen:
		-- screenshot.html5(x, y, width, height, callback)
	else
		-- IMPORTANT! The functionality below is NOT available on HTML5

		-- Take screenshot and encode to a PNG
		-- Write it to foo.png
		local png, w, h = screenshot.png()
		local f = io.open("screenshot1.png", "wb")
		f:write(png)
		f:flush()
		f:close()

		-- Take screenshot and return it as a Defold buffer
		-- Set buffer as texture on a model
		local buffer, w, h = screenshot.buffer()
		local url = go.get("cube#model", "texture0")
		resource.set_texture(url, { type = resource.TEXTURE_TYPE_2D, width = w, height = h, format = resource.TEXTURE_FORMAT_RGBA }, buffer)

		-- Take screenshot and return pixels as a Lua string
		local pixels, w, h = screenshot.pixels()

		-- Capture screenshots of a portion of the screen
		screenshot.png(x, y, w, h)
		screenshot.buffer(x, y, w, h)
		screenshot.pixels(x, y, w, h)
	end

Credits

You can’t perform that action at this time.