-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsprite.lua
46 lines (38 loc) · 964 Bytes
/
sprite.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using 'pl'
using 'dokidoki'
local graphics = dokidoki.graphics
local quaternion = dokidoki.quaternion
local gl = require 'gl'
local box_image = {
draw = function ()
gl.glBegin(gl.GL_QUADS)
gl.glVertex2d(0, 0)
gl.glVertex2d(1, 0)
gl.glVertex2d(1, 1)
gl.glVertex2d(0, 1)
gl.glEnd()
end
}
local sprite = pl.class(dokidoki.component)
sprite._name = 'sprite'
function sprite:_init(parent, transform)
self:super(parent)
self.transform = assert(transform or parent.transform)
self.image = box_image
self.color = false
self.scale = false
self:add_handler_for('draw')
end
function sprite:draw()
gl.glPushMatrix()
graphics.apply_transform(
self.transform.pos, self.transform.orientation, self.scale)
if self.color then
gl.glColor4d(color[1], color[2], color[3], color[4] or 1)
end
gl.glNormal3d(0, 0, 1)
self.image:draw()
if self.color then gl.glColor3d(1, 1, 1) end
gl.glPopMatrix()
end
return sprite