Drawing an Image From The Resource Memory

This is the place for discussion and support for LunaLua and related modifications and libraries.
Forum rules
Before you make a topic/post, consider the following:
-Is there a topic for this already?
-Is your post on topic/appropriate?
-Are you posting in the right forum/following the forum rules?
User avatar
Sambo
Blooper
Blooper
Posts: 189
Joined: Fri Jan 24, 2014 6:43 pm
Current Project: SMBX2, Mario & the 7 Orbs

Drawing an Image From The Resource Memory

Postby Sambo » Mon Jun 06, 2016 5:33 pm

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.

S1eth
Spiny
Spiny
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Drawing an Image From The Resource Memory

Postby S1eth » Mon Jun 06, 2016 5:55 pm

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

User avatar
Sambo
Blooper
Blooper
Posts: 189
Joined: Fri Jan 24, 2014 6:43 pm
Current Project: SMBX2, Mario & the 7 Orbs

Re: Drawing an Image From The Resource Memory

Postby Sambo » Tue Jun 07, 2016 12:48 am

Are you sure this works? Because, I tried this and got a "No matching overload" error every time, with every drawing function.

User avatar
Quantumenace
Ripper II
Ripper II
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Drawing an Image From The Resource Memory

Postby Quantumenace » Tue Jun 07, 2016 1:04 am

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.

User avatar
Sambo
Blooper
Blooper
Posts: 189
Joined: Fri Jan 24, 2014 6:43 pm
Current Project: SMBX2, Mario & the 7 Orbs

Re: Drawing an Image From The Resource Memory

Postby Sambo » Tue Jun 07, 2016 5:01 pm

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.

PixelPest
Link
Link
Posts: 7116
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Drawing an Image From The Resource Memory

Postby PixelPest » Tue Jun 07, 2016 9:47 pm

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 

S1eth
Spiny
Spiny
Posts: 54
Joined: Sat Apr 23, 2016 10:44 am

Re: Drawing an Image From The Resource Memory

Postby S1eth » Tue Jun 07, 2016 10:16 pm

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

PixelPest
Link
Link
Posts: 7116
Joined: Sun Jul 12, 2015 5:38 pm
Flair: Tamer of Boom Booms
Current Project: Boom Boom Evolution
Chat Username: PixelPest
Contact:

Re: Drawing an Image From The Resource Memory

Postby PixelPest » Tue Jun 07, 2016 10:18 pm

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

User avatar
Quantumenace
Ripper II
Ripper II
Posts: 308
Joined: Mon Dec 28, 2015 2:17 am

Re: Drawing an Image From The Resource Memory

Postby Quantumenace » Wed Jun 08, 2016 2:29 am

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.

Enjl
Cute Yoshi Egg
Cute Yoshi Egg
Posts: 8425
Joined: Mon Jan 20, 2014 12:58 pm
Flair: Orphion Egamalenitar Osmos IV, Esq.

Re: Drawing an Image From The Resource Memory

Postby Enjl » Wed Jun 08, 2016 2:48 am

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.
The ABC of Creation
________________________________________________________
Image


Return to “LunaLua”

Who is online

Users browsing this forum: No registered users and 4 guests