Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
manage objects automatically
#6
(11-12-2023, 09:58 PM)aliensoldier Wrote: A question about the image_manager functions, I don't know exactly how useful this is, but it occurred to me that I could create a function that cycles through the images that are in the "assets" folder and then loads it into the "loadimage" function, and then make the function return that value to use it in the objects.

How could you create that images function, and the other question is if it is mandatory to free the memory of the loaded images because I am seeing the freeimages function to delete those images but I don't see it being used.

I've rewritten LoadAssets so that it loads all png files it can find in the assets folder.

Code:
function LoadAssets()
    ' Load images using LoadImage from image_manager. We can use GetImage in our other files to
    ' access these images.
    files = GetFiles("assets")
    foreach f in files
        ' Only load png files. The image manager automatically adds "assets/" to the path, and
        ' GetFiles returns filenames that include "assets/", so use GetFilename to remove everything
        ' but the filename (and the extension, ".png", if the second parameter is true).
        if lower(mid(f, len(f) - 4, 4)) = ".png"  LoadImage(GetFilename(f, true))
    next
endfunc

You have to add:

Code:
include "file.n7"

at the beginning of the_shooter.n7 to use the functions GetFiles and GetFilename. This library comes with n7 (it's in the N7/lib folder, so your program can always find it), but I haven't documented it.

Edit: I wrote image_manager.n7 because it was the "simplest" way of sharing image resources between multiple source code files. The FreeImages function is pretty pointless, all resources are released when the program terminates.
Reply


Messages In This Thread
manage objects automatically - by aliensoldier - 11-11-2023, 07:01 PM
RE: manage objects automatically - by Marcus - 11-11-2023, 09:46 PM
RE: manage objects automatically - by Marcus - 11-12-2023, 09:10 AM
RE: manage objects automatically - by Marcus - 11-13-2023, 02:57 PM
RE: manage objects automatically - by Marcus - 11-14-2023, 04:30 PM
RE: manage objects automatically - by Marcus - 11-16-2023, 04:13 PM
RE: manage objects automatically - by Marcus - 11-14-2023, 07:47 PM
RE: manage objects automatically - by Marcus - 12-09-2023, 09:28 PM
RE: manage objects automatically - by Marcus - 12-18-2023, 04:08 PM
RE: manage objects automatically - by Marcus - 12-18-2023, 05:11 PM
RE: manage objects automatically - by Marcus - 01-18-2024, 04:49 PM

Forum Jump:


Users browsing this thread: 5 Guest(s)