[back to index]

Library Reference (v 0.10.0)

Gfx

For drawing and manipulating shapes and images.
Gfx.clearscreen(color:Int)
Clears the screen to the given colour.
Gfx.clearcolor:Int
Set to the colour you want to clear the screen to at the start of each frame. If set to Col.TRANSPARENT, the the screen is not cleared at the start of each frame. Default value is Col.BLACK.
import haxegon.*;

class Main {
 function new() {
  //Don't clear the screen each frame
   Gfx.clearcolor = Col.TRANSPARENT;
 }
 
 function update() {
  //Draw a filled hexagon at the mouse cursor
  Gfx.fillhexagon(Mouse.x, Mouse.y, 50, Core.time, Gfx.hsl(Core.time * 30, 0.5, 0.5)); 
 }
}
Gfx.drawbox(x:Float, y:Float, width:Float, height:Float, color:Int, alpha:Float = 1.0)
Draw a box at (x, y) with given width, height, colour and alpha.
Gfx.fillbox(x, y, width, height, col)
Fill a box at (x, y) with given width, height, colour and alpha.
Gfx.drawtri(x1:Float, y1:Float, x2:Float, y2:Float, x3:Float, y3:Float, color:Int, alpha:Float = 1.0)
Draw a triangle between the points (x1, y1), (x2, y2) and (x3, y3) with given colour and alpha.
Gfx.filltri(x1:Float, y1:Float, x2:Float, y2:Float, x3:Float, y3:Float, col:Int, alpha:Float = 1.0)
Fill a triangle between the points (x1, y1), (x2, y2) and (x3, y3) with given colour and alpha.
Gfx.drawcircle(x:Float, y:Float, radius:Float, color:Int, alpha:Float = 1.0)
Draw a cirle centered at (x, y), with given radius, colour and alpha.
Gfx.fillcircle(x:Float, y:Float, radius:Float, color:Int, alpha:Float = 1.0)
Fill a cirle centered at (x, y), with given radius, colour and alpha.
Gfx.drawhexagon(x:Float, y:Float, radius:Float, angle:Float, color:Int, alpha:Float = 1.0)
Draw a hexagon centered at (x, y), with given radius, angle, colour and alpha.
Gfx.fillhexagon(x:Float, y:Float, radius:Float, angle:Float, color:Int, alpha:Float = 1.0)
Draw a filled hexagon centered at (x, y), with given radius, angle, colour and alpha.
Gfx.drawline(x1:Float, y1:Float, x2:Float, y2:Float, color:Int, alpha:Float = 1.0)
Draw a line between (x1, y1) and (x2, y2) with a given colour and alpha.
Gfx.linethickness:Float
Set the thickness of the line when drawing lines, boxes, triangles, etc. Default value of 1.0.
Gfx.setpixel(x:Float, y:Float, color:Int):Int
Sets the pixel at (x, y) to the given colour.
Gfx.getpixel(x:Float, y:Float)
Get the colour at the pixel (x, y). Very slow! Try to avoid using every frame if you can!
Gfx.screenwidth:Int
Returns screen width.
Gfx.screenheight:Int
Returns screen height.
Gfx.screenwidthmid:Int
Returns screen width divided by two.
Gfx.screenheightmid:Int
Returns screen height divided by two.
Gfx.fullscreen:Bool
Set true or false to switch between window and fullscreen.
Gfx.resizescreen(width, height)
Sets the width and the height of the screen canvas. Automatically scales to fit in the current window, depending on your resize settings.
Gfx.loadimage(imagename:String)
Loads a .PNG or .JPG image from data/graphics/.
Gfx.drawimage(x:Float, y:Float, imagename:String)
Draw this image to the point (x, y).
Gfx.drawsubimage(x:Float, y:Float, x1:Float, y1:Float, w1:Float, h1:Float, imagename:String)
Draw a subset of this image from the rectangle (x1, y1, w1, h1) to the point (x, y).
Gfx.imagewidth(imagename):Int
Returns the width of an image.
Gfx.imageheight(imagename):Int
Returns the height of an image.
Gfx.createimage(imagename:String, width:Int, height:Int) 
Creates a blank image, with the name imagename, with given width and height.
Gfx.drawtoscreen()
Tell all future draw operations to draw to the screen. (rather than an image or tile.)
Gfx.drawtoimage(imagename:String)
Tell all future draw operations to draw to this image. (rather than a tile or the screen). Warning: drawing to something other than the screen is currently very slow in Haxegon!
Gfx.drawtotile(tilesetname:String, tilenumber:Int)
Tell all future draw operations to draw to this tile on this tileset. (rather than an image or the screen). Warning: drawing to something other than the screen is currently very slow in Haxegon!
Gfx.grabimagefromscreen(imagename:String, screenx:Float, screeny:Float)
This function grabs a copy of the screen from position (screenx, screeny), and places it in the image.
Gfx.grabtilefromscreen(tilesetname:String, tilenumber:Int, screenx:Float, screeny:Float)
This function grabs a tile from the screen at position (screenx, screeny), and places it in the tile.
Gfx.grabimagefromimage(imagetocopyto:String, sourceimage:String, sourceimagex:Float, sourceimagey:Float)
This function grabs an image from another image at position (sourceimagex, sourceimagey), and places it in the new image.
Gfx.copytile(totileset:String, totilenumber:Int, fromtileset:String, fromtilenumber:Int)
Copies a tile from one tileset to another. If the source tile is larger than the destination tile, the tile is cropped.
Gfx.rotation(angle:Float, xpivot=Gfx.CENTER, ypivot=Gfx.CENTER)
Rotates image drawing functions. Optionally set rotation pivot point.
Gfx.scale(xscale:Float, yscale:Float, xpivot=Gfx.CENTER, ypivot=Gfx.CENTER)
Scales image drawing functions like Gfx.drawimage and Gfx.drawtile. Optionally set scaling pivot point. Scales X and Y seperately - if you call with only one argument, it scales X and Y the same. If you call with no arguments, it resets the scale to 1.0.
Gfx.imagecolor:Int
Set a colour multipler in RGB for image drawing functions. Set to Col.WHITE or call Gfx.resetcolor() to return to normal.
Gfx.resetcolor()
Reset colour multiplier for image drawing functions. Same as calling Gfx.imagecolor = Col.WHITE;
Gfx.imagealpha:Float
Set an alpha multipler [0 to 1.0] for image drawing functions. Default value is 1. Set to 1 or call Gfx.resetalpha() to return to normal.
Gfx.resetalpha()
Reset alpha multiplier for image drawing functions. Same as calling Gfx.imagealpha = 1;
Gfx.reset()
Reset alpha multiplier, colour multiplier, rotation and scale for image drawing functions.
Gfx.loadtiles(tilesetname:String, tilewidth:Int, tileheight:Int)
Loads a .PNG or .JPG image from data/graphics/, and splits it into tiles.
Gfx.createtiles(tilesetname:String, tilewidth:Int, tileheight:Int, amount:Int)
Creates a blank tileset, with the name 'tilesetname', with each tile a given width and height, containing 'amount' tiles.
Gfx.drawtile(x:Float, y:Float, tilesetname:String, tilenum:Int)
Draw this tile to the point (x, y).
Gfx.drawsubtile(x:Float, y:Float, tilesetname:String, tilenum:Int, x1:Float, y1:Float, w:Float, h:Float)
Draw a subset of this tile from the rectangle (x1, y1, w1, h1) to the point (x, y).
Gfx.addblanktiles(tilesetname:String, num:Int):Int
Add some blank tiles to the end of a tileset.
Gfx.numberoftiles(tilesetname:String):Int
Returns the number of tiles in a tileset.
Gfx.tilewidth(tilesetname:String):Int
Returns the width of a tile in this tileset.
Gfx.tileheight(tilesetname:String):Int
Returns the width of a tile in this tileset.
Gfx.CENTER
A constant passed to functions like Gfx.rotation() and Gfx.scale() to set the pivot point for either the x or y value to the center of the image.
Gfx.LEFT
A constant passed to functions like Gfx.rotation() and Gfx.scale() to set the pivot point for the x value to the left of the image.
Gfx.RIGHT
A constant passed to functions like Gfx.rotation() and Gfx.scale() to set the pivot point for the x value to the right of the image.
Gfx.TOP
A constant passed to functions like Gfx.rotation() and Gfx.scale() to set the pivot point for the y value to the top of the image.
Gfx.BOTTOM
A constant passed to functions like Gfx.rotation() and Gfx.scale() to set the pivot point for the y value to the bottom of the image.