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.

DarkBASIC Professional Discussion / Isometric 2D in DBPro using sprites?

Author
Message
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 23rd Sep 2011 21:46
Hey all,

I was just thinking about something here... I know you can have transparent sprites in DBPro, however is it possible to do a collision detect on a pixel-by-pixel basis with sprites?

Also, what would be a good way to check when to draw sprites first? (like say my player was in front of a wall rather than behind it, or vice versa)

Thanks!
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 23rd Sep 2011 22:57 Edited at: 23rd Sep 2011 22:59
Pixel perfect sprite collision is not supported natively by DBP. However there are a couple of ways of achieving it.

First off, the eXtends plugin for DBP includes pixel perfect sprite collision and is reasonably fast given how slow the technique normally is. However there are some issues including the need to use bmp images and restrictions on what sprite manipulation is supported.

Another approach would be to use DBP codes from the codebase (just do a search like this) or to write your own algorithm.

An alternative technique to pixel perfect collision detection is line collision detection. It is much more efficient and generally easier to code. At this point, I'm going to do a shameless plug for my LineMap Plugin. This is a plugin for DBP that supports all documented DBP sprite manipulations and provides a visual editor for you. However even if you don't want to use this, you could always write your own algorithm. The idea is that you create a virtual line around your sprites and then just check for line intersections.

Hope that helps with the options for collisions. On the issue of the order of drawing sprites, how about checking the y coordinate of the bottom of each sprite. The ones that have lower y coordinates could be drawn further back. I can't say I've tried anything like this.

If any of that doesn't make sense, do just ask. Good luck!

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 23rd Sep 2011 23:06
Thanks much! It all makes pretty good sense. I'm in no big rush to use isometrics in my game yet, but I figured it would be handy to know how to do in case I change my game design.

I might even do what you suggested with line collisions... I've done stuff like that in the past in 3D, but not to that extent.

AND BTW, what does your visual editor contain if you don't mind my asking?
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 24th Sep 2011 04:37
Glad that helps

Quote: "what does your visual editor contain if you don't mind my asking?"

The visual editor is for making "linemap files". Each sprite you use in my plugin has an accompanying linemap file that stores the data of how collisions should be detected. So, you load your sprites into the visual editor and draw the lines you want around the sprite. You then save these as a linemap file and load them in your DBP projects for detecting collisions.

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 00:16
Thanks!

I apologize for the late reply... but I've come to a conclusion that isometric drawings aren't necessarily at 45 degree angled, or rotated squares. Can anyone point me in the right direction to actually making good "tiles", with the bottom two lines being at the correct angle from center?
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Sep 2011 00:30 Edited at: 26th Sep 2011 00:36
For isometric tiles, the order of drawing the tiles is dependent on a few things....

- The type of isometric map. Slide, Staggered or Diamond


*The Mousemap is the same for all three but not the tile_walker
*Thee type of map will also change the tile_walker.
*Anchoring points are important.
*Blitting algorithm combined with tile_layering will vary slightly depending on the map type.

There is virtually no need for Pixel_Perfect Collisions... though I'll entertain any thoughts on why it would be needed.


I can help you out with this when you get to it.

Your signature has been erased by a mod please reduce it to 600 x 120.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Sep 2011 00:40
Quote: "Can anyone point me in the right direction to actually making good "tiles", with the bottom two lines being at the correct angle from center?"


it depends on how you want to utilize the space in your tile. Do you you want your tiles to have an automatic Height-edge to them, or completely flat?

Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 00:40
Well, I'm planning on re-making my commercial game to be isometric. The map layout will be diamond. I realized that the tile's are at a 2:1 ratio for the bottom lines, which now makes sense. (for every 2 pixels, go up 1)

The reason I'm doing this is I like the simplicity of 2D, but I also like the ability to have 8 directions my player can go in.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Sep 2011 00:43 Edited at: 26th Sep 2011 00:56
You may really want the map to be hex. It's not much different from doing ISO.

here is an example of flat iso tiles and built-in height-edge


It's not a great example of the right dimensions though.

