Page 1 of 1
Drawing an Image From The Resource Memory
Posted: Mon Jun 06, 2016 5:33 pm
by Sambo
I was wondering if there's a way to draw an image on the screen that has been loaded into the resource memory of SMBX when the level started. For instance, I could grab the image that has been loaded for block-1 and draw it on the screen. There is a reason for this. I want to draw several images on the screen that are already loaded into SMBX when the level starts, and it seems redundant (and bad for memory usage) to load them all again so I can draw them.
Re: Drawing an Image From The Resource Memory
Posted: Mon Jun 06, 2016 5:55 pm
by S1eth
Sambo wrote:I was wondering if there's a way to draw an image on the screen that has been loaded into the resource memory of SMBX when the level started. For instance, I could grab the image that has been loaded for block-1 and draw it on the screen. There is a reason for this. I want to draw several images on the screen that are already loaded into SMBX when the level starts, and it seems redundant (and bad for memory usage) to load them all again so I can draw them.
What you need is here:
http://wohlsoft.ru/pgewiki/SpriteOverride_%28class%29
and
http://wohlsoft.ru/pgewiki/LunaLua_glob ... _functions
You can get a LuaImageResource from a block/npc/etc. by typing:
Code: Select all
local blockImg = Graphics.sprites.block[1].img -- get the image of the block with id 1
You can then use this blockImg variable in Graphics.drawImageWP.
However, there appears to be a bug when trying to use this with certain drawing functions:
http://www.supermariobrosx.org/forums/v ... 73#p219773
Re: Drawing an Image From The Resource Memory
Posted: Tue Jun 07, 2016 12:48 am
by Sambo
Are you sure this works? Because, I tried this and got a "No matching overload" error every time, with every drawing function.
Re: Drawing an Image From The Resource Memory
Posted: Tue Jun 07, 2016 1:04 am
by Quantumenace
I was never able to make that work either. Reading from that array gets you "something" (it isn't nil) but it doesn't appear to be the same as a lua image resource. It doesn't have a readable .width or .height like a lua-loaded image does.
Re: Drawing an Image From The Resource Memory
Posted: Tue Jun 07, 2016 5:01 pm
by Sambo
It says the class will return an SMBXMaskedImage object. This is probably not usable by any of the drawing functions. Perhaps compatibility should be added. Of course, there are probably very few situations in which it would actually be useful.
It
does work, but only if I replace the sprite with a luaImageResource object first, which really defeats the whole purpose of this anyway.
Here is a little test script I created to test this:
Code: Select all
local blockImg = Graphics.loadImage("block-1.png")
function onStart()
Graphics.sprites.block[65].img = blockImg
img = Graphics.sprites.block[65].img
end
function onTick()
Graphics.drawImage(img, 32, 568)
end
There is a custom image for block-1 in my test level's folder. Also, apparently, the returned variable must be used. using the Graphics.sprites... thing in the draw function won't work.
Re: Drawing an Image From The Resource Memory
Posted: Tue Jun 07, 2016 9:47 pm
by PixelPest
If it already has a custom graphic, why not just do:
Code: Select all
local img = Graphics.loadImage("block-1.png")
function onDraw()
Graphics.drawImag(img, x, y)
end
Re: Drawing an Image From The Resource Memory
Posted: Tue Jun 07, 2016 10:16 pm
by S1eth
PixelPest wrote:If it already has a custom graphic, why not just do:
Code: Select all
local img = Graphics.loadImage("block-1.png")
function onDraw()
Graphics.drawImag(img, x, y)
end
Sambo wrote:It does work, but only if I replace the sprite with a luaImageResource object first, which really defeats the whole purpose of this anyway.
Sambo wrote:defeats the whole purpose
Re: Drawing an Image From The Resource Memory
Posted: Tue Jun 07, 2016 10:18 pm
by PixelPest
S1eth wrote:PixelPest wrote:If it already has a custom graphic, why not just do:
Code: Select all
local img = Graphics.loadImage("block-1.png")
function onDraw()
Graphics.drawImag(img, x, y)
end
Sambo wrote:It does work, but only if I replace the sprite with a luaImageResource object first, which really defeats the whole purpose of this anyway.
Sambo wrote:defeats the whole purpose
I don't see how it defeats the whole purpose if it works
Re: Drawing an Image From The Resource Memory
Posted: Wed Jun 08, 2016 2:29 am
by Quantumenace
The point of the original post was that logically you should not have to load an image already in the game's memory a second time in order to draw it. I don't know whether this actually adds the full data to memory a second time or processes what's already there.
Also, if you want to load the default sprite, I don't know how you can use Graphics.loadImage to get an image from the default SMBX image folders. Maybe you can, but when I asked how to go up one level in the file path, I got no answer, so maybe you'd have to copy the original and put it in your level folder. Again, that should not be necessary.
Personally I want to be able to get the width and height of custom block images in the sprite array without having to load them a second time like this. It's supposed to compare the height to the original so blocks with extra frames will be animated automatically.
Re: Drawing an Image From The Resource Memory
Posted: Wed Jun 08, 2016 2:48 am
by Enjl
To go up one folder you put ..\\ when searching the file:
Graphics.loadImage("..\\butts\\file.png")
However you'll never need that if you want to grab from \\graphics.
Graphics.loadImage(Misc.resolveFile("graphics\\blocks\\block-1.gif")
However this is absolutely useless for graphics with mask because you can't apply the mask.