Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Lightbulb moment... Using text as a tiled map?

Author
Message
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 31st Jul 2012 16:47
Hi all, wanted to open this up for discussion, see if anyone else has done something similar, that sorta thing.

So, anyone who's used it, will know that AGK's text system is awesome, it's really nicely put together, and I'm nothing but impressed by how nice it can make text look, consistantly. It takes a bit of setting up, but it was that 'complex' setup that got me thinking.
The text system uses a text file with details of each character, and the area of the relevant image that is used for that character. So a standard font, maybe from that font generator (which name escapes me, I do know it has a Russian flavor to it) - will involve a .PNG image with all the characters laid out, and an acompanying text file with each ascii characters position, width, and height.
Now, my point is that it's possible to make a custom text file for a tile sheet, and treat it just like text in AGK. Rather than using several sprites, you would have a text box for a single screen, or several text boxes to cover your whole map. I have tested this idea, and it seems to work pretty sharply, like using a 16x16 tile map, 256 images, it looked just as good as the sprite version. I haven't had a chance to do any speed comparisons, but I'm thinking that having a preset text object is better than having, what, 256 sprites.

There are some limitations that I found - mostly that you'd have to keep your tiles within a safe ascii limit, like mimicking an actual font, starting at char 32 for example. When I tried to be greedy, and used 256 individual tiles, the strange ascii values wouldn't work - so the text object would have random text inbeside the tiles, due to ascii. So the rules would be... maybe an 8x8 grid of tiles instead of 16x16. It can be tricky, because that doesn't give a lot of tiles for say, an RPG game, but would be fine for a platform game. That could be stretched, maybe using 10x10 tiles, to give 100 different tiles. The standard ascii really starts at char 32, so the subimage file would start at 32 as well, and include however many images it can support. I'm not 100% sure, of course.

So, if you want a big map, maybe text objects is an option for you. As long as you don't need hundreds of different tiles, I think it's a pretty workable idea. You'd get a tileset, say a grid of 8 by 8 tiles, then make tile 1 blank, and set the ascii characters on each text object to suit the map data. I'd stick with a text box size of 16x16 tiles, so each text object would hold 256 characters, and each text object would be positioned on the world, so changing the view offset is akin to scrolling the screen. Considering a decent sized 2D map, say 256x256, well that could be 65,000+ sprites, or it could be 256 text objects. If AppGameKit creates the text objects and just leaves them alone unless something changes - well it might just reduce the overhead and make for a fast and efficient tiled map engine. Low maintenance as well - if a map tile changes, just change it in the text object, like re-build the text string based on the map.

When I get a spare hour, I'll see if I can make an example of this - my experiment code is not exactly elegant, really I just wanted to see if anyone else had some ideas, and maybe it's worth having a good look at the text system, who knows what it could make possible with a little hacking and thinking outside the box.

Health, Ammo, and bacon and eggs!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 31st Jul 2012 17:29
That's a clever idea Van B. I hadn't thought of that. Another limitation might be that the text object may always be visible on screen so you might end up with a huge "image" being displayed when you actually only need to display a couple of dozen sprites. I don't think you'd get the same advantage as using an atlas sheet for your tile images but I'd be very interested in your test results!

You may also loose the opportunity of using physics and collision testing but it could be used for backgrounds / foregrounds etc...

Love this kind of out of the box thinking


