a basic TileMap implementation

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

a basic TileMap implementation

Post by jph_wacheski »

for the first attempt I use the Font Component to cut the tiles up and arrange them,. works well enough for my purpose; a single screen tile based game to be called; nascii.

We end up with a 21x38 grid in modern wide screen mode (16:9).

Notice the CharScale=.9995; in the levelLayout RenderText Expression to 'clip' the edges of the tiles where adjacent sub pixel noise bleeds in due to rounding errors in the font component, I assume. Suppose we could also use the Font Component's BorderPixels to buffer them,. however I was working with this tile set made by Olav ( http://cellusious.tumblr.com/ )

hold/press SPACE to get some noise gen levels,. and the LMB will remove tiles,. all there is so far.

wondering if it would be better to use a mesh with the grid size 21x38 and set the texture coordinates to the tile locations on the bitmap,. seems the Text renderer is using a quad per char? This makes many effects possible,. . hummmm.

like most stuff there are a large number of ways to implement something like this.

open to ideas and suggestions. thanks in advance.
Attachments
nascii_001.png
nascii_001.png (198.7 KiB) Viewed 12081 times
nascii_levels_007.zip
.zgeproj
(43.63 KiB) Downloaded 435 times
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Re: a basic TileMap implementation

Post by Kjell »

Hi jph,
jph_wacheski wrote:Notice the CharScale=.9995; in the levelLayout RenderText Expression to 'clip' the edges of the tiles where adjacent sub pixel noise bleeds in due to rounding errors in the font component, I assume.
Tile bleeding isn't caused by rounding errors, it's because of how rasterizers work ( check this page for more information ). Anyway, you can easily "fix" this by offsetting your texture matrix slightly.
jph_wacheski wrote:wondering if it would be better to use a mesh with the grid size 21x38 and set the texture coordinates to the tile locations on the bitmap.
That would be a better solution yes ( but still not ideal ). The font component generates & renders each character individually ( each using a whopping 5 matrix multiplications .. while you don't need any ) each frame, which makes the Font component pretty much the worst way of rendering a tile-map ( or text for that matter ).

K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

What would you consider the "ideal" solution? Assuming the tileMap will be dynamically modify-able as the game is played.

For my immediate use, the map is limited in size,. however what if we are doing a scrolling type game with a vast area? Then the display area should move over a larger non-displayed field of data,. I suppose.

I assume no solution is universally useful and therefor "ideal" only applies to the specific task at hand?

I would like to make a simple tile system available in ZGE for pixel level type work, since these are common elsewhere and applicable to many design styles and game types.
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph,
jph_wacheski wrote:I assume no solution is universally useful and therefor "ideal" only applies to the specific task at hand?
In this case there actually is a ideal / standard .. and it has been used in pretty much all 8 / 16-bit consoles. Of course there are some minor implementation details that are debatable when translating this "standard" to a polygon pipeline, but they are only minor.
jph_wacheski wrote:I would like to make a simple tile system available in ZGE for pixel level type work, since these are common elsewhere and applicable to many design styles and game types.
Probably my most used sentence on this forum .. should be built-in.

K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

ZGE is opensource perhaps to encourage people like yourself wit knowledge/skills to contribute to it, just saying "it should be" this or that does little to further the project. Build it in,. share the code!

You do provide many examples and tutorials currently, and I for one am always happy learning from other peoples work, so I do appreciate when ppl post examples and ideas.

For this tileMapping thing I am not intending any new systems in ZGE just some implementations of functional concepts.

"ideal" is for philosophers,. lolz.
iterationGAMES.com
User avatar
Kjell
Posts: 1876
Joined: Sat Feb 23, 2008 11:15 pm

Post by Kjell »

Hi jph,
jph_wacheski wrote:ZGE is opensource perhaps to encourage people like yourself wit knowledge/skills to contribute to it, just saying "it should be" this or that does little to further the project. Build it in,. share the code!
I don't have CodeGear Delphi ( XE5 ), so there's no way for me to compile the Editor and thus create a component.

I understand where you're coming from though. Voicing these kind of complaints ( regardless of whether they are warranted or not ) can be toxic to a community.
jph_wacheski wrote:"ideal" is for philosophers.
Well, "ideal" has multiple definitions, but let me rephrase it to .. the best solution they could come up with in the 70s / 80s ( and still holds up today ) ;)

K
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

Even without coding in the source one can still provide pseudo-code, implementation suggestions, and ideas without doing the actual builds., just a thought.

The old console solutions would not be taking any modern 3d hardware into account?,. the idea of a tileMap system in ZGE is that we can still use the modern openGL stuff to augment the displaying of the tiles and create interesting effects and such,. . if that makes any sense.
iterationGAMES.com
User avatar
VilleK
Site Admin
Posts: 2274
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post by VilleK »

What could help when suggesting new features are some additional specifications:

- What new components (if any) are needed?
- What are the properties of those components?
- Changes to existing components?
- Is there anything that could cause backward compatibility issues?
- Could it be implemented as a ZLibrary/externalibrary instead? Pros/cons?

It helps me think in more concrete terms on how the feature can be implemented.
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

Like I've said this idea is just working out how to implement a basic tilemap using ZGE as it is (no new components). Whether it should be "built in" or not is up to you. The Font component does do a good job of cutting up a single bitmap into tiles,. but I suspect it would be more efficient to do this in a script setting TexCoord to map the tiles on a mesh. Just did not want to do the math/logic,. overactive lazy mind, lol. Perhaps a StaticText (StaticTile) component that does not have time based manipulation would be useful,. up to you.

Most anything can be done with ZLibrary/externalibraries now,. just makes it more difficult/slow for people who would rather build a game than design/build engine/tech.

Anyway, I will post some more when I get more working,. weather is still rather nice here, so only getting small spurts of work done,. still open to suggestions/examples of implementations of pixel based tile rendering. btw

The nascii game idea is developing nicely from all this,. should have something playable shortly.
iterationGAMES.com
User avatar
jph_wacheski
Posts: 1005
Joined: Sat Feb 16, 2008 8:10 pm
Location: Canada
Contact:

Post by jph_wacheski »

ok, had a bit of time with this, and the idea to build a mesh instead of using the zge Font component for rendering the tileMap. Seems to be working well,.

Now we can RMB to select a tile, and LMB to place what is selected,. need to add a way to see all the tiles.
Also SPACE to gen noise levels, and hold B w/ SPACE to step back in the noise.

main 'tile to mesh' stuff is in the g_levelMesh;

Code: Select all

  float tle_num=levelMap[lpY.iteration,lpX.iteration]; //get tile num

   float tileX=ceil(frac(tle_num/16)*16);    //pick tile from bitmap
   float tileY=ceil((tle_num/16));

this.TexCoord.X=((this.V.X+1)+2*tileX)*.03125;  //set tile to mesh
this.TexCoord.Y=((this.V.Y+1)+2*tileY)*.03125;

this.V.X+=lpX.iteration*1.9995;  //pos mesh in structure
this.V.Y+=lpY.iteration*1.9995;       //slightly < 2 to clip rastering noise
Should be possible to add tile flipping and rotation to this as well,. probably use a separate array for that data.

Anyway, now we have an array to work the gameplay on,. I am going to need an A* for moving units around walls and stuff next,. anyone implemented an A* or better algorithm in zge they want to share??
Attachments
nascii_levels_020.zip
.zgeproj file
(45.4 KiB) Downloaded 432 times
iterationGAMES.com
Post Reply