Simple animation of a sprite.. help?

Although I am not new to programming in C++ and Java, I am new to both Lua and programming video games… I would like my career to be in game design, so this is a good place to start :slight_smile: enough introductions…
I am having trouble simply animating an Alien head sprite, here is my code:

function setup()
xPosition = 100
yPosition = 100
function update()
xPosition = xPosition +1
yPosition = yPosition + 1
function draw()
sprite(“NameOfSprite”, xPosition, yPosition)

Currently, I am only creating new sprites at a slightly different spot. How do i delete the previous sprite?
I’ve been looking around and cant find anything…

background() with some values is the simplest way. Typically like background(0,0,0,255). If background() isn’t good for what you’d like to do, I’d have to understand that before offering an alternative.

It worked! but does that just create a new background over everything? So it basically just covers the previous sprite up? Would that eventually cause things to slow down due to memory?

Without “RETAINED” they draw everything every frame and their intial release didn’t have that. They could answer to the technical details but they began their app assuming redrawing every frame.

It can eventually slow down, but you can use meshes (it’s in one of the examples that comes with codea) for more direct access to the graphics card, and then you’d have to be drawing thousands of sprites per frame before performance is really affected

@Code_Phox the sprite() function doesn’t actually “create” a new sprite. It just draws it once.

Drawing the background() at the start of the draw call doesn’t keep all the old sprites in memory — they are already gone (though their images may still be on the screen). The background() just replaces the contents of the screen buffer with a solid colour.

Hope this explains things.

Think of sprite() as a “stamp”. You have to redraw everything every frame, as if you were making a stop-motion movie.

So - first you clear the screen, then you stamp your sprites, then you repeat that over and over. To animate a sprite, you change where you draw it each frame.

I too am new to Codea and this topic really helped. Thanks to all for their insight!!