Game bug
Author |
Message |
vertdragon23
|
Posted: Tue Dec 17, 2013 6:26 pm Post subject: Game bug |
|
|
What is it you are trying to achieve?
<Fixing the bug where image streaks are left behind when you move character.>
What is the problem you are having?
<Image streaks appear after character moves.>
Describe what you have tried to solve this problem
<Coming to comp sci.>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Add your code here>
|
Please specify what version of Turing you are using
<4.1.1 (latest)>
Description: |
|
Download |
Filename: |
documents-export-2013-12-17.zip |
Filesize: |
104.97 KB |
Downloaded: |
72 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Dreadnought
|
Posted: Tue Dec 17, 2013 10:11 pm Post subject: Re: Game bug |
|
|
You are simply drawing the character in a new position each time you go through the loop which means that any part of the previous image of the character that you don't draw on is left behind (in this case, the edge of the feet).
The easiest way to avoid this problem is to redraw the entire screen on each frame, you could also use the sprite module.
|
|
|
|
|
|
vertdragon23
|
Posted: Tue Dec 17, 2013 10:45 pm Post subject: RE:Game bug |
|
|
I want to keep the Pic.Draw command because I was told its the smoothest way to do this. Can you explain how to redraw the entire screen each frame?
|
|
|
|
|
|
Raknarg
|
Posted: Tue Dec 17, 2013 10:50 pm Post subject: RE:Game bug |
|
|
Consider these two programs: How are they different?
|
|
|
|
|
|
vertdragon23
|
Posted: Tue Dec 17, 2013 10:52 pm Post subject: RE:Game bug |
|
|
hmm, interesting, the first one is supposedly the worse version of the second, which is proper, I presume the program is supposed to be a ball moving to the right. The second one has the cls which fixes the streak. But when I implement the cls in my code, it makes the screen flash uncontrollably.
|
|
|
|
|
|
Raknarg
|
Posted: Tue Dec 17, 2013 11:11 pm Post subject: RE:Game bug |
|
|
Yup. That is because your screen is showing you everything, every step of the way. You draw a ball on the screen, it shows up. You clear the screen, it turns the screen white. This repeats forever.
There is a thing called "Double Buffering". Imagine you had two windows. One of them would always be showing while the other is hiding. Whenever you draw something to the screen, you paint it onto the hiding one. Then, with a simple command, the panels switch, and now you get to see what you drew. You do this again with the next panel. You clear everything that was on it before, and you draw everything you want to, then switch. This way, the only thing you ever see is the finished product. Neat, huh?
In turing, you can change the screen mode like this:
This tells Turing that you're now in double buffered mode, and you only want it to update the screen when you call a certain command. This command is View.Update. Try this out:
Most languages do something like this automatically, I think. However for Turing, you have to do it manually.
|
|
|
|
|
|
vertdragon23
|
Posted: Tue Dec 17, 2013 11:19 pm Post subject: RE:Game bug |
|
|
I added the View.Update and offscreen, and going to the right works perfectly, but to the left and it just goes crazy!
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
right:=1
megamanx:=megamanx + 4
else right := 0
end if
if chars (KEY_LEFT_ARROW) then
left:=1
megamanx:=megamanx - 4
else left := 0
end if
level:=1
if left= 1 then
Pic.Draw (megamanreverse,megamanx,megamany,0)
View.Update
elsif right =1 then
Pic.Draw (megaman, megamanx, megamany, 0)
View.Update
delay (26)
cls
end if
end loop
|
|
|
|
|
|
Raknarg
|
Posted: Tue Dec 17, 2013 11:26 pm Post subject: RE:Game bug |
|
|
Protip: A lot of neophytes tend to use View.Update multiple times. Unless you have a very good reason for it, use View.Update delay cls only once in your loop.
The reason it's not working is probably because each if has a different kind of updating statement in it. Look closely.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
|
|