this.mess = abs(sin(times#))
3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 31st Jul 2012 18:16 Edited at: 31st Jul 2012 19:07
I like to see the results of using text boxes to display text instead of sprites. But I haven't played with text boxes like this. I thought they were for input only. So Using a text box to display information I think would save on speed, but look mighty ugly. I thought of idea of putting your movie on the internet so using HTML commands to load the video would make it so that AppGameKit does not have to include video in there commands. I don't know if this can be done but it sure needs to be discussed as well.

I think that if you write a tutorial on this I will read it. So If agk makes it possible in the future to use the input text boxes or something similar to it it would make games preform a lot faster. Because your using native IOS/DROID commands to make the text.

I think another way of saving space is use html commands to make a web page that displays your text for your app. That would be cool if someone made a game that relied on html and agk at the same time, but I think only people on these forums would appreciate such a game.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 31st Jul 2012 18:37
Some things...

You don't really need a text box for this. If the characters are uniform width, you can include a chr(10) to make the text wrap to the next row. So your whole screen can be one text object.

Also, if the font is fixed width, you don't need a subimages file.

Quote: "The font image may either be fixed width or variable width. For fixed width the font image must be laid out in a grid of 16 characters across and 6 characters down, starting with the ascii character 32 (space) in the top left and proceeding left to right, top to bottom, ending with ascii character 127 (DEL) in the bottom right. The image width must be divisible by 16 and the image height must be divisible by 6."


So you are limited to characters from ascii 32 to 127. BUT... you can also use an extended font image file for characters from ascii 128 to 255. So really quite a few tiles can be used.

Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 1st Aug 2012 01:14
Van B, that is a really good idea, interesting way to use the text outside the box

Although, I am wondering does anyone use the old trick of just having 1 sprite with animation, each frame being a tile, and just setting the frame and drawing it anymore? I find this works very well in AppGameKit and no need for sub images because you do not switch the texture(image).
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 1st Aug 2012 11:50
Thanks Rich, that's good stuff to know, much appreciated.

I've never tried that Pilz, I tend to just clone a main sprite and set the frame, position it to suit. I think that someone mentioned in my tiled map example that repeatedly drawing the sprite instead is a bit slower. That's a shame really, it would be great to take control over sprite drawing - like rather than using several sprites for a complex characer.

Health, Ammo, and bacon and eggs!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 1st Aug 2012 13:05
I have also been using the text system in non-standard ways. For me it started when I wanted huge numbers, but didn't want a full, oversized image map to achieve this. Imagine loading over 70 images at 256x256, just to display the numbers 0 to 9.

I messed around and worked out how to "cheat" the system. Here is the tutorial I made on it. Also note that missing ASCII values revert to 32, so make sure your default tile is represented by a space. Step 5 in my tutorial is redundant.

http://www.thegamecreators.com/news/2012/05/innumeracy-made-good/

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 1st Aug 2012 13:47
Draw sprite is slower and was only added after release. It's not meant to be used to draw the level each loop. Once you get the hang of sprites they are very nice.

Pilz X Schizo
17
Years of Service
User Offline
Joined: 21st Mar 2007
Location: Massachusetts, USA
Posted: 1st Aug 2012 21:20
So far the only way I get a slow down with draw sprite is if I switch back and forth between sprites repeatedly, which would keep switching the image/texture. Using 1 sprite for something like a map and just looping through drawing the specific frame for the tile does not give any sort of slow down for me.

@Digital Awakening: It is not that I do not have the hang of using sprites, I find that it is overly complicated and processor intensive to create/handle each and every sprite that makes up the level, especially if you have a map that is 1000x1000, for a total of 1,000,000 sprites, or just draw the 400 tiles that are on the screen.

@Van B, Still think this is a really good idea, nice way to take advantage of a single texture and have AppGameKit create 1 object to display a level.
Rich Dersheimer
AGK Developer
14
Years of Service
User Offline
Joined: 1st Jul 2009
Location: Inside the box
Posted: 1st Aug 2012 23:28 Edited at: 1st Aug 2012 23:30
I'm trying something almost the opposite in my current project.

I'm making text on the screen by drawing sprites, getting them as an image, making a sprite from the image, then messing with the sprite to achieve the look I want.

Since I want to use really big characters, and I'm changing the UV's of the sprite, I'm loading in each letter as a separate 256x256 image. (UV changes work best with powers of 2 and non-atlas images)

So far it's working well, but time will tell...

@batvink...

Quote: "Imagine loading over 70 images at 256x256"


Yah, that's exactly what I'm trying, heh heh.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 2nd Aug 2012 01:22
Quote: "So far the only way I get a slow down with draw sprite is if I switch back and forth between sprites repeatedly, which would keep switching the image/texture. Using 1 sprite for something like a map and just looping through drawing the specific frame for the tile does not give any sort of slow down for me."


Ah, that's interesting. Should be useful for those making huge maps to use it to fill up the screen.

3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 2nd Aug 2012 03:23 Edited at: 2nd Aug 2012 03:26
no one responded to this it was the same idea of using a sprite sheet to make chars. I thought no one was interested in this stuff.

http://forum.thegamecreators.com/?m=forum_view&t=197520&b=41

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.
erebusman
12
Years of Service
User Offline
Joined: 23rd Jul 2011
Location: Sacramento, CA
Posted: 2nd Aug 2012 08:11
@3d point in space;

-- I would say the difference is that VanB went to some length to explain the concept; having had read your post before; and just re-read it ; I had no idea that's what you even meant either time.

In other words; it is not that people were not interested; but perhaps you could have communicated your message more clearly/effectively.
3d point in space
14
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 3rd Aug 2012 08:43
Explain: why do something so silly I like the direct approach better. Get the message out and do it in the least words possible. It is more because he is a mod so more people listen.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.
Van B
Moderator
21
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Aug 2012 09:49 Edited at: 3rd Aug 2012 10:05
3D, All I am doing here is presenting an idea that I feel has some benefits - it's clear that I should make an example to try and overcome the issues with non-ascii characters, as well as some speed tests to see if there is real benefit in this idea.

It's an open discussion, your thread, well to be honest I have no idea what your saying, or asking, or telling - you include an image of the alphabet for example, in black... black is the least useful colour you can possibly use for text images. If you had provided an example or a code snippet, then I'm sure that more people would understand and respond.

As for the idea being silly, well you might not think that if you knew how OpenGL works. There's a chance that the text system uses a vertex array, or even an internal image render, either of which would be faster than displaying the relevant sprites. Ideally, I'd like to find out the fastest possible way to handle a tiled map in AppGameKit, if that involves cheating and using something like the text system, then so be it - should I feel guilty because people like the idea or want to contribute to it?
I imagine, that the people responding here have already had to make their own text system, this thread isn't about text, it's about extracting any benefit that might be hidden below the surface.

Health, Ammo, and bacon and eggs!
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 3rd Aug 2012 10:45
Have to say I'm with Van B on this one. Any potential optimisation techniques are useful to have to experiment with.

-- Jim
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 3rd Aug 2012 15:04
Van B, I had the same idea as soon as I understood that the text letters, were just read in from an image sheet. But I don't see the real need for this technique in level design, since I make my levels with a system that reads letters in a string, to place the sprite tiles in my game.

On the other hand, we can use it to display smilies, and "stange" international letters, like Æ Ø Å by replacing unneeded ASCII letters, in the font file.

We can even make animations, I think, by changing the font for each frame. Don't know the impact of this, but it will instantly change all the text objects on screen I would think, to make animated text.

I love this thinking out of the box thing. I hate boxes!

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.

Login to post a reply

Server time is: 2024-04-27 21:36:06
Your offset time is: 2024-04-27 21:36:06