I just noticed here:
Code:
function TForm1.GetCorners(aSpr: TSprite): TCorners;
// get object corners, includes velocity!
begin
// calculate tile index for each object corner
Result.Left := Math.Floor((aSpr.x -4) / 64);
Result.Right := Math.Floor((aSpr.x + aSpr.Width) / 64);
Result.Up := Math.Floor((aSpr.y -4) / 64);
Result.Down := Math.Floor((aSpr.y + aSpr.Height) / 64);
this seems incorrect...I think it should be this:
Code:
function TForm1.GetCorners(aSpr: TSprite): TCorners;
// get object corners, includes velocity!
begin
// calculate tile index for each object corner
Result.Left := Math.Floor((aSpr.x - aSpr.w + aSpr.vx) / cTileW);
Result.Right := Math.Floor((aSpr.x + aSpr.w + aSpr.vx) / cTileW);
Result.Up := Math.Floor((aSpr.y - aSpr.h + aSpr.vy) / cTileH);
Result.Down := Math.Floor((aSpr.y + aSpr.h + aSpr.vy) / cTileH);
Each sprite corner is the position (x or y) added to the sprite's half width or height (see ascii art):
Code:
TL up TR
* | *
|-h
Left | Right
--------*-------
-w | +w
|+h
|
* down *
BL BR
This then needs to have the velocity added onto it so the correct tile index is being calculated for the new position being moved to
Does this make it any clearer?
Oh, also I can't see where you are setting the sprite's vx an vy properties in the code?
Note: I think you should use constants or similar for the tile width and height so it is all the same throughout the code and only needs to be changed once
PS. Maybe I will download Adorra so I can try fixing the code myself if you are still having troubles
Good luck
cheers.
Paul
Bookmarks