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 :) enough introductions.. I am having trouble simply animating an Alien head sprite, here is my code:
function setup()
xPosition = 100
yPosition = 100
end
function update()
xPosition = xPosition +1
yPosition = yPosition + 1
end
function draw()
update()
sprite("NameOfSprite", xPosition, yPosition)
end
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..
@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.
It looks like you're new here. If you want to get involved, click one of these buttons!