Howdy, Stranger!

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

Tween trail problem

edited March 2013 in General Posts: 43

Hi! So i'm trying to make a sprite with simple tween animation...my code:

function setup()
    box = {x=100,y=100}
    dotween()
end

function draw()
    sprite("Cargo Bot:Command Grab", box.x,box.y)
end

function dotween()
    td=tween(2,box,{x=300,y=300})
    tween.sequence(td)
end

The problem is it leaves a trail behind the sprite... What am I doing wrong wrong?

Tagged:

Comments

  • Posts: 2,161

    Two things:

    1. Not enclosing your code in tildes (~~~) on the forum, and
    2. Not using background() to clear the canvas at the start of draw.
  • So that's what background does!

    1. I've wondered how to enclose code, but could not find it...it should be a sticky or in the sidebar since it's so common a mistake...
  • Posts: 2,161

    Re code: http://www.twolivesleft.com/Codea/Talk/discussion/275/faq-please-read

    You can think of background as a flood fill. It's also quite useful in setContext to blank the image to a given colour. The advantage of background over a large rect is that background(0,0,0,0) (note the alpha) sets every pixel to transparent black, where as the corresponding rect call does nothing due to the alpha.

    (One could simulate background using rect with the right blendMode, though.)

Sign In or Register to comment.