Board index » delphi » Sprite Corruption!!!

Sprite Corruption!!!

I have been working on a little sprite routine for a while now, and have
gotten a LOT of very helpful responses :-)  

I just came across the worst error yet, you'll see what I mean when you run
the following bit of code:

------------------------------------------------------------------------------------------------------------------
uses CRT,GRAPH;

CONST
                Circle : array[1..8,1..8] of byte =
             ((0,15,15,15,15,15,15,0),
             (15,0,0,0,0,0,0,15),
             (15,0,0,0,0,0,0,15),
             (15,0,0,0,0,0,0,15),
             (15,0,0,0,0,0,0,15),
             (15,0,0,0,0,0,0,15),
             (15,0,0,0,0,0,0,15),
             (0,15,15,15,15,15,15,0));
VAR
            x,y,x1,y1,gd,gm:integer;
            b,pointer;
            k:char;

begin
x1:=300;
y1:=90;
gd:=detect;
initgraph (gd,gm,'c:\tp');
if graphresult<>grOK then halt (1);
for y:=1 to 8 do begin
for x:=1 to 8 do begin
if circle[x,y]<>0 then PutPixel (y,x,Circle[x,y]);
end;
end;

getimage (0,0,8,8,B);
clearviewport;
repeat;
putimage (x1,y1,B,NormalPut);
if keypressed then k:=readkey;
if k='2' then inc (y1);
until 1=2;
readln;
end;

-------------------------------------------------------------------------------------------------------------------
(sorry for the bad indentation, my net software uses proportional fonts.)

Ok, you'll see a white circle against a black screen. Now press '5'.
Notice the weird grey lines above the top of the image!! How can I get rid
of this!!

This is especially apparent when there is more than one pointer in the VAR
list. You can hit '2' to move the image down to make the corruption more
apparent. What causes this, and how can I fix it?  I have tried everything
I know to no avail.

Quick question, can I GetImage on the same bitmap twice under different
pointers? When I try, the first image is totally messed up, but the 2nd one
is just fine.

Thanks!
<cg...@hooked.net>

 

Re:Sprite Corruption!!!


In article <4o8fqe$...@fish.hooked.net>, cg...@fish.hooked.net (Charles

Quote
McDonald) wrote:
> I have been working on a little sprite routine for a while now, and have
> gotten a LOT of very helpful responses :-)  

> I just came across the worst error yet, you'll see what I mean when you run
> the following bit of code:

the problem is you are not allocating memory for the getimage to store to
so it's overwriting something(obviously not important otherwise you would
get a crash) but then the program is overwriting the sprite because it
thinks the memory is avaliable.

------------------------------------------------------------------------------------------------------------------

Quote
> uses CRT,GRAPH;

> CONST
>                 Circle : array[1..8,1..8] of byte =
>              ((0,15,15,15,15,15,15,0),
>              (15,0,0,0,0,0,0,15),
>              (15,0,0,0,0,0,0,15),
>              (15,0,0,0,0,0,0,15),
>              (15,0,0,0,0,0,0,15),
>              (15,0,0,0,0,0,0,15),
>              (15,0,0,0,0,0,0,15),
>              (0,15,15,15,15,15,15,0));
> VAR
>             x,y,x1,y1,gd,gm:integer;
>             b:pointer;
>             k:char;

->              temp:word;

Quote

> begin
> x1:=300;
> y1:=90;
> gd:=detect;
> initgraph (gd,gm,'c:\tp');
> if graphresult<>grOK then halt (1);
> for y:=1 to 8 do begin
> for x:=1 to 8 do begin
> if circle[x,y]<>0 then PutPixel (y,x,Circle[x,y]);
> end;
> end;

->temp := size(0,0,8,8);
->getmem(b,temp);

Quote
> getimage (0,0,8,8,B);
> clearviewport;
> repeat;
> putimage (x1,y1,B,NormalPut);
> if keypressed then k:=readkey;
> if k='2' then inc (y1);
> until 1=2;
> readln;
> end;

-------------------------------------------------------------------------------------------------------------------

there you go that should work.

Quote
> Thanks!
> <cg...@hooked.net>

Bevyn.

--

You have reached me at a sane moment.
Please call back later.

Other Threads