You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Load the custom image for each BGO if it exists in .PNG format
32
+
* This will rather redundantly reload images that are already in the memory of SMBX; however, there is no workaround for this issue right now.
33
+
********************************************]]
34
+
localfunctionloadImg(id)
35
+
localimageName=Misc.resolveFile("background-" ..id..".png") -- Search level and episode directorties
36
+
localimage;
37
+
ifimageNamethen
38
+
image=Graphics.loadImage(imageName)
39
+
end
40
+
ifimagethenreturnimage;
41
+
elsereturnnil; end;
42
+
end
43
+
44
+
--[[********************************************
45
+
* Set the given BGO to be drawn over if a valid custom image exists
46
+
* and it is larger than the original in either dimension.
47
+
********************************************]]
48
+
localfunctionsetShouldDraw(bgo, image)
49
+
ifimagethen
50
+
if (image.width~=bgo.width) or (image.height~=image.height) then
51
+
returntrue;
52
+
else
53
+
returnfalse;
54
+
end
55
+
end
56
+
end
57
+
58
+
--[[********************************************
59
+
* Get the default render priority for the BGO with the given ID
60
+
********************************************]]
61
+
localfunctiongetDefault(id) -- Test sets from most likely to least likely, except for the largest set, to avoid as many tests as possible.
62
+
for_,vinpairs(defaults.foreground) do
63
+
ifid==vthen
64
+
return-20;
65
+
end
66
+
end
67
+
for_,vinpairs(defaults.veryBackBgos) do
68
+
ifid==vthen
69
+
return-95;
70
+
end
71
+
end
72
+
for_,vinpairs(defaults.specialBGOs) do
73
+
ifid==vthen
74
+
return-80;
75
+
end
76
+
end
77
+
return-85;
78
+
end
79
+
80
+
--[[********************************************
81
+
* Set the render priority to the default value or to a custom value inputted by the user
82
+
* Note: This uses LunaLua render priorities, which are not equivalent to SMBX sort-order priorities!
83
+
* This could change the render order from how it is normally. If this occurs, use setPriority to fix it.
84
+
* This will only work if called in onStart!
85
+
********************************************]]
86
+
functionbgofix.setPriority(id, priority)
87
+
assert(bgos[id].image, "Cannot change the render priority of BGO-" ..id.." because it doesn't have a .PNG custom image.") -- Make sure the user didn't break the rules.
88
+
if (priority) andnot (bgos[id].shouldDraw) then
89
+
bgos[id].shouldDraw=true-- Handling for the user changing the render priority of BGOs which are the same size as the original
90
+
end
91
+
92
+
bgos[id].priority=priorityorgetDefault(id) -- fetch default setting if custom setting is not given.
93
+
Graphics.sprites.background[id].img=blank-- Make the actual BGO invisible. This is to allow the user to make the BGO's render priority lower.
94
+
end
95
+
96
+
--[[********************************************
97
+
* Resize the given BGO to have the same dimensions as its image
98
+
********************************************]]
99
+
localfunctionresize(bgo, image)
100
+
if ((image) and (bgo.width~=image.widthorbgo.height~=image.height)) then
101
+
bgo.width=image.width
102
+
bgo.height=image.height
103
+
end
104
+
end
105
+
106
+
--[[********************************************
107
+
* Initialization
108
+
********************************************]]
109
+
functionbgofix.initialize()
110
+
111
+
for_,bgoinipairs(BGO.get()) do
112
+
ifnotbgos[bgo.id] then-- Do this only once for each BGO with a unique ID.
113
+
bgos[bgo.id] = {}
114
+
bgos[bgo.id].image=loadImg(bgo.id) -- custom image (nil if no valid image)
115
+
bgos[bgo.id].shouldDraw=setShouldDraw(bgo, bgos[bgo.id].image); -- Does the BGO need to be rendered over?
0 commit comments