Sprite pack renaming

Hi! I have always thought you should be able to code ON the device so I look for IDEs on every gadget I buy. Back in the iPod days, I found out Apple didn’t allow it. I have an Android phone which has an app called AIDE on it, which lets you code in exactly the same way as you would on a PC set up with Eclipse. So I get an iPad and I was surprised to find … This! And it’s not a clunky “have a server run code and stream it” work-around, it’s the real thing! And I needed to learn Lua anyway! I’m so happy that I found Codea.

Anyway, that little anecdote aside … Is there any way to change the names of sprites I saved in the Documents sprite pack? I imported a whole bunch from a sprite app I have, and I skipped the 37th of 68. Rather than renaming them all, I do a trick in my for loop to import them to the program in the right order. It looks horribly messy but it works!

The reason why the order matters is I use the sprite app to create the map array too. I’m already swapping the row order (because most drawing programs make 0,0 on top left).

The code works, it’s just messy. All I’d need to do to fix it is rename the images in docs. I tried clicking on the document window in various ways. I’m a little lost without the android menu button that I’m so used to. Apple apps seem to always have these secret ways to change settings and stuff. I was hoping I just haven’t figured out how to do it yet.

Renaming an image is a feature we should definitely have, I hadn’t actually considered it before. If you could add it as a feature request to the Issue Tracker (link at the top), it would be greatly appreciated.

For now, here is a way to create your own image rename function:

function moveImage( fromName, toName )
    -- Note, this always overwrites the destination
    -- be careful!

    -- Read the image at fromName
    local img = readImage( fromName )

    -- Save or overwrite toName with this image
    saveImage( toName, img )
    
    -- Delete the original image (fromName)
    saveImage( fromName, nil )
end
```


You can use this like so:

moveImage( "Documents:Circle", "Documents:CircleNewName" )
```


Edit: Here's a version with a parameter to overwrite or not if the destination exists

function moveImage( fromName, toName, allowOverwrite )
    -- Read destination to check if it exists
    local dest = readImage( toName )

    if dest == nil or allowOverwrite then
        -- Read the image at fromName
        local img = readImage( fromName )

        -- Save or overwrite toName with this image
        saveImage( toName, img )
    
        -- Delete the original image (fromName)
        saveImage( fromName, nil )
    else
        print( "moveImage failed: image exists at destination '"..toName.."'" )
    end
end

```

So I run this once inside my project and suddenly all the images get renamed? You know how odd it is to run a program which changes its own environment?

But cool, since I have to rename like 39 images that will be faster than doing it in a UI anyway. I’ll do that and add the feature request too.

I have another question. I’m writing the tiles to the screen, and I set up a zoom slider (1x to 4x).

Screen shot is at:
https://docs.google.com/open?id=0B3AKtexx9J-ybUF5U2o4NFhEYWM

It was really easy to set up, but it doesn’t stitch the images together on screen like you’d expect. There are artifacts in between the tiles as you can see in the picture.

The key draw line is:

sprite(images[grid[j+1][i+1]],gsX+(i-gsI)*sz,gsY+(j-gsJ)*sz,sz,sz)

So it’s a long line because I do the scale and the touch/drag offset myself. Images are 32 pixels as a 16 retina image, but it also does it with actual 16 pixel and 32 pixel images. It does it before I drag the map around. It does it from 2x to 4x.

gsX,gsY is the start location of the draw (set b offset, which is accumulated from touch.delta)
gsI,gsJ are the locations in the array for the draw start, so the window gets clipped
geI,geJ are the end locations in the array
sz is the image size, so it’s 16 for 1x scale, 32, 48, and 64.

I’m wondering if I need to figure out the camera controls like in the 3D example code instead of using the slider that I set up.

This is only for play so it’s not a big deal if there are artifacts. Just a wee bit frustrating.

Try using noSmooth() before rendering your sprites. By default, scaled sprites are rendered using bilinear interpolation, this softens them as they scale up or down (rather than allowing them to pixellate) but can cause edges to appear slightly misaligned.

Failing that (or if you do want smooth interpolation) you could add them into a mesh and slightly inset the texture coordinates by half a pixel. This is a much more advanced technique though.

Brilliant! Thanks. I vaguely remember reading that when I started learning. Old school RPGs need no steenkin anti-alias anyway.

That completely fixed the draw issue.