gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Beginners > Dynamically putting tiles on map

#43466 - sabkaraja - Mon May 23, 2005 9:14 pm

Hi

I am asking this question after reading the FAQ and newbie questions in this forum. I am not sure whether its my inability to understand it.

Let me explain what I have done: I have an image (240*176, 256 color) where(240*160 is an image and rest are gfx of alphabets and numbers).
I have a bgchar[...] = {................};
I have a bgmap[32*20] = {.................};

What I want to acheive is:add some text on the screen which will be visible along with the background image at runtime. I dont want to create sprites. I want to have dynamically modify the bg map and add string like score or debug messages which should overlay on top of this bg layer itself.

As an example I created another tempmap[4] = {........}; where each element is tile on the bgchar.

Now when I use DmaArrayCopy(3, tempmap, BG_VRAM + 0x1000, 16);
it replaces the whole image instead of the text at the said location.


Am I doing something seriously wrong ?

TIA

Rajesh

#43544 - jenswa - Tue May 24, 2005 12:51 pm

You can create the text with sprites on top of the bg. This way you don't need the rewrite the entire background.

You can put the text on the background. But then you need to render the text in the bitmap. Bitmap contains pixels and the pixels have positions.
You need to replace several pixels in the bitmap with some colour to create a character.
What i am actually saying is that you should try to start with rendering a square over your bitmap background.
The square has an simple shape, which makes calculating the positions of the pixels relatively simple.
When you've experimented with the square you can try more difficult shapes like a circle and text characters.

I hope this helps you a bit.
Jenswa
_________________
It seems this wasn't lost after all.

#43564 - Lord Graga - Tue May 24, 2005 7:00 pm

Jenswa is making it far too complicated :)

What you want to do right now is 8x8 fonts on a tilemap. To do this, create a font gfx with the text in ASCII order (i.e, space is 0x20, A is 0x21, B is 0x22, C is 0x23, etc), and then to write a piece of text to the tilemap, simply copy the string to the map one letter at the time, with the tileoffset as the first letter's tile (space) subtracted by 0x20 (32).

Pseudocode:

Code:
function "print text to map" (mapbuffer, x, y, string)

    for i = 0 to stringlength

        (u16) mapbuffer[ x + y * 32 + i ] = (char) string[ i ] - 32

    next i

end function

#43671 - sabkaraja - Wed May 25, 2005 4:57 pm

Thanks everyone.

I managed to put dynamic fonts on the BG.

Taking it up to the next level. At present the fonts are 7*7 in size and are positioned as tile. I would like to know how we can plot a font which is bigger than a tile and space it evenly , say two pixels each (not with tiles).

If I am doing that, part of a letter will be lying in one tile and rest in another.

I am not sure whether I am clear.

Regards

Rajesh

#43689 - Miked0801 - Wed May 25, 2005 6:40 pm

That gets much more difficult. It's a matter of checking for char edge boundaries and handling it. Too much code to really post here. Basically, if you want to do this easier, use sprites.

#43693 - sabkaraja - Wed May 25, 2005 7:17 pm

Sprites are agreeable.

However the main idea driving me is - there's a limit of sprites you can have on screen. What if I want to have a screen where there are screen ful text plus some sprite animations to go with that.

I dont know if that can be achieved through sprites itself. I would choose bg to render text, if I had a way (unless there's a better way).

Regards

#43695 - poslundc - Wed May 25, 2005 7:28 pm

Unfortunately, there is always a tradeoff whichever method you go with.

Games that use sprites for their fonts usually multiplex the sprites to get around the OAM limitation. This means every N scanlines you change the OAM values during HBlank to point to different characters. It's an advanced technique and has some drawbacks.

Painting to a background across tile boundaries is always going to incurr a performance hit, but many games prefer this method regardless. This is also the reason many of them display text one character at a time, so they don't have to paint them all in one go.

This thread is about the definitive resource on the different strategies.

Dan.

#43879 - sabkaraja - Fri May 27, 2005 3:49 pm

Sorry about this. This is regaring one problem which started off this topic.

I created bg map with some deafult tiles.

Later added/changes some tiles on that.

But whatever I do, the updated tile doesnt seem to get updated in the VRAM.

I noticed that if i add the dynamic tiles before I go into the while loop in the main function, it is visible. However if I do it within a function inside the loop, it doesnt !

Why does it happen? Any suggestions ?

I tried & used
DMAArrayCopy
CPUFastArrayCopy

Regards

#44045 - sabkaraja - Sun May 29, 2005 7:43 pm

Hey... I think that since I was defining the bg map with default tiles - it was loaded into ROM.

So I removed the default tiles and tried to generate them at runtime.. It displayed some thing on screen.

So I went back to the first step and added the
attribute__ ((section (".sbss")))

attribute to the map data to load it in external ram.

But that doesnt work.. Will anyone please give a brief or pointer to this situation.

Thanks in advance

Regards

#44051 - tepples - Sun May 29, 2005 8:32 pm

Anything in section .sbss will be loaded as zeroes. Use section .ewram if you're loading actual data into RAM.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.