Scrupp 0.1 Manual
Create your own 2D games and applications
Image support is implemented using SDL_image.
JPEG support requires the JPEG library:
IJG Homepage
PNG support requires the PNG library:
PNG Homepage
and the Zlib library:
Zlib Homepage
TIFF support requires the TIFF library:
SGI TIFF FTP Site

Loading

game.addImage(filename)
Loads the image file with the given filename. Supported formats: BMP, PNM (PPM/PGM/PBM), XBM, LBM, PCX, GIF, JPEG, PNG and TIFF. Returns an image object.

Methods

image:getWidth()
Returns the image width.
image:getHeight()
Returns the image height.
image:getSize()
Returns the width and the height of the image.
image:isTransparent(x, y)
Returns true if the pixel of the image with the coordinates x and y is not opaque, i.e. has an alpha value lower than 255. Returns false otherwise. This is not influenced by the alpha value of the whole image changed using image:setAlpha().
image:setAlpha(alpha)
Changes the alpha value of the image. alpha has to be between 0 (transparent) and 255 (opaque).
image:getAlpha()
Returns the current alpha value of the image. This value is between 0 (transparent) and 255 (opaque).
image:render(x, y)
Renders the image at the window coordinates x and y.
image:render(table)
This is nearly the same as the last one. This time a table contains the arguments. The first two elements of the array part of the table have to be the x- and y-coordinate of the point that the image should be rendered at. The table may have an optional rect entry. This has to be a table describing the rectangle the image should be clipped to. It contains the x- and y-coordinate of the upper left corner and the width and height of the rectangle inside the image.

Example

game.init("Image Test", 600, 400, 32, false)

-- load an image file
image = game.addImage(<image file>)

-- get the dimension of the image
width = image:getWidth()
height = image:getHeight()

-- this has the same result:
width, height = image:getSize()

if width > game.getWindowWidth() or height > game.getWindowHeight() then
	print("Please choose an image with smaller dimensions.")
	game.exit()
end

-- calculate the x- and y-coordinate of the image
x = (game.getWindowWidth()-width)/2
y = (game.getWindowHeight()-height)/2

main = {
	render = function(dt)
		-- get the position of the mouse pointer
		mx, my = mouse:getPos()
		-- set the image alpha depending on the x-coordinate of the 
		-- mouse pointer
		image:setAlpha(mx/game.getWindowWidth()*200+50)
		-- if you click with the left mouse button,
		-- only a part of the image is rendered
		if mouse.isDown("left") then
			image:render{
				mx, my,
				rect = { mx-x, my-y, width/2, height/2 }
			}
		-- otherwise the whole image is rendered
		else
			image:render(x,y)
		end
	end
}

Hosted by
SourceForge.net Logo

Valid XHTML 1.0!

Last modified Tue May 20, 2008