Engine 0.0.4
Game engine in lua
Loading...
Searching...
No Matches
draw.lua
Go to the documentation of this file.
1local math = require('math')
2
3--! @cond
4local canvas = nil
5local game = nil
6--! @endcond
7
8local function color(c)
9 local R = math.floor(c/0x1000000)
10 local G = math.floor(c/0x10000) - (R * 0x100)
11 local B = math.floor(c/0x100) - (R * 0x10000) - (G * 0x100)
12 local A = c - (R * 0x1000000) - (G * 0x10000) - (B * 0x100)
13 canvas:attrColor(R, G, B, A)
14end
15
16local function clear(c)
17 color(c)
18 canvas:drawRect('fill', 0, 0, game.width, game.height)
19end
21local function rect(mode, x, y, width, height)
22 canvas:drawRect(mode == 0 and 'fill' or 'frame', x, y, width, height)
23end
24
25local function text(x, y, text)
26 if x and y then
27 canvas:drawText(x, y, text)
28 end
29 return canvas:measureText(text or x)
30end
31
32local function font(a,b)
33 canvas:attrFont(a,b)
34end
35
36local function line(x1, y1, x2, y2)
37 canvas:drawLine(x1, y1, x2, y2)
38end
39
40local function install(std, lgame, application, ginga)
41 canvas = ginga.canvas
42 game = lgame
43 std = std or {}
44 std.draw = std.draw or {}
51 local index = #application.internal.fixed_loop + 1
52 application.internal.fixed_loop[index] = function ()
53 canvas:attrColor(0, 0, 0, 0)
55 application.callbacks.draw(std, game)
56 if game.fps_show and game.fps_show >= 0 and std.draw.fps then
57 std.draw.fps(game.fps_show, 8, 8)
58 end
59 canvas:flush()
60 end
61 return std.draw
62end
63
64local P = {
66}
67
68return P
local function fps(self, show, x, y)
local function require(std, game, application)
local application
Definition main.lua:16
local canvas
nclua:canvas
Definition main.lua:22
local game
Definition main.lua:17
local std
Definition main.lua:18
local function fixed_loop()
local color
Definition main.lua:12
local function install(std, lgame, application, ginga)
local function line(x1, y1, x2, y2)
local function clear(c)
local function font(a, b)
local function rect(mode, x, y, width, height)
local math
Definition draw.lua:1
local function text(x, y, text)
local function draw(std, game)