-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTKPropUtil.lua
63 lines (55 loc) · 1.49 KB
/
TKPropUtil.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
62
63
module(..., package.seeall)
function flopProp ( prop, flipped )
local x, y = prop:getScl ()
if flipped then
if x > 0 then
x = -x
end
else
if x < 0 then
x =-x
end
end
prop:setScl ( x, y )
end
function flipProp ( prop, flopped )
local x, y = prop:getScl ()
if flopped then
if y > 0 then
y = -y
end
else
if y < 0 then
y =-y
end
end
prop:setScl ( x, y )
end
function scaleProp ( prop, scaleFactor, scaleFactorY )
local x, y = prop:getScl ()
if not scaleFactorY then
scaleFactorY = scaleFactor
end
prop:setScl ( x * scaleFactor, y * scaleFactorY )
end
function replaceProp ( layer, propId, frame, texturePack )
local prop = layer:findPropById( propId )
local scaleX, scaleY = prop:getScl ()
local x, y = prop:getLoc()
local priority = prop:getPriority ()
local frameInfo = texturePack:getFrameInfo ( frame )
local index = frameInfo.index
local deck = frameInfo.deck
local resourceScaleFactor = frameInfo.resourceScaleFactor
local newProp = MOAIProp2D.new ()
newProp:setDeck ( deck )
newProp:setIndex ( index )
newProp:setLoc ( x, y )
newProp:setScl ( resourceScaleFactor )
newProp:setPriority ( priority )
newProp:setScl ( scaleX, scaleY )
newProp.onTouch = prop.onTouch
layer:removeProp ( prop )
layer:insertProp ( newProp )
layer:cacheView ( propId, newProp )
end