-
Notifications
You must be signed in to change notification settings - Fork 0
/
image.lua
executable file
·61 lines (46 loc) · 1.3 KB
/
image.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Image = class('Image')
local g = love.graphics
function Image:initialize(image, x, y, w, h, sx, sy, mirror)
self.image = image
self.w = w
self.h = h
self.sx = sx or 1
self.sy = sy or 1
self.mirror = mirror or false
self.quad = g.newQuad(x, y, w, h, image:getWidth(), image:getHeight())
end
function Image:set(px, py)
self.px = px
self.py = py
end
function Image:draw(x,y,w,h,angle)
w = w or self.w
h = h or self.h
angle = angle or 0
self.image:setFilter('nearest', 'nearest')
g.setColor(255,255,255,255)
g.drawq(self.image, self.quad, x, y, 0, w / self.w, h / self.h, self.w/2, self.h/2)
end
function Image:draw2(x,y,w,h, r, g1, b, a)
x = x or self.px
y = y or self.py
w = w or self.w
h = h or self.h
r = r or 255
g1 = g1 or 255
b = b or 255
a = a or 255
self.image:setFilter('nearest', 'nearest')
g.setColor(r, g1, b, a)
g.drawq(self.image, self.quad, x, y, 0, w / self.w, h / self.h)
end
function Image:drawRotate(x,y,angle)
self.image:setFilter('linear', 'linear')
g.setColor(255,255,255,255)
if self.mirror then
g.drawq(self.image, self.quad, x, y, angle, self.sx, self.sy, self.w, self.h/2)
g.drawq(self.image, self.quad, x, y, angle, -self.sx, self.sy, self.w, self.h/2)
else
g.drawq(self.image, self.quad, x, y, angle, self.sx, self.sy, 1, self.w/2, self.h/2)
end
end