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 / Tile Based Map

Author
Message
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 4th Jul 2012 12:53 Edited at: 4th Jul 2012 13:33
I'm starting out a new project. Which is gonna need a tile based map. I'm in the dark for this. Any pointers to get started with a tiled base engine? I have been looking online but cant find any for agk.

I would like to create one in Tier 1 as i cant code Tier 2.

Thanks.

(Mod Note: Please don't link to suspected maleware sites, thank you!)
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Jul 2012 13:18
I think you'd be surprised at how well AppGameKit runs with just using sprites for the map. The creation of sprites is kinda slow, but once the sprites are made, and they all use the same image, then it runs quite nicely.

For example, make a sprite using your map tileset, set the image sizes etc, then hide that sprite. Then, step through your map locations, copying that sprite and positioning it, change it's animation frame to suit the map. If you use the world coordinates and screen view, then it's very straightforward.

I've been looking at this stuff recently, I was worried about the lack of a tile based map system, but not anymore, I'll just use sprites. One benefit in this, is that those sprites could be proper sprites, like for an isometric engine. Use Z depth based on the world Y position, and a lot of the grunt work is done for you. You might even want to use proper sprites instead of tiles, it's a good way to have the sprites go behind and in front of details properly, that saves a lot of hassle doing it that way.

Health, Ammo, and bacon and eggs!
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 4th Jul 2012 13:45
Ok Thanks for the info, maybe that is indeed the best way to go about it. Loading in sprites => loading map data => setting sprites using the loaded data.

Seems easy. will experiment with this later tonight.

http://redostrike.be/shiny/
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 4th Jul 2012 13:57
It would be extremely nice to have a demo of this technique!

-- Jim
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Jul 2012 16:28
As soon as I get my PC back up, I'll upload a little demo of this. PC blew last week and I'm waiting on a new PSU and case arriving - hopefully it arrived today.

Health, Ammo, and bacon and eggs!
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 4th Jul 2012 19:07
Is it faster to clone a sprie than creating new ones?

Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 4th Jul 2012 19:34
I haven't tested that, just assuming based on how DBPro is faster at cloning. I'm sure there's very little in it - but the thing with sprite sheets and tiled maps, is the setup you have to do. I found it easier to just clone the sprite in the X,Y map loop. I think AppGameKit automatically ignores sprites outside of the screen view, which is great - but even resetting the view, like using a big bank of sprites for the tiles and positioning them and setting the frame, it was still pretty fast.

I'm still using an old beta of AppGameKit, don't have the full thing yet... even though I beta tested it ahem... I'm waiting on Rick giving the mods their mod gold, so I can get the full thing. But, I would be very interested in what sort of frame rates people get. If it's too slow on actual devices, then I think we should start a campaign to get a tiled map system into AppGameKit, all of my ideas depend on it!.

Health, Ammo, and bacon and eggs!
3d point in space
15
Years of Service
User Offline
Joined: 30th Jun 2009
Location: Idaho
Posted: 4th Jul 2012 20:46 Edited at: 4th Jul 2012 21:07
You can look at mine but it not well documented and it is in tier 2. I have worked a lot with tile maps tiled and it is a good program. Like I have said though I too busy too write an editor in tier 1. So your only solution is to look at how baxslash does it he might give you the code.
An Easy way of doing this is a two dimensional array, but if you want to go more advanced look at something like tiled.

Developer of Space Chips, pianobasic, zipzapzoom, and vet pinball apps. Developed the tiled map engine seen on the showcase. Veteran for the military.
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 4th Jul 2012 20:52
From my understanding AppGameKit handles multiple sprites very well and ignores the ones that are out of view. I have not tested it myself but IIRC others have with great success. If they all use the same image it's even faster as you say.

I find it easier to read from a file and create new sprites than to clone. Since they all are created with the same image I do wonder if cloning is any faster at all. But since I haven't tested it I do not know.

Someone who wants to throw some quick tests together and share the results?

Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 4th Jul 2012 22:16 Edited at: 4th Jul 2012 22:17
No clean code and just put it together real fast.



Loads pretty fast. Is all random now but should load data file first. Sprites are 32 X 32.

http://redostrike.be/shiny/
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 4th Jul 2012 22:38
Try putting the 'sync()' inside the do loop. Otherwise you might not actually see anything. Or, do two 'sync()' commands to make sure that the back buffer gets displayed.

Cheers,
Ancient Lady
AGK Community Tester
The Daddy
15
Years of Service
User Offline
Joined: 13th Jan 2009
Location: Essex
Posted: 5th Jul 2012 01:51
The simplest wa to create a scrolling tile map is the same way it used to be done on 8 bit machines like the c64 (had to use assembly language in those days)

Let's assume the app width is 768 and your app height is 1024 and you want your tile size to be 64pixels square.

That means that you require 12 sprites wide by 16 sprites high to fill your screen. However you also want an extra one top, bottom, left and right so 14 sprites wide by 18 sprites high.

Read in a text file that stores a bunch of image id's. So you may have 100 images and you tiled map is built from these images.

Then write a routine that moves all the sprites left, right, up and down by x pixels at a time.

When x = 64 reset x zero.

At this point reset all the sprite images to the next image.....I think I should write a little demo and upload it as I think my glasses of wine are causing me to ramble.....! Be back soon!

Constantly seeking!
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 5th Jul 2012 13:35
Using a few sprites to just cover the screen and move them around is one way to do it. However, I am not so sure it will be any faster. You need to add code to hide, move and change them and if you use T1 it could be slower than AppGameKit handling it by itself.

Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 5th Jul 2012 13:39 Edited at: 5th Jul 2012 13:51
Quote: "Try putting the 'sync()' inside the do loop. Otherwise you might not actually see anything. Or, do two 'sync()' commands to make sure that the back buffer gets displayed."


Worked the way i posted haven't tested it on my android phone trough the player.

Lets try this out now.

EDIT: Runs smooth and loads sprites directy.


Quote: "The simplest wa to create a scrolling tile map is the same way it used to be done on 8 bit machines like the c64 (had to use assembly language in those days)

Let's assume the app width is 768 and your app height is 1024 and you want your tile size to be 64pixels square.

That means that you require 12 sprites wide by 16 sprites high to fill your screen. However you also want an extra one top, bottom, left and right so 14 sprites wide by 18 sprites high.

Read in a text file that stores a bunch of image id's. So you may have 100 images and you tiled map is built from these images.

Then write a routine that moves all the sprites left, right, up and down by x pixels at a time.

When x = 64 reset x zero.

At this point reset all the sprite images to the next image.....I think I should write a little demo and upload it as I think my glasses of wine are causing me to ramble.....! Be back soon!"


I've read that this way is used often. You then need to read the file again to get the map details every time you move the "character" actually the character stays in the middle of the screen and you move the world sounds stupid if you say it but it makes sense.

Maybe its beter to load it the whole file then sprite the whole map (sprite are not on screen arent made by agk itself) and then move the "camera's view" the same size as your sprite?

http://redostrike.be/shiny/
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Jul 2012 14:40
That's what I would do, I think it makes sense to use the camera system, rather than offsetting all your sprites, and upsetting Box2D.

No reason why you can't take the camera position and use that to guage the area that you want to show though. Like take the top left corner of the screen, and the bottom right, and each grid location inside that area can have sprites added, plus a border of 1 or 2 locations - then update this when the player moves, maybe update it only when the player is reaching the end of the previous area. That's what I've done with my experiments, and it seems to work out pretty nicely.

Health, Ammo, and bacon and eggs!
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 5th Jul 2012 15:46
Yes, using setViewOffset() is a LOT easier and quicker.

Also huge maps will be as quick to navigate as small maps. There are some simple commands for checking if a sprite is in the view area too. No point in reinventing the wheel here.

If you're thinking of using Box2D then you have to do it this way, trust me.


this.mess = abs(sin(times#))
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Jul 2012 20:25
I've uploaded an example in a new thread in this board, please try it on your device, would be great to know how it runs.

Health, Ammo, and bacon and eggs!
Redostrike
21
Years of Service
User Offline
Joined: 9th Feb 2003
Location: Belgium
Posted: 5th Jul 2012 21:29
Again not great code, just to test things out.



Changed some things, when i set maxx and maxy to high numbers the loading times are also alot longer. Thats a problem! I think 150 x 150 pixels isent alot and its already taking long. I tried 1000 x 1000 and it took so long that i did not even see sprites poping up.

http://redostrike.be/shiny/
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 5th Jul 2012 22:08
Well, it's the sprite creation that's slow, only way to avoid that is to limit the number of sprites, like create enough sprites to fill the current view and reset that when you scroll. Remember that on a 1000x1000 map, your creating 1 million sprites! - that'll take a while no matter what language you use.

Health, Ammo, and bacon and eggs!
Grook
AGK Backer
12
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 13th Jul 2012 16:24 Edited at: 13th Jul 2012 16:24
I'm doing a tile based screen in a similar way. The question I have is (in Tier 1) is there a way to use a single image to store all the sprite images then create the sprites by copying a section of the main image each time?

I was thinking of using SetSpriteAnimation to set this big image into each sprite then choosing what tile I want on the map by setting the frame of the animation... However, I'm worried that this will duplicate the large image in memory for each sprite which could lead to some severe memory issues! Anybody have any experience of doing it this way?

"Happiness is contrary to the human condition" --White (to Black)
Van B
Moderator
22
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 13th Jul 2012 16:28
Yup, that's exactly what I do - no slowdown, because you would clone the sprite each time, and only referencing the texture it uses. Not that it matters - if you only load an image once, then you'll only ever have 1 copy of the image in memory. I would just load the image, make the sprite, set the animation, size etc - then for each tile just clone that sprite, set the tile number, and position it. I've done tests with large areas, like probably over 100,000 sprites, enough sprites to proove that the image is not repeated anywhere.

Health, Ammo, and bacon and eggs!
Grook
AGK Backer
12
Years of Service
User Offline
Joined: 22nd Jun 2012
Location: Lancashire, England
Posted: 13th Jul 2012 16:33
Ah, excellent news, thanks for that Van B.

"Happiness is contrary to the human condition" --White (to Black)
Digital Awakening
AGK Developer
22
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 14th Jul 2012 19:19
It is faster to render if you have one large image (remember 1024x1024 is max) than having multiple small ones.

Login to post a reply

Server time is: 2024-11-23 18:18:16
Your offset time is: 2024-11-23 18:18:16