looping scrolling foreground

SGDK only sub forum

Moderator: Stef

Post Reply
Kuroto
Interested
Posts: 46
Joined: Sat Mar 02, 2013 4:34 pm

looping scrolling foreground

Post by Kuroto » Tue Apr 15, 2014 9:04 pm

Hi all,

What would be the best way to create a looping scrolling foreground?
Say I have a large BMP file of a map, and I would want to scroll it, for example on the A Plane. What would be the best way to do it?

I'm trying to use the A plane to draw the "pipes" in my flappy bird game, so eventually I would also like to implement colission detection. But that's for later.

I've tried drawing a BMP file to APLAN, but if it's too large it'll start to glitch (out of memory?).

Then I've tried the following:

Code: Select all

        if (lscroll > 0) VDP_setHorizontalScroll(APLAN, lscroll);



        lscroll-=8;

Obviously, this doesn't loop. But it does scroll the A plane to the left.
So i'm trying to use this as a starting point. I would love to use some larger maps though.

I've been searching these forums as well, and I did stumble upon some posts about updating the tiles, but I'm not sure how to start with that.

Thanks in advance.

Kuroto
Interested
Posts: 46
Joined: Sat Mar 02, 2013 4:34 pm

Post by Kuroto » Mon Apr 21, 2014 10:17 pm

So, small update.

I'm using Mappy now with MDPPY.

It generated an .asm file, which I'm trying to use in SGDK.
Unfortunately I can't find any information about using .asm maps at all. :?

I'm stuck at this point, so any help is appreciated.
Thanks!

Best regards,

Steve

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Apr 22, 2014 8:35 am

I missed your message sorry.
Actually you can use a very large image with rescomp to define all the complete map. Rescomp will compile it as a image resource where you have the tile data (tileset field), the map data (map field) and palette.
Then when you have those, you can use these methods to display it :

Code: Select all

// load tileset
VDP_loadTileSet(myMap.tileset, TILE_USERINDEX, TRUE);
// unpack the map once
Map *map = unpackMap(myMap.map, NULL);

// main loop
while(TRUE)
{
  // move plan wherever you want
  ...
  // set plan part where we are
  VDP_setMapEx(BPLAN, map, TILE_ATTR(PAL0, FALSE, FALSE, FALSE), xpos, ypos, xoffset, yoffset, w, h);
  ..
}

// release the map when you don't need it anymore...
MEM_free(map);
In the setMapEx method, the xpos and ypos correspond to the top left tile position in your plan where you want to change tilemap.
The xoffset, yoffset is the top left tile position in your map object, and w and h are just the width and height of the map section to update.
Last edited by Stef on Tue Apr 22, 2014 11:10 pm, edited 1 time in total.

Kuroto
Interested
Posts: 46
Joined: Sat Mar 02, 2013 4:34 pm

Post by Kuroto » Tue Apr 22, 2014 10:26 pm

Hi Stef,

No worries :)

I've been trying your suggestion, however i get an "invalid initializer" error when trying to use the map on this line:

Code: Select all

Map map = unpackMap(level1.map, NULL);
Also, is this the right way to declare an image to use as a map? Or should i use something different?

Code: Select all

IMAGE level1 "res/level1.png" -1
Thanks in advance :)

-Steve

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Tue Apr 22, 2014 11:11 pm

Kuroto wrote: I've been trying your suggestion, however i get an "invalid initializer" error when trying to use the map on this line:

Code: Select all

Map map = unpackMap(level1.map, NULL);
Oh minor mistake from me, i meant a Map pointer for map variable :

Code: Select all

Map *map = unpackMap(level1.map, NULL);
I fixed my previous post too !

Kuroto
Interested
Posts: 46
Joined: Sat Mar 02, 2013 4:34 pm

Post by Kuroto » Sun Apr 27, 2014 12:33 am

Hi Stef,

Thanks for the fix!

I'm trying to implement it, but I'm not sure how to be honest.
I've created a new project to test this. This is my current code:

Code: Select all

#include <genesis.h>
#include "resources.h"

int main()
{
VDP_setScrollingMode(HSCROLL_TILE, VSCROLL_PLANE); 
u16 hscroll_value=0;

VDP_loadTileSet(level1.tileset, TILE_USERINDEX, TRUE);
Map *map = unpackMap(level1.map, NULL);


    while(TRUE)
    {
        VDP_setMapEx(APLAN, map, TILE_ATTR(PAL0, FALSE, FALSE, FALSE), 0, 0, 0, 0, 64, 64);

        hscroll_value++;
        VDP_setHorizontalScrollTile(APLAN, 22, hscroll_value, 1 , FALSE);
        VDP_waitVSync();

    }
    MEM_free(map);


}

I can see that I'm really close, and I'm guessing it has something to do with the values I use for setMapEx.

I'm pretty sure I'm mixing pixels vs. tiles up. Is there any relation between the two?


The width and the height we're specifying in the VDP_setMapEx, is that in pixels or in tiles? This is what's confusing me at this point.



Thanks in advance!

-Steve

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Sun Apr 27, 2014 11:12 am

Yeah the map is always expressed in tile.
Tile is a 8x8 pixel bloc, the tileset is the set of tiles you required to display a background / image or whatever... where the map (tilemap) contains the reference to these tiles to build the final image. All informations for map methods are expressed in tile. You have method documentation in the header file, it is handy to understand what a specific parameter does :)

Post Reply