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.

Newcomers AppGameKit Corner / Some tileset questions

Author
Message
DaRealWAZY
7
Years of Service
User Offline
Joined: 26th Sep 2017
Location:
Posted: 23rd Oct 2017 13:02
I have been reading the documentation but for some reason either I missed it completely or it is not there but how do I use a tileset called tileset.png

Like first how do I split it up into the different tiles, it has 16 tiles in a row and 12 rows of image data on a 512 by 384 pixels. I mean like I said I could of missed it or couldn't find an example in the examples section but this would be very useful as I have around 32gb's of game resources and a lot of them are for RPG games and they have a whole lot of spritesheets in png format. I just figured to use the assets I have for prototyping instead of making the assets myself tbh
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 23rd Oct 2017 14:06
You could do something like CopyImage and loop through spritesheet.

This " 16 tiles in a row and 12 rows of image data on a 512 by 384 pixels", what do you mean? 16 columns and 12 rows?

Here is some code that will compile directly but you can get the idea.

13/0
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 23rd Oct 2017 15:36
The easiest way to use a tileset at the moment is to use Tiled to draw your map and use importer code (search forum there is lots of TMX importers out there) to draw the map in AppGameKit, most people end up writing there own map editors its a relatively simple process once you know your way round the function set.

in short a tile is simply a sprite setup the same as an animated sprite 'SetSpriteAnimation' and it displays a tile from your tileset with 'SetSpriteFrame'



Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 23rd Oct 2017 22:41 Edited at: 23rd Oct 2017 23:11
Quote: "You could do something like CopyImage and loop through spritesheet."


That is what I was thinking too, only I would save using the array for the layout of the map.

Just make a set of sprites from the sprite sheet then make a little map editor to clone the sprites for the array for the map grid.

Quote: "his " 16 tiles in a row and 12 rows of image data on a 512 by 384 pixels", what do you mean? 16 columns and 12 rows?"

Yes, from his dimensions given, they are 32 x 32 pixels for each image.

My code is like yours but a bit different for the example... (image is attached to run this code if you want)



I am using a temporary counter to go from 1 to 192 for the images, and each sprite being created is using an image assigned with the same number.

You can use the up and down arrow keys to cycle through the tiles. (notice that I resized the sprites to 64 x 64 to make them easier to see)

You can see the nested loop is like his, 16 inside of 12, because we increment the x position in the inner loop for each column.

Then, the outer loop is dropping down a row by an increment to the y position for the copied image.

Notice you have to reset the x position back to 0 each time you start the outer loop so we start our new row back at the starting position.

Like I said, I would save the array for the actual layout of the map for a logical order for the sprites made from the sprite sheet that are being cloned for the array.

That way, the array would be set up logically for the grid of the map and not the sprite sheet, but it can be set up multiple ways so it doesn't really matter.

That is just one way of doing it, and it would really depend on the map editor being used as to how you want to load these images and build your array.

As PartTimeCoder says, there should be some great tools for map making already in the forums that you will find by searching.

If you replace my image with yours, then you will cycle through your tiles with the sprite number being shown for each one.

I thought that numbering an image for you would help you understand how we are copying these images.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1

Attachments

Login to view attachments
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 24th Oct 2017 09:28
A map? Oh, I read it as he wanted something like a character sprite :-P
13/0
DaRealWAZY
7
Years of Service
User Offline
Joined: 26th Sep 2017
Location:
Posted: 24th Oct 2017 11:19
yea I should of being more specific but yea basically it's a bunch of images used for creating a map. Just trying to figure out if I want to hard code my maps or use a map editor like tiled
Cybermind
Valued Member
21
Years of Service
User Offline
Joined: 28th Nov 2002
Location: Denmark
Posted: 24th Oct 2017 12:02
If you are going to make multiple large maps, then a map editor is great. A few small maps can be hardcoded.
13/0
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd Nov 2017 04:52
Quote: "Like first how do I split it up into the different tiles, it has 16 tiles in a row and 12 rows of image data on a 512 by 384 pixels."


_mySprite = createsprite(loadimage("tileset.png"))

setSpriteAnimation(_mySprite , 32, 32, 192)

Determine the size of your tiles:
512 / 16 = 32
384 / 12 = 32

The last number is how many tiles you have in your sprite sheet: 16*12 = 192

Now you can clone that sprite all you want and it'll share that same texture. Then use setSpriteFrame() to set the desired tile for that particular sprite.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-11-22 20:18:17
Your offset time is: 2024-11-22 20:18:17