Simple animation of a sprite.. help?
  • Code_PhoxCode_Phox February 14

    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..

  • Ipad41001Ipad41001 February 14

    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.

  • Code_PhoxCode_Phox February 14

    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?

  • Ipad41001Ipad41001 February 14

    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.

  • ruilovruilov February 14

    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

  • SimeonSimeon February 15

    @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.

  • BortelsBortels February 17

    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.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with OpenID Sign In with Google

Sign In Apply for Membership

In this Discussion

Tagged