Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Animation + "button"
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
nflavour




PostPosted: Tue Jan 06, 2009 4:40 pm   Post subject: Animation + "button"

Hi!
I am working something for school, and i am doing a short animation, which is make a word flash and change colour.
The animation should go on forever until i click on a button.
But I use all the buttonwait, and mousewhere and stuff, they won't work, since the animation runs forever.
So, if i put the button before the animation loop, buttonwait, or mousewhere would stop.
If i put it in the loop, it will stop to wait for the button when i use buttonwait, and mousewhere would only respond once a while, as it takes time for the animation to run.
If i put it at the end, it won't get the buttons, becuase the loop never ends.
I try to use GUI, but i can't exit the animation loop with it...
Anyone got any idea on how i should do the animation and the button together?
or Do I have to delete the animation for the button to work.
Here is my animation code
Turing:

var tcolor:int:=0
var height:int:=130
const STRING:="SOMETHING"
const FONT:=Font.New ("Arial:13:bold")
const DELAY:=150
loop
   tcolor += 1
    for i : 1 .. length (STRING)
        Font.Draw (STRING (i), 610, height, FONT, tcolor)
        delay (DELAY)
        height -= 15
    end for
    height := 130
    for i : 1 .. length (STRING)
        Font.Draw (STRING (i), 610, height, FONT, 0)
        height -= 15
    end for
    height := 130
    if tcolor = 255 then
        tcolor := 0
    end if
end loop
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue Jan 06, 2009 4:51 pm   Post subject: RE:Animation + "button"

use a single loop (no for-loops), Mouse.Where, and no delays. You want Mouse.Where to run together with the animation in the same loop, but it's not going to work during the delays.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
nflavour




PostPosted: Tue Jan 06, 2009 6:17 pm   Post subject: Re: RE:Animation + "button"

Tony @ Tue Jan 06, 2009 4:51 pm wrote:
use a single loop (no for-loops), Mouse.Where, and no delays. You want Mouse.Where to run together with the animation in the same loop, but it's not going to work during the delays.

Well, is there a way for me to not change the loops or the delays and have a working button?
This is the best i can do:
Turing:

var tcolor : int := 1
var height : int := 130
var i : int := 1
const STRING := "SOMETHING"
const FONT := Font.New ("Arial:13:bold")
const DELAY := 150
var x, y, button : int
Draw.FillBox (150, 150, 200, 200, black)
loop
    if height = 130 - 15 * length (STRING) then
        height := 130
    end if
    if tcolor > 255 then
        tcolor := 1
    end if
    if i > length (STRING) then
        i := 1
    end if
    Font.Draw (STRING (i), 610, height, FONT, tcolor)
    delay (100)
    i += 1
    height -= 15
    tcolor += 1
    Mouse.Where (x, y, button)
    exit when x > 150 and x < 200 and y > 150 and y < 200 and button = 1
end loop


i made the delay less, and check Mousewhere everytime it runs, since it doesn't have a for loop. But sometimes it would work, cuz it miss the moment when it does the Mouse.Where
TheGuardian001




PostPosted: Tue Jan 06, 2009 6:31 pm   Post subject: Re: Animation + "button"

you really shouldn't have a delay if you want this to work. The problem with having a delay is that the user is still able to click the mouse while the program is waiting, and the click won't be registered.
If you need the delay due to flickering, I would advise you to look into View.Update and "offscreenonly" mode for View.Set, although I'm not sure that would work since you draw each letter individually... it would probably screw that up
nflavour




PostPosted: Tue Jan 06, 2009 6:53 pm   Post subject: Re: Animation + "button"

TheGuardian001 @ Tue Jan 06, 2009 6:31 pm wrote:
you really shouldn't have a delay if you want this to work. The problem with having a delay is that the user is still able to click the mouse while the program is waiting, and the click won't be registered.
If you need the delay due to flickering, I would advise you to look into View.Update and "offscreenonly" mode for View.Set, although I'm not sure that would work since you draw each letter individually... it would probably screw that up

Is there a way to do my animation without drawing each letter individually then?
andrew.




PostPosted: Tue Jan 06, 2009 9:19 pm   Post subject: RE:Animation + "button"

If you want to do it with a delay without using the command "delay (DELAY", you could check the time and mod it by 100 (your delay).

e.g. Instead of putting:
code:
Font.Draw (whatever)
delay (150)

You can put something along the lines of:
code:
if Time.Elapsed mod 150 = 0 then
    Font.Draw (whatever)
end if


What this does is that it checks how long the program has been running for in milliseconds and modulus it by 150 (divide it and return the remainder). If the time modulus 150 is 0, meaning it divides into 150 evenly, then it will do Font.Draw (whatever).
Tony




PostPosted: Tue Jan 06, 2009 9:24 pm   Post subject: RE:Animation + "button"

instead of
code:

delay (100)
i += 1

you could use
code:

delay(1)
i += 0.01
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Tony




PostPosted: Tue Jan 06, 2009 9:27 pm   Post subject: Re: RE:Animation + "button"

andrew. @ Tue Jan 06, 2009 9:19 pm wrote:
running for in milliseconds and modulus it by 150

you are expecting that line to be executed during an exact millisecond, which might not always be the case.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: