Animation
Author |
Message |
cycro1234
|
Posted: Sun Jan 16, 2005 7:02 pm Post subject: Animation |
|
|
I'm trying to animate a ball that falls down, but it gets erased at the very end. How do I fix this?
code: | procedure dropBall (x : int)
for decreasing y : 470 .. 70 by 70
if whatdotcolour (x, y) not= 12 then
drawfilloval (x, y, 23, 23, brightred)
View.Update
delay (200)
drawfilloval (x, y, 24, 24, 43)
drawoval (x, y, 24, 24, black)
end if
end for
end dropBall |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Cervantes
|
Posted: Sun Jan 16, 2005 7:16 pm Post subject: (No subject) |
|
|
It's not that it gets erased at the end, it just doesn't get drawn. Try changing the second bounds of the for loop from 70 to 0.
Here's your program, only with easier customization
code: |
procedure dropBall (x, topY, bottomY, spacing, totalTime : int)
const timeForEach := round (totalTime / ((topY - bottomY) / spacing))
for decreasing y : topY .. bottomY by spacing
if whatdotcolour (x, y) not= 12 then
drawfilloval (x, y, 23, 23, brightred)
View.Update
delay (timeForEach)
drawfilloval (x, y, 24, 24, 43)
drawoval (x, y, 24, 24, black)
end if
end for
end dropBall
dropBall (maxx div 2, maxy, 0, 10, 750)
|
|
|
|
|
|
|
cycro1234
|
Posted: Sun Jan 16, 2005 7:26 pm Post subject: (No subject) |
|
|
Easier customization? It seems a LOT more complicated than mine was It seems as if my code draws a red circle then erases it by drawing an orange one on top, then draws a red circle under the previous, then erases it again, and so on. The last circle gets drawn, then immediately gets erased. I dont want it to get erased. |
|
|
|
|
|
Cervantes
|
Posted: Sun Jan 16, 2005 7:37 pm Post subject: (No subject) |
|
|
Oh, I get it. Well, having just copied and pasted the code into Turing and not really thinking I skipped over the fact that my run window was set to nooffscreenonly. Try adding a View.Update at the very end of your procedure (after the end for). Mind you, all that does is make the last circle turn orange, as all the others have, instead of staying red.
I don't think the circle can get drawn then erased, given the code tat you posted. It must be something outside of that procedure. |
|
|
|
|
|
cycro1234
|
Posted: Sun Jan 16, 2005 8:10 pm Post subject: (No subject) |
|
|
Thx for the help. I have another question though. I want to program some AI for my game, and to do a check to see if there are 4 of one colour in a row, diagonaly, etc. How would I check to see if there are 4 pieces connected? Could I use a whatdotcolour around a piece to check if there is one of the same nearby, then do a whatdotcolour on that piece and so on? Or is there an alternate method? |
|
|
|
|
|
Cervantes
|
Posted: Sun Jan 16, 2005 8:30 pm Post subject: (No subject) |
|
|
Whatdotcolour? I would advise going with number comparisons. I'm sure you could come up with a recursive function to find four in a row. Unfortunately, I probably won't be of much help there. |
|
|
|
|
|
cycro1234
|
Posted: Sun Jan 16, 2005 8:32 pm Post subject: (No subject) |
|
|
Thanks a lot for your help. If anybody else has any ideas on how I could fix my code from my first post, I'd appreciate it! |
|
|
|
|
|
|
|