4 Replies Latest reply on Jan 10, 2008 7:56 AM by gtrufitt

# Tweening with lingo

Hi,

I have a sprite that I need to tween from one location to another but I am not sure how to do it, below is the lingo that I have used but this causes the sprite to jump from one location to the needed location without tweening smoothly. Is there a way to tween it smoothly with lingo or would I have to find another way?

if (_key.keyPressed(126)) then
repeat while (timmy.locV > 337)
timmy.locV = timmy.locV - 1
end repeat
end if
end

Thanks, Gareth

Also - How do you write an if.. then statement that does

if(condition) AND (condition) AND (condition) then

So that something is done if all conditions are met?

Thanks,

Gareth
• ###### 1. Re: Tweening with lingo
Just let it happen in the normal flow of Director's events:

on enterFrame
if (_key.keyPressed(126)) then
if (timmy.locV > 337) then
timmy.locV = timmy.locV - 1
end if
end if
end enterFrame

Andrew

• ###### 2. Re: Tweening with lingo
quote:

Originally posted by: gtrufitt
Hi,

I have a sprite that I need to tween from one location to another but I am not sure how to do it, below is the lingo that I have used but this causes the sprite to jump from one location to the needed location without tweening smoothly. Is there a way to tween it smoothly with lingo or would I have to find another way?

if (_key.keyPressed(126)) then
repeat while (timmy.locV > 337)
timmy.locV = timmy.locV - 1
end repeat
end if
end

Also - How do you write an if.. then statement that does
if(condition) AND (condition) AND (condition) then

So that something is done if all conditions are met?

Here's a good link on tweening:
http://www.jmckell.com/parametric.html
start there and read on for some really good information and examples

As for your second question; you actually answered it yourself, ie:
if (condition) AND (condition) AND (condition) then
-- code here
end if
-- that's exactly the syntax of it.
• ###### 3. Re: Tweening with lingo
Hi

The following code wont really work:

repeat while (timmy.locV > 337)
timmy.locV = timmy.locV - 1
end repeat

because inside the repeat loop, Director will not update the image buffer meaning that you wont see the animation. Either (a) put an updateStage call inside the repeat loop or (b) animate on enterframe or some other time-based event (such as Andrew's approach)

Another trick to remember is to not use simple 1-px linear tweens but include some 'easing' - for example see lingoworkshop.com/downloads/examp74.dir

-- Luke
• ###### 4. Re: Tweening with lingo
Cheers for the help guys, i'll give it a go

-Gareth