Scrolling map
Moderator: Stef
Scrolling map
I want to make a sample of a map, scrolling both horizontally and vertically, being wider and higher than the plane it's drawn onto.
I see there's a Map class in SGDK. I was wondering if methods to update the plane had been implemented, or if I have to code them (I know propeller does that and I'll have a look into its code if necessary).
I'm sorry if some documentation somewhere deals with that, I'm a little lost to find usable documentation on SGDK (for the moment, I mostly read the sources).
I see there's a Map class in SGDK. I was wondering if methods to update the plane had been implemented, or if I have to code them (I know propeller does that and I'll have a look into its code if necessary).
I'm sorry if some documentation somewhere deals with that, I'm a little lost to find usable documentation on SGDK (for the moment, I mostly read the sources).
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Re: Scrolling map
Here are the methods (and attached doxygen documentation) using the Map structure :tryphon wrote:I want to make a sample of a map, scrolling both horizontally and vertically, being wider and higher than the plane it's drawn onto.
I see there's a Map class in SGDK. I was wondering if methods to update the plane had been implemented, or if I have to code them (I know propeller does that and I'll have a look into its code if necessary).
I'm sorry if some documentation somewhere deals with that, I'm a little lost to find usable documentation on SGDK (for the moment, I mostly read the sources).
Code: Select all
/**
* \brief
* Load Map at specified position.
*
* \param plan
* Plan where we want to load Map.<br/>
* Accepted values are:<br/>
* - VDP_PLAN_A<br/>
* - VDP_PLAN_B<br/>
* \param map
* Map to load.
* \param basetile
* Base index and flags for tile attributes (see TILE_ATTR_FULL() macro).
* \param x
* Region X start position (in tile).
* \param y
* Region Y start position (in tile).
*
* Load the specified Map at specified plan position.
*
* \see VDP_setTileMapData()
* \see VDP_setTileMapDataEx()
*/
u16 VDP_setMap(u16 plan, const Map *map, u16 basetile, u16 x, u16 y);
/**
* \brief
* Load Map region at specified position.
*
* \param plan
* Plan where we want to load Map.<br/>
* Accepted values are:<br/>
* - VDP_PLAN_A<br/>
* - VDP_PLAN_B<br/>
* \param map
* Map to load.
* \param basetile
* Base index and flags for tile attributes (see TILE_ATTR_FULL() macro).
* \param x
* Plan X destination position (in tile).
* \param y
* Plan Y destination position (in tile).
* \param xm
* Map region X start position (in tile).
* \param ym
* Map region Y start position (in tile).
* \param wm
* Map region Width (in tile).
* \param hm
* Map region Heigh (in tile).
*
* Load the specified Map region at specified plan position.
*
* \see VDP_setTileMapDataRect()
* \see VDP_setTileMapDataRectEx()
*/
u16 VDP_setMapEx(u16 plan, const Map *map, u16 basetile, u16 x, u16 y, u16 xm, u16 ym, u16 wm, u16 hm);
I would say the VDP_setMapEx(..) should allow you to do what you want. Just don't forget to unpack the Map first (as it can be compressed), if you don't do it, the Map will be unpacked at each method call (very slow).
You have a method to unpack Map :
Code: Select all
/**
* \brief
* Unpack the specified Map structure.
*
* \param src
* map to unpack.
* \param dest
* Destination map where to store unpacked data, be sure to allocate enough space in tiles and tilemap buffer.<br/>
* If set to NULL then a dynamic allocated Map is returned.
* \return
* The unpacked Map.<br/>
* If <i>dest</i> was set to NULL then the returned map is allocated in a single bloc and can be released with Mem_Free(map).<br/>
* <i>NULL</i> is returned if there is not enough memory to store the unpacked map.
*/
Map *unpackMap(const Map *src, Map *dest);
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
Eight-way scrolling like in Propeller/Goplanes is tricky. Unfortunately their code is not super clear so you might not get it right away. You might have a better time looking at the Violence Pingouin code. It doesn't do 8-way scrolling, just straight horizontal or vertical, but it's much simpler to understand. The code is a tad better laid out too.tryphon wrote:I want to make a sample of a map, scrolling both horizontally and vertically, being wider and higher than the plane it's drawn onto.
I see there's a Map class in SGDK. I was wondering if methods to update the plane had been implemented, or if I have to code them (I know propeller does that and I'll have a look into its code if necessary).
I'm sorry if some documentation somewhere deals with that, I'm a little lost to find usable documentation on SGDK (for the moment, I mostly read the sources).
Not saying that it's impossible. Just saying maybe some walking before running
Stef, when using VDP_setMapEx, does this reload all visible tiles, or just the new ones? For instance if the map is scrolling to the right then just one column on the left side would need to be loaded, right?
I've got an 8 way unlimited scrolling demo that maybe I'll try to clean up and post at some point, but if there are facilities already built into SGDK, that may be more convenient.
I've got an 8 way unlimited scrolling demo that maybe I'll try to clean up and post at some point, but if there are facilities already built into SGDK, that may be more convenient.
-
- Very interested
- Posts: 710
- Joined: Sat Feb 18, 2012 2:44 am
I think there's a bit of confusion.
The original poster was asking for a scrolling system, one that updates the borders of the screen with new rows/columns of data to simulate playing fields that are larger than the VDP planes.
The file functions Stef explained can be used to implement a scrolling system (use them to copy a strip of map from rom map data to a vdp plane) but it won't update the borders for you. You'll have to take care of that.
The original poster was asking for a scrolling system, one that updates the borders of the screen with new rows/columns of data to simulate playing fields that are larger than the VDP planes.
The file functions Stef explained can be used to implement a scrolling system (use them to copy a strip of map from rom map data to a vdp plane) but it won't update the borders for you. You'll have to take care of that.
I have a question about Map struct : I found its specification :
I guess tilemap is a sequence of w*h words with the bit-format (thanks Charles McDonald) :
But from the header of VDP_setMap function :
What does the basetile do ? Is it added to each word of the tilemap before being sent to the VRAM ?
Code: Select all
typedef struct
{
u16 compression;
u16 w;
u16 h;
u16 *tilemap;
} Map;
Code: Select all
pccvhnnnnnnnnnnn
p = Priority flag
c = Palette select
v = Vertical flip
h = Horizontal flip
n = Pattern name
Code: Select all
u16 VDP_setMap(u16 plan, const Map *map, u16 basetile, u16 x, u16 y);
-
- Very interested
- Posts: 3131
- Joined: Thu Nov 30, 2006 9:46 pm
- Location: France - Sevres
- Contact:
Exactly !
The basetile value is added (actually ored) with the word data in the map. It allows you to add an offset for the first tile index for instance, but also to override h/v flip flag, palette number and priority.
Code: Select all
/**
* \brief
* Load Map at specified position.
*
* \param plan
* Plan where we want to load Map.<br/>
* Accepted values are:<br/>
* - VDP_PLAN_A<br/>
* - VDP_PLAN_B<br/>
* \param map
* Map to load.
* \param basetile
* Base index and flags for tile attributes (see TILE_ATTR_FULL() macro).
* \param x
* Region X start position (in tile).
* \param y
* Region Y start position (in tile).
*
* Load the specified Map at specified plan position.
*
* \see VDP_setTileMapData()
* \see VDP_setTileMapDataEx()
*/
u16 VDP_setMap(u16 plan, const Map *map, u16 basetile, u16 x, u16 y);