Computer Science Canada Running once... In a loop? |
Author: | Grim [ Thu Oct 21, 2010 7:22 pm ] | ||
Post subject: | Running once... In a loop? | ||
What is it you are trying to achieve? I'm trying to create a game using Pac-Man. I am using whatdotcolour for collision detection, but because that code has to be in the same loop as my draw commands, I am re-drawing my background every time, causing an annoying flicker. Describe what you have tried to solve this problem Nested loop, Nested for loop, nested decreasing for loop, placing draw command outside loop Here's the code...
Any possible way of making that draw command run only once? |
Author: | DanShadow [ Thu Oct 21, 2010 8:09 pm ] |
Post subject: | RE:Running once... In a loop? |
If flickering is your issue, using: View.Set ("graphics,offscreenonly") should fix your problem. Alternatively, you can draw your background outside your loop, and every time pacman moves you can redraw a portion of the background where pacman used to be (before he moved). Im guessing the background would be black, so pretty easily done. View.Set("graphics,offscreenonly") is probably a lot easier though. |
Author: | Grim [ Thu Oct 21, 2010 8:48 pm ] | ||
Post subject: | Re: Running once... In a loop? | ||
I'll post the whole program. The flickering is caused because every time my loop runs, it re-draws the background. Perhaps this will show you what I mean.
I know processes are a no-no around here, but this seemed the easiest way to do it at the time. |
Author: | TheGuardian001 [ Thu Oct 21, 2010 9:12 pm ] | ||
Post subject: | Re: Running once... In a loop? | ||
Grim @ Thu Oct 21, 2010 8:48 pm wrote: I know processes are a no-no around here, but this seemed the easiest way to do it at the time. It's not. Processes will basically guarantee flickering, even if you use View.Set("offscreenonly"), which you should be using. Your layout should look something like this:
|
Author: | Grim [ Thu Oct 21, 2010 9:34 pm ] |
Post subject: | RE:Running once... In a loop? |
Using View.Update, I can't actually get Pac-Man to move. I get the drawing but nothing else. |
Author: | TheGuardian001 [ Thu Oct 21, 2010 9:38 pm ] |
Post subject: | Re: RE:Running once... In a loop? |
Grim @ Thu Oct 21, 2010 9:34 pm wrote: Using View.Update, I can't actually get Pac-Man to move. I get the drawing but nothing else.
1)Are you still using processes 2)Do you have both View.Set("offscreenonly") and View.Update? You need both. |
Author: | Grim [ Thu Oct 21, 2010 9:50 pm ] | ||
Post subject: | Re: RE:Running once... In a loop? | ||
TheGuardian001 @ 21/10/2010, 21:38 wrote: Grim @ Thu Oct 21, 2010 9:34 pm wrote: Using View.Update, I can't actually get Pac-Man to move. I get the drawing but nothing else.
1)Are you still using processes 2)Do you have both View.Set("offscreenonly") and View.Update? You need both. Yes, using offscreenonly and View.Update, no processes. Here.
Presumably, I could put View.Update at the end of each procedure, but even that doesn't work. |
Author: | TheGuardian001 [ Thu Oct 21, 2010 10:52 pm ] | ||||
Post subject: | Re: Running once... In a loop? | ||||
Let's take a look at the order you're drawing in:
You need to rearrange it so that Pac-Man is drawn last (since he's on top) and isn't erased before you update.
Erasing Pac-man is not actually required, since you draw a while box the size of the screen each loop anyway. |