thrungames

Variables

The game object has a lot of variables to take advantage of. Here is the complete list of them.

Dimensions

width

Width is the width of the game. It is a readonly variable. Trying to overwrite it will not change the canvas size.

var game = new THRUNIUM.Game(400, 400);
game.width;
// returns game width

height

Height is the width of the game. It is a readonly variable. Trying to overwrite it will not change the canvas size.

var game = new THRUNIUM.Game(400, 400);
game.height;
// returns game height

scale

Scale is the density of real pixels in a pixel. It is adjusted automaticly to keep the game sharp. Readonly.

var game = new THRUNIUM.Game(400, 400);
game.scale;
// returns game scale

fitScale

FitScale is the size of the game divied by window size. This basicly fits the game to the window. It is also adjusted automaticly. Readonly.

var game = new THRUNIUM.Game(400, 400);
game.fitScale;
// returns game fitScale

Elements

canvas

Canvas is the reference to the game canvas you can call all normal canvas methods to this variable. Read more

var game = new THRUNIUM.Game(400, 400);
game.canvas;
// returns canvas

ctx

Context (ctx) is the reference to the game 2d context you can call all normal context2d methods to this variable. Read more

var game = new THRUNIUM.Game(400, 400);
game.ctx;
// returns canvas context2d

Loop

fps

FPS is the Frames per Second for the game. It is updated every gameloop. Its a readonly variable and if it is overwriten it will just get replaced next gameloop.

var game = new THRUNIUM.Game(400, 400);
game.fps;
// returns fps count

runSpeed

RunSpeed is max fps divided by current fps. If a device is in power saving mode it will most likely drop in most browsers. You can use this variable to fix your gamespeed. It is updated every gameloop. Its a readonly variable and if it is overwriten it will just get replaced next gameloop.

var game = new THRUNIUM.Game(400, 400);
game.runSpeed;
// returns runSpeed ratio

lastRun

LastRun is a UNIX timestamp in miliseconds of the last time the gameloop was run. It is updated every gameloop. Its a readonly variable and if it is overwriten it will just get replaced next gameloop.

var game = new THRUNIUM.Game(400, 400);
game.lastRun;
// returns lastRun timestamp

gameRunning

GameRunning is a variable that controls the game loop. It can be used to pause the game or to read if the game is running. Default is true.

var game = new THRUNIUM.Game(400, 400);
game.gameRunning = false;
// game will not loop

showFPS

ShowFPS is a variable that controls the display of a FPS meter. It can be used to toggle the FPS meter if set to true it will be dispalyed. Default is false.

var game = new THRUNIUM.Game(400, 400);
game.showFPS = true;
// FPS meter will now be shown

Mouse

mouseX

MouseX is the x coordinate of the mouse, it is updated every time the mouse is moved or clicked. It is a readonly and will be overwriten.

var game = new THRUNIUM.Game(400, 400);
game.mouseX;
// returns the x coordinate of the mouse

mouseY

MouseX is the y coordinate of the mouse, it is updated every time the mouse is moved or clicked. It is a readonly and will be overwriten.

var game = new THRUNIUM.Game(400, 400);
game.mouseY;
// returns the y coordinate of the mouse

State

state

State is the index value of the current state the gameloop is looping. By changed this value you will change the state to loop. At default it is at the loading state but will switch to startState when loaded.

var game = new THRUNIUM.Game(400, 400);
game.state = 'game';
// sets the state to loop

startState

StartState is the index value of the state to loop after startup. This value will only be used once and needs to occur before game init . At default it is set to null so you will have to change it before you start the game.

var game = new THRUNIUM.Game(400, 400);
game.startState = 'menu';
// sets the state to loop after startup

states

States is the array that contains your states. Its a list of functions that will be used as different gameloops. To change to a specific state just change the state value to your states index value.

var game = new THRUNIUM.Game(400, 400);
game.states['game'] = function() {
	// your code to be looped here
}

backgroundColor

backgroundColor is the default backgroundColor of the game. Set this variable to the value you want, supports (hexadecimals, rgb, rgba, hsl, hsla).

var game = new THRUNIUM.Game(400, 400);
game.backgroundColor = '#fff';
// backgroundColor set to #fff

Assets

assetsLoaded

AssetsLoaded is a boolean value that tells you if the requested assets is loaded.

var game = new THRUNIUM.Game(400, 400);
game.assetsLoaded;
// returns a boolean value

loadedAssets

LoadedAssets is the amount of your requested assets that is loaded.

var game = new THRUNIUM.Game(400, 400);
game.loadedAssets;
// returns amount of loaded assets

Font

font

Font is the standard font for your game. Changing this value will change that font. Default value is "Arial"

var game = new THRUNIUM.Game(400, 400);
game.font = "Arial";
// sets the standard font

textSize

TextSize is the standard text size for your game. Changing this value will change that text size. Default value is "32px"

var game = new THRUNIUM.Game(400, 400);
game.textSize = "32px";
// sets the standard text size