Inserting existing sprites and music from pico8

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
chillyskull
Prole
Posts: 9
Joined: Sun Jun 06, 2021 11:05 pm

Inserting existing sprites and music from pico8

Post by chillyskull »

Hey all,
I'm trying to move over my exported sprites, map (it combines them both into png). As well as my sound tracks. thanks!
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Inserting existing sprites and music from pico8

Post by MrFariator »

You can load the combined sprite sheet with love.graphics.newImage (or love.image.newImageData, and then pass that ImageData to newImage). From there, you can splice up the image into quads. Basically, each quad will define the region that you want to draw from an image - that you can draw as many times and wherever you please. Pico8 probably uses quads under the hood somewhere.

However, because you're taking a combined pico8 image into löve, I imagine you might have to define those quads manually in code for each individual little sprite or tile present in the sheet. Depending on your sprite sheet's size (namely, amount of tiles and sprites in them), this may be require varying amounts of work. It may be worth it to check if there's some tool that may help you automate that process, outputting a code file that defines the quads' positions and such automatically. For example, I personally use TexturePacker, but it works by taking individual images and combining them into a sheet + lua file - not by taking an already assembled image.

For audio, I'm not sure what kind of audio formats pico8 uses/outputs, but you can load .wav, .mp3 and .ogg files (and maybe more, haven't checked) with love.audio.newSource. Generally you might want to load sound effects as 'static', and any longer music tracks as 'stream'.
User avatar
zorg
Party member
Posts: 3435
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Inserting existing sprites and music from pico8

Post by zorg »

The pico-8 fandom page on exporting does say that sound effects and music are exported as wav files, so that's the simpler solution in that it can just be loaded by löve and played back.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
chillyskull
Prole
Posts: 9
Joined: Sun Jun 06, 2021 11:05 pm

Re: Inserting existing sprites and music from pico8

Post by chillyskull »

zorg wrote: Sun Jun 13, 2021 6:57 am The pico-8 fandom page on exporting does say that sound effects and music are exported as wav files, so that's the simpler solution in that it can just be loaded by löve and played back.
Yeah I've tried going that route, Whenever I try dragging and dropping the exported files into Atom it puts them in a new tab. I don't know how to link it to my main.lua tab. How do I remedy this?
User avatar
zorg
Party member
Posts: 3435
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Inserting existing sprites and music from pico8

Post by zorg »

chillyskull wrote: Mon Jul 19, 2021 12:57 am
zorg wrote: Sun Jun 13, 2021 6:57 am The pico-8 fandom page on exporting does say that sound effects and music are exported as wav files, so that's the simpler solution in that it can just be loaded by löve and played back.
Yeah I've tried going that route, Whenever I try dragging and dropping the exported files into Atom it puts them in a new tab. I don't know how to link it to my main.lua tab. How do I remedy this?
What do you mean by linking it to your main.lua tab? If you mean that you want the content of those files inside your main.lua, then i'd advise against it, if only because wav files are gigantic binary blobs that can just be next to your main.lua and be loaded in with love.audio.newSource instead.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
chillyskull
Prole
Posts: 9
Joined: Sun Jun 06, 2021 11:05 pm

Re: Inserting existing sprites and music from pico8

Post by chillyskull »

zorg wrote: Mon Jul 19, 2021 5:56 am
chillyskull wrote: Mon Jul 19, 2021 12:57 am
zorg wrote: Sun Jun 13, 2021 6:57 am The pico-8 fandom page on exporting does say that sound effects and music are exported as wav files, so that's the simpler solution in that it can just be loaded by löve and played back.
Yeah I've tried going that route, Whenever I try dragging and dropping the exported files into Atom it puts them in a new tab. I don't know how to link it to my main.lua tab. How do I remedy this?
What do you mean by linking it to your main.lua tab? If you mean that you want the content of those files inside your main.lua, then i'd advise against it, if only because wav files are gigantic binary blobs that can just be next to your main.lua and be loaded in with love.audio.newSource instead.
loaded in with love.audio.newSource? would i have to write that command for every instance of sfx? there's over 60 active tracks.
MrFariator
Party member
Posts: 509
Joined: Wed Oct 05, 2016 11:53 am

Re: Inserting existing sprites and music from pico8

Post by MrFariator »

LÖVE has no IDE, and Atom is a code editor - there is no drag and dropping files. As such, everything you really ever want to accomplish needs to be done through code. Loading graphics? Code. Loading Audio? Code. Any other data you might want to load? Yep, code.

So, in a simple case you'll write a line of code for every piece of sfx or music you might want to load:

Code: Select all

-- inside love.load, or any other place you might want
-- this assumes that the files are placed right next to main.lua, in the same folder
local sfx1 = love.audio.newSource( "sfx1.ogg", "static" )
local sfx2 = love.audio.newSource( "sfx2.ogg", "static" ) 

local bgm1 = love.audio.newSource ( "bgm1.ogg", "stream" )
-- etc
(the "static" defines that the audio file is decoded into memory at once, which is fine for sfx. For longer audio tracks like music, the "stream" option is generally recommended)

However, if you have a bunch of files, you can also write a simple for loop to enumerate through a folder's contents. Like, lets assume you create a folder named "sfx" next to your main.lua, you could use the following snippet:

Code: Select all

local files = love.filesystem.getDirectoryItems( "sfx" ) -- grabs and returns a table of files and subdirectories as strings
local sfx = {}
for i = 1, #files do
  sfx[files[i]] = love.audio.newSource ( "sfx/" .. files[i], "static" )
end
This then gives you a table that contains all your sound effects in the said sfx folder. After that loading has been done, you can play individual sound effects like:

Code: Select all

love.audio.play ( sfx["jump.ogg"] ) -- assuming there is a file named "jump.ogg" among the files we loaded earlier
You may want to trim the file extension from the file name as you save them into the sfx table, but I'll leave that up to you.
User avatar
chillyskull
Prole
Posts: 9
Joined: Sun Jun 06, 2021 11:05 pm

Re: Inserting existing sprites and music from pico8

Post by chillyskull »

MrFariator wrote: Tue Jul 20, 2021 5:21 am LÖVE has no IDE, and Atom is a code editor - there is no drag and dropping files. As such, everything you really ever want to accomplish needs to be done through code. Loading graphics? Code. Loading Audio? Code. Any other data you might want to load? Yep, code.

So, in a simple case you'll write a line of code for every piece of sfx or music you might want to load:

Code: Select all

-- inside love.load, or any other place you might want
-- this assumes that the files are placed right next to main.lua, in the same folder
local sfx1 = love.audio.newSource( "sfx1.ogg", "static" )
local sfx2 = love.audio.newSource( "sfx2.ogg", "static" ) 

local bgm1 = love.audio.newSource ( "bgm1.ogg", "stream" )
-- etc
(the "static" defines that the audio file is decoded into memory at once, which is fine for sfx. For longer audio tracks like music, the "stream" option is generally recommended)

However, if you have a bunch of files, you can also write a simple for loop to enumerate through a folder's contents. Like, lets assume you create a folder named "sfx" next to your main.lua, you could use the following snippet:

Code: Select all

local files = love.filesystem.getDirectoryItems( "sfx" ) -- grabs and returns a table of files and subdirectories as strings
local sfx = {}
for i = 1, #files do
  sfx[files[i]] = love.audio.newSource ( "sfx/" .. files[i], "static" )
end
This then gives you a table that contains all your sound effects in the said sfx folder. After that loading has been done, you can play individual sound effects like:

Code: Select all

love.audio.play ( sfx["jump.ogg"] ) -- assuming there is a file named "jump.ogg" among the files we loaded earlier
You may want to trim the file extension from the file name as you save them into the sfx table, but I'll leave that up to you.
Thank you for this, this is very helpful stuff, glad someone on here is very knowledgeable about Love AND Atom. I think I understand how to write this. It's so daunting writing in a slightly different language. I've been putting this off for a while. I can only imagine how hard it'll be to write API code in this down the line. I'll most likely will respond back on this when something doesn't load right.
Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests