Tiles and sprites question
Moderator: Stef
Tiles and sprites question
Hi, i have some questions about tiles and sprites collision.
What is the best way to handle tile drawing ?
Use the PLAN_A and draw all the tiles on it ?
Or draw all tiles like a sprite ?
How do you detect player and tiles collision ?
Are you looking for all tiles in the screen ?
Are you looking for the 9 titles around the player ? (3 rows x 3 columns)
Thank you
What is the best way to handle tile drawing ?
Use the PLAN_A and draw all the tiles on it ?
Or draw all tiles like a sprite ?
How do you detect player and tiles collision ?
Are you looking for all tiles in the screen ?
Are you looking for the 9 titles around the player ? (3 rows x 3 columns)
Thank you
Re: Tiles and sprites question
so i found how to deal with tile and sprite collision
Based on sprite sample
Now i have some other questions
How to deal with map and plan scrolling ?
Do i need to refresh the plan in a vblank ?
Based on sprite sample
Code: Select all
typedef struct {
u16 col_x;
u16 col_y;
u16 tile;
} collision_info_t;
static u16 checkTileXCollision(u16 x, u16 y0, u16 y1, collision_info_t * coll) {
u16 tile = 0;
u16 y;
for(y = y0; y <= y1; y++) {
tile = MAP_getTile(&MyLevel, x, y, 0);
if (tile) {
coll->col_x = x;
coll->col_y = y;
coll->tile = tile;
return tile;
}
}
return tile;
}
static u16 checkTileYCollision(u16 y, u16 x0, u16 x1, collision_info_t * coll) {
u16 tile = 0;
u16 x;
for(x = x0; x <= x1; x++) {
tile = MAP_getTile(&MyLevel, x, y, 0);
if (tile) {
coll->col_x = x;
coll->col_y = y;
coll->tile = tile;
return tile;
}
}
return tile;
}
static void updateTileCollision() {
// @todo use boundingbox
#define BOX_X 16
#define BOX_W 16
#define BOX_H 40
s16 __xr = ((fix32ToInt(posx) + BOX_W + BOX_X) >>3);
s16 __xl = ((fix32ToInt(posx) + BOX_X) >>3);
s16 __y = (fix32ToInt(posy)>>3);
s16 __yb = ((fix32ToInt(posy)+ BOX_H) >>3);
collision_info_t col= {};
u16 left = 0;
u16 right = 0;
u16 bottom = 0;
u16 top = 0;
// XAXIS
// Left
if (checkTileXCollision(__xl, __y, __yb-1, &col)) {
posx = FIX32((col.col_x<<3) - 8);
movx = 0;
}
// Right
else if (checkTileXCollision(__xr, __y, __yb-1, &col)) {
u16 m = (col.col_x<<3) - BOX_X - BOX_W;
posx = FIX32(m);
movx = 0;
}
// YAXIS
if (movy>0 && checkTileYCollision(__yb, __xl, __xr, &col)) {
posy = FIX32((col.col_y<<3) - BOX_H);
movy = 0;
}
if (left || right/* || bottom*/) {
VDP_drawText("COLL", 5, 0);
} else {
VDP_drawText("NO_C", 5, 0);
}
}
Now i have some other questions
How to deal with map and plan scrolling ?
Do i need to refresh the plan in a vblank ?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Tiles and sprites question
Your questions are such generic and basics that we can't really reply them in a fast way, dealing with collision is up to the developer and many solutions exists for instance ! I think you search in the forum, i guess many of your questions has already been replied or at least discussed
SGDK provide methods to deal with MAP and scrolling :
https://github.com/Stephane-D/SGDK/blob ... c/vdp_bg.h This unit contains methods to set scrolling on bg plan (A and B)
https://github.com/Stephane-D/SGDK/blob ... vdp_tile.h This unit contains methods to set MAP infos (with VDP_setMap(..) or VDP_setMapEx(..) for instance).
SGDK provide methods to deal with MAP and scrolling :
https://github.com/Stephane-D/SGDK/blob ... c/vdp_bg.h This unit contains methods to set scrolling on bg plan (A and B)
https://github.com/Stephane-D/SGDK/blob ... vdp_tile.h This unit contains methods to set MAP infos (with VDP_setMap(..) or VDP_setMapEx(..) for instance).
Re: Tiles and sprites question
How to remove fonts from VDP-RAM ?
Not enough space for a boss-sprite.
Not enough space for a boss-sprite.
Re: Tiles and sprites question
Simply overwrite ?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Tiles and sprites question
It depends about which methods you are using in your code to load your gfx data to VRAM but normally you are free to overwrite the font space if you really want to, but then you won"t be able to display number or string for debug stuff :-/
Re: Tiles and sprites question
It's better to use KDebug methods anyway
Re: Tiles and sprites question
Incidentally, in this case, it would be useful mirror of plane.
Twice would save memory of VDP-RAM, due with a symmetric background.
Twice would save memory of VDP-RAM, due with a symmetric background.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Tiles and sprites question
Mirror of plane exists and are supported by hardware, rescomp does it automatically if your background image is correctly done
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Tiles and sprites question
What did you used to generate the image resource ? and the symmetry should be aligned on tile (8 pixels blocks) else it cannot be optimized.
Re: Tiles and sprites question
I painted in the paint-dot-net, then through the photoshop - was save in 16с palette.
image size 240*64 - It must be divisible by 8.
image size 240*64 - It must be divisible by 8.
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Tiles and sprites question
and you imported it in binary form with rescomp ?
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Tiles and sprites question
Can you show me the content of your .res file and the code you used to display the background ?