and yes 2:1 is the proper ratio for seemless tiles. I also stick with using powers of 2 for sizes so... 64x32 or 128x64 or 256x128

Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 00:54
What are the advantages of hex over iso also? And can you show a hex tile example as well? (Not trying to ask for too much, just trying to figure out my options.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Sep 2011 01:01 Edited at: 26th Sep 2011 01:06
Quote: "What are the advantages of hex over iso also? And can you show a hex tile example as well? (Not trying to ask for too much, just trying to figure out my options"


tile-wise hex differs by splitting an iso tile in half and placing a rectangle inside it.


The dimensions don't loo exaclty right in text, but you get the idea.

Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 01:05
Oh, okay, that makes sense. But are hex tiles advantageous over iso?
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Sep 2011 01:09 Edited at: 26th Sep 2011 01:15
Visually, things look the same.

Gah,, nevermind. When I first read your above post I thought I read 6 directions rather than the 8 directions. but to continue.. it's a user interface type thing. the only thing that changes is movement through the map. RPG's and some Strategy games lend themselves beeter to hex

here's the height edge i was referring to with iso


Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 01:14
Ah, I see... thanks.
zenassem
23
Years of Service
User Offline
Joined: 10th Mar 2003
Location: Long Island, NY
Posted: 26th Sep 2011 01:17 Edited at: 26th Sep 2011 01:22
and here is height edges. Notice the tiles turning into a hex tiles. that's the other diffrence. You can do a simple edge to a regular iso tile (like that first row).



Your signature has been erased by a mod please reduce it to 600 x 120.
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 01:33
Ah, cool! For specialized items (chests, tables, some buildings and such), I'm going to have them be bigger than normal tiles, that way they don't have to be tiled but rather be individual tiles, that way I can save the amount of sprite work I have to do.

Also, what I'm doing is setting it up for line collision for individual tiles, which means I'm going to have to make a "map/tile editor" in a sense where you can draw collision lines on the tiles and output those out in a file that the game can read from. I'm already working on some ground tiles. My only concern now is how I am going to lay out/draw character sprites since they'll have 8 directions they can go in. N,S,E,W are easy directions, but the difficulty will be with NE,SE,NW,SW.
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 26th Sep 2011 05:24
Quote: "Also, what I'm doing is setting it up for line collision for individual tiles, which means I'm going to have to make a "map/tile editor" in a sense where you can draw collision lines on the tiles and output those out in a file that the game can read from."

Just for the record, this is exactly what my plugin does. The visual editor included works as you describe your "map/tile editor". So if you want to save a bit of time, you might want to use that, but I guess you might want to make it anyway.

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 05:28 Edited at: 26th Sep 2011 05:33
Well, one question I do have is can I use any size tile and how many lines can I set up per tile?

EDIT: Also, what's the license on this? I would like to make my game commercial as I've said a few times.
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 26th Sep 2011 08:33 Edited at: 26th Sep 2011 08:35
Quote: "can I use any size tile and how many lines can I set up per tile?"

Certainly, within reason. If you went for something monstrously large or really tiny you might need to ask me to change the zoom a bit so you could see what you were doing but there is no imposed limit. Again if you went for something involving lines longer than a 4 byte integer you'd run in to problems but again, that's not likely. Same goes for number of lines. There is no imposed limit so really, you're just talking about technical limitations. Again, best to keep within numbers handled by 4 byte integers.

Quote: "what's the license on this?"

It's free to use for any purpose whatsoever. The only caveat is that you're not allowed to sue me if it eats your hard drive of blows up your car. I keep meaning to make it open source too but there are a few things I want to do first that I've not had time to do yet... Like add comments...

EdzUp
23
Years of Service
User Offline
Joined: 8th Sep 2002
Location: UK
Posted: 26th Sep 2011 12:55
zenassem: To be honest you only ever really need the tallest tile you require, when rendering the whole landscape you place the tile at the height it should be and the next line render will 'hide' the sections of the tile that fall below the map. After you render everything you just add the nice border to the game arena if required to hide the side segments of the game arena.

So only the bottom tiles are required but the y position of the tile on screen is adjusted by the height of the section of the map to be drawn so if the ground is lower you move the tile down the screen to make it appear lower on the map.

-EdzUp
Graveyard Dogs
Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 26th Sep 2011 19:36
Quote: "Certainly, within reason. If you went for something monstrously large or really tiny you might need to ask me to change the zoom a bit so you could see what you were doing but there is no imposed limit. Again if you went for something involving lines longer than a 4 byte integer you'd run in to problems but again, that's not likely. Same goes for number of lines. There is no imposed limit so really, you're just talking about technical limitations. Again, best to keep within numbers handled by 4 byte integers."


Well, looking at the way this is designed, this could allow me to create levels in (maybe) a unique way, which would force me to create my own level editor.

Rather than having individual "tiles" for the most part, the background would be one big map with lines for boundaries. That would be at the bottom level of the map (level 1). Then would come stuff on the players surface which would be foreground objects that he could collide with directly (level 2). After that, there could be another level which can fully block the player, or if there's a way that he can access level 2 sprites (like a ramp), then he'd change to level 2 and collide directly with level 2 sprites, and so on and so forth in the sprite lineage.

But then one more thing I am wondering... Is it possible to detect which line you are colliding with using your plugin? Like say I have a particular line that is at the bottom of a ramp, and if my player collides with it, then it changes him to be at level 2.
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 26th Sep 2011 23:08
Quote: "Also, what would be a good way to check when to draw sprites first?"

What I do is queue all the sprites I want to draw into an array then right before the sync I run a sorting algorithm to sort the array based on the y coordinates plus any offsets (Example: Say you have a ball near the bottom of map but it gets kicked into the air but you still need it to be drawn last).

You can use any sorting algorithm but I'd recommended using Radix sort.

Here's a link to an old post I made with an example.
http://forum.thegamecreators.com/?m=forum_view&t=167651&b=4

WLGfx
18
Years of Service
User Offline
Joined: 1st Nov 2007
Location: NW United Kingdom
Posted: 26th Sep 2011 23:32
Iso maps are still using a 2D array, just shifted across each line. You still will only need to draw the base layer from top to bottom and left to right (actually right to left) without sorting as in a normal tile map. The next layer of sprites needing to be drawn will then have to be sorted by position as mentioned above, that way you can optimise your map tiles and drawing of them.

The height of the tiles will be saved along with the tile piece info so that you know the offset to draw the other layers of sprites at.

Warning! May contain Nuts!
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 27th Sep 2011 08:24 Edited at: 27th Sep 2011 08:26
Quote: "Is it possible to detect which line you are colliding with using your plugin?"

Yes and no. You can tell which "linemap" is colliding with which other "linemap". A linemap is a collection of as many lines as you choose. Linemaps may be created either in the visual editor or in DBP code on the fly. So if you had a particular line that you wanted to check for collisions for, you would be able to make a linemap containing just that line and check for collisions with that linemap. Depending on how you want this to work, you can also get the x, y coordinates of a linemap collision so that also might allow you to calculate which line was being touched although this might be more complex.

As for your idea of how to create your tile map using the system; it should certainly be possible to have a big background map. One of the examples, the mouse-maze game, uses a similar idea and there is a variant of the linemap collision detection command that is optimised for this situation by eliminating circle checking (that will always return true in these cases anyway). You'd have to code your own level code though as the plugin doesn't support anything like that.

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 27th Sep 2011 19:20
Okay, that would work! What I'm thinking about doing is including your linemap plugin as part of my editor I'm working on now (utilizing it to create the linemaps), provided you don't mind. Then after this use the plugin for the game itself.
Lucas Tiridath
AGK Developer
17
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 28th Sep 2011 02:16
Sounds great! Do keep me posted on how you find using it. If you run in to any issues, just let me know on this thread or on the plugin's thread so that I'll see and hopefully be able to help. Good luck with the whole project too!

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 28th Sep 2011 02:54 Edited at: 28th Sep 2011 02:55
Thanks! Will do most definitely! I'm running into issues with the editor itself though, namely trying to make text prompts for input. They work, but then none of my sprites show up after I run them. I'm coming to a conclusion that sprites seem finicky in DBP and are almost illogical in their layout.
Ashingda 27
18
Years of Service
User Offline
Joined: 15th Feb 2008
Location:
Posted: 28th Sep 2011 03:58
Sprites are awesome in dbpro you just got to manually handle them such as pasting the sprite rather than using the other native sprite commands.

Pincho Paxton
23
Years of Service
User Offline
Joined: 8th Dec 2002
Location:
Posted: 28th Sep 2011 04:15
Everything sounds like a Sync problem somewhere.

Da_Rhyno
15
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 28th Sep 2011 04:22
Yeah... but the most recent problem actually seems to be a problem with the file I'm giving not being recognized for some reason. Check out my most recent thread in the Newcomers Forum for details... maybe you can help.

Login to post a reply

Server time is: 2026-07-11 14:37:08
Your offset time is: 2026-07-11 14:37:08