Spritely to Dropbox

If any of you use the Spritely example program for images, here is a quick little program that saves an image made in Spritely to your Dropbox

--# Main
-- SpritelyToDropbox

-- Use this function to perform your initial setup
function setup()
    print("Hello World!")
    aloader = SpritelyLoader()
    -- Change "YourImageNameHere" to the name of your image
    Name = "YourImageNameHere"

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(40, 40, 50)

    -- This sets the line thickness

    -- Do your drawing here
    createImage = loadstring( readProjectData(Name))
    anImage = createImage() 
    saveImage("Dropbox:"..Name, anImage)
    -- Quits program as soon as image is saved


--# SpritelyLoader
SpritelyLoader = class()

-- SpriteLoader 
-- ver. 1.0
-- moves data from global to project storage
-- ====================

-- This class takes data from global and dumps it into your project.
-- To use this class, create an instance in your project.
-- For example:  aloader = SpritelyLoader()
-- This call will read both keys and images from the global Spritely
-- storage and copy them into your project space. 
-- Once in the project data, load the saved string to 
-- an image using it's key.  For example:
-- createImage = loadstring( readProjectData("bob"))
-- anImage = createImage() 

-- To display your images, you'll need to load them into
-- a sprite. The command looks like this

-- sprite(anImage, 100, 100, 32, 32)

-- Good luck!

function SpritelyLoader:init()
    local keys, k, s
    if readGlobalData("SpritelyKeys") == nil then
        print("No Spritely data found.")
        -- read global keys
        keys = readGlobalData("SpritelyKeys")
        saveProjectData("SpritelyKeys", keys)
        for k in string.gmatch(keys,"([^,]+)") do
            s = readGlobalData(k)
            saveProjectData(k, s)
        print("Move complete.")

Just change Name = “YourImageNameHere” to your image name and after running the program sync your Dropbox from within Codea

Also note, if you want it to save to documents just change saveImage(“Dropbox:”) to saveImage(“Documents:”)
The program is supposed to close as soon as the image is saved so do not be alarmed when it quits, the image should have been saved


@JakAttak, I am getting an error on line 23 string expected got nil. Do you know why. I have one Sprite saved in spritely.i had changed Dropbox to Documents on line 26

@Saurabh most likely you have forgotten to change the Name variable to the name of your image as it is in Spritely. (Line 10) If that is not it, I will have a look

@Saurabh, with no disrespect intended to the person who wrote Spritely (because it was one of his early projects), it stores images extremely inefficiently.

I think a better approach is to draw your image outside Codea on a mac or PC, then if you want to encode it (ie turn it into code so you don’t have to distribute separate images), I have some code to do that. For example, it would work with your archer, as well. It seems to compress about as well as jpeg.


here is the code


Thanks Ignatz. The first code by Jakattak worked well for me cause the problem I was facing is the archer in the balloon game, I made, had a white background, so I had to choose the background for the game as white(unless I used paint or photoshop to change the background colour.) my question is how can I get rid of the white background and only have the archer. How can i copy the output from your project(long tap doesn’t work). And one more question how did your project have two main,coder tabs spelled exactly the same way.

you need a paint program to remove the background. I use Paint.net, which is free (PC) and has a little wand tool. If you click this on the background it should select the archer’s outline, then pressing delete will delete the background. If any background is trapped inside the archer’s arm, you’ll have to click and delete in there, too. This isn’t guaranteed to give you a totally clean picture, there may still be traces of background, or maybe Paint.net will delete part of the arm by mistake!

Then you can use my program to embed it in your code if you want.

I agree that gist I gave you, is tricky to copy, for some reason. Hold to select something near the top left, then drag the little blue ball to the top left corner of the text box and it should select the whole thing.

I’ve only got one Main tab, but it has two labels at the top, that’s all.

Thanks ill try that.

Thanks to Ignatz. It works very well.

How do you copy the output (the encoded image) after you run the program @Ignatz I am not able to do it by long tapping it.

A short tap should be enough to copy it