Fantastic work Mark. I love that you put sound effects in for painting, and that you seem to have built the UI icons in your own editor, nice touch
Regarding getting the data back out of the editor, there’s a new, undocumented function in 1.2 you can use to make this awesome.
loadstring() will let you execute a chunk of Lua code. So you can do the following instead of printing the text to the output window.
Store the image creation code as a big string using the custom data storage. Do the following: saveProjectData( “SpritelyData”, “lots of image code as a string” )
The “lots of image code as a string” data would look something like this:
local spritely = image( 16, 16 )
spritely:set( 1, 4, 244, 100, 16 )
spritely:set( 2, 4, 244, 100, 16 )
spritely:set( 3, 4, 244, 100, 16 )
spritely:set( 4, 4, 244, 100, 16 )
-- ... and so on
- In order to create an image from this saved data, all the user has to do is the following:
createImage = loadstring( readProjectData("SpritelyData") )
myImage = createImage() -- executes the above code
sprite( myImage, x, y ) -- render image
- Bonus points if you can allow the user to customise the name that spritely saves the data under (instead of “SpritelyData”). The user can have a quick way to create images from Spritely’s saved data.
Note: sprite editing is actually a feature I’ve wanted to add to Codea for a long time, and still might add.
One way to allow the user to store the data under their own key could be to do the following, print something like this to the output window:
-- Copy this data into your own sprite with the following code
saveProjectData( "YOUR SPRITE NAME", readProjectData( "SpritelyData" ) )
-- Load your new sprite into an image
-- (Note the function call braces at the end of the line)
myImage = loadstring( readProjectData( "YOUR SPRITE NAME" ) ) ()