Computer Science Canada Pic.New doesn't work |
Author: | who cares? [ Sun Jul 06, 2003 4:49 pm ] |
Post subject: | Pic.New doesn't work |
Hello, I am trying to make a Pong game, and I am trying to use the Pic. New command in order to take a picture of the place where the ball is going to be, before it gets there and then paste it after the ball passes the place, so that I get a smooth motion, without having to clear the screen every time the ball moves. The problem is that when I use the Pic.New command, I get the message "Illegal pictured ID number '0'. (Probable cause: picture was not succesfully created.)." Here is my program: ----------------------------------------------- setscreen ("graphics") var x, y : int var xchange, ychange : int var pic1 : int x := 0 y := 0 xchange := 1 ychange := 1 Draw.FillBox (0, 0, maxx, maxy, black) loop if x > 639 then xchange := -xchange elsif x < 0 then xchange := -xchange end if if y > 399 then ychange := -ychange elsif y < 0 then ychange := -ychange end if x := x + xchange y := y + ychange pic1 := Pic.New (x - 4, y - 4, x + 4, y + 4) Draw.FillBox (x - 4, y - 4, x + 4, y + 4, white) Pic.Draw (pic1, x, y, picCopy) delay (5) end loop ----------------------------------------------- Any help would be appreciated. Thank you very much. |
Author: | krishon [ Sun Jul 06, 2003 5:14 pm ] |
Post subject: | |
which version of turing are u using? that might be the problem, tho i doubt it |
Author: | who cares? [ Sun Jul 06, 2003 5:22 pm ] |
Post subject: | I'm using... |
I'm using version 4.0.4 c of Turing. I have the latest updates installed. |
Author: | Asok [ Sun Jul 06, 2003 5:26 pm ] |
Post subject: | |
k Pic.New shouldn't be in the loop, because the picture is a constant. only the location (Pic.Draw) changes. The whole thing needs to be restructured. Store the pic then draw it. |
Author: | krishon [ Sun Jul 06, 2003 5:28 pm ] |
Post subject: | |
maybe it'll help if u put a procedure...i dunno if its necessary tho |
Author: | Tony [ Sun Jul 06, 2003 5:48 pm ] |
Post subject: | |
might be faster if you keep the whole background in the memory, this way you dont have to use Pic.New inside the loop and should also speed up your game. |
Author: | PaddyLong [ Sun Jul 06, 2003 5:50 pm ] | ||
Post subject: | |||
well unless you are going to have something in the background other than just black, it would likely be easier to simply draw a small black box over it rather than using Pic any way... here is what you want if you want to use the Pic method (also note I started the ball at 10,10 rather than 0,0 this is because you are trying to take a pic at x - 4 and y - 4 so it would be trying to take a pic from -4,-4 to 4,4) I also modified your if statements for changing the directions so that they'll work better and also commented the stuff for the drawing/erasing so hopefully you can understand what is going on with it
|
Author: | PaddyLong [ Sun Jul 06, 2003 5:56 pm ] | ||
Post subject: | |||
also, if you want it to run smoother add in setscreen("offscreenonly") and after
but before the delay put in View.Update this will elminate the small flickering of the ball that you notice |
Author: | AsianSensation [ Sun Jul 06, 2003 7:40 pm ] |
Post subject: | |
doesn't turing only allow so many pics to be declared? then if you declare it in a loop, then it's going to run out of space, and you get an error that way... |
Author: | who cares? [ Sun Jul 06, 2003 8:20 pm ] |
Post subject: | Thank you |
Thank you all for your help. I have found a way to do it, but your code is better. Thank you for it. Oh well, I am just a begginer in Turing. Thank you all for your help. |
Author: | PaddyLong [ Sun Jul 06, 2003 10:17 pm ] |
Post subject: | |
yes Asian, that's why the Pic.Free is there |
Author: | AsianSensation [ Mon Jul 07, 2003 8:26 am ] |
Post subject: | |
oh, heh heh, didn't see it.... oh well, sorry about that |