Checking pixels in tmx files

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
szmol96
Citizen
Posts: 51
Joined: Mon Oct 07, 2013 4:24 pm
Location: Horvátkút, Hungary

Checking pixels in tmx files

Post by szmol96 »

Hi. I am working on an engine for my later games and I'm using getPixel on a map image for collision detection, but have I realised that if my image would be larger, it would take more time to check for collisions. So I came up with the idea of checking pixels in tmx maps. Is that possible? If so, please tell me how to do it. Thanks in advance.
All your code are belong to us.
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Checking pixels in tmx files

Post by Kingdaro »

Checking individual pixels in a map for collision detection is a rather slow way of doing things. Why not use a collision layer? As in, an invisible layer with a bunch of shapes denoting where the collisions are. Something like this:

Image
Image

(from here)
User avatar
szmol96
Citizen
Posts: 51
Joined: Mon Oct 07, 2013 4:24 pm
Location: Horvátkút, Hungary

Re: Checking pixels in tmx files

Post by szmol96 »

I know, but I want to experiment a bit with the different kinds of collision systems, starting with the easiest ones to implement. I have tried tile based so far, but I didn't like it, because it didn't give me enough freedom.
All your code are belong to us.
User avatar
Murii
Party member
Posts: 216
Joined: Fri Jul 05, 2013 9:58 am
Location: Arad, Romania
Contact:

Re: Checking pixels in tmx files

Post by Murii »

szmol96 wrote:Hi. I am working on an engine for my later games and I'm using getPixel on a map image for collision detection, but have I realised that if my image would be larger, it would take more time to check for collisions. So I came up with the idea of checking pixels in tmx maps. Is that possible? If so, please tell me how to do it. Thanks in advance.
Uh what? This is a bad idea for checking collision detection :))
User avatar
szmol96
Citizen
Posts: 51
Joined: Mon Oct 07, 2013 4:24 pm
Location: Horvátkút, Hungary

Re: Checking pixels in tmx files

Post by szmol96 »

Ok, I will listen to you guys, pixel collision may be slow, but i don't know how to make any other collision system, except tile based. The one with polygons sounds good, but I have no idea how to implement it. Can somebody explain it, including the details?
All your code are belong to us.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Checking pixels in tmx files

Post by micha »

I wouldn't say, that pixel based collision is bad per se. But it is probably not easy to implement.

The same goes for vector based collision. It is not easy to implement. I would rather use a library that does it for me, such as the love.physics module.

This article gives a nice comparison of the general approaches to collision detection.

In the Free Game Resources Section of the wiki you finde some in depth tutorials on collision detection with different approaches.
User avatar
szmol96
Citizen
Posts: 51
Joined: Mon Oct 07, 2013 4:24 pm
Location: Horvátkút, Hungary

Re: Checking pixels in tmx files

Post by szmol96 »

Pixel collision will be fine for me, but how can I make it faster if I plan on making huge levels?
All your code are belong to us.
User avatar
HugoBDesigner
Party member
Posts: 403
Joined: Mon Feb 24, 2014 6:54 pm
Location: Above the Pocket Dimension
Contact:

Re: Checking pixels in tmx files

Post by HugoBDesigner »

The problem with pixel collision is that it is slow under most circumstances. Making the computer check thousands of pixels everytime is slow. Are you checking them every frame? If you are, just compare the pixels in an area close to the player (for example, pixels in a radius of 50 pixels around the player). Depending on what you have this can work very well :)
@HugoBDesigner - Twitter
HugoBDesigner - Blog
User avatar
Kingdaro
Party member
Posts: 395
Joined: Sun Jul 18, 2010 3:08 am

Re: Checking pixels in tmx files

Post by Kingdaro »

szmol96 wrote:Pixel collision will be fine for me, but how can I make it faster if I plan on making huge levels?
That's pretty much the tradeoff of using such an expensive algorithm. Either keep your levels small, use polygons, or don't use LOVE.

Depending on the level of detail and intricacy in your game, a good method for you would be to use the love.physics module along with using tiled maps with a library like STI, then using object layers in Tiled for collision zones.
User avatar
szmol96
Citizen
Posts: 51
Joined: Mon Oct 07, 2013 4:24 pm
Location: Horvátkút, Hungary

Re: Checking pixels in tmx files

Post by szmol96 »

HugoBDesigner wrote:The problem with pixel collision is that it is slow under most circumstances. Making the computer check thousands of pixels everytime is slow. Are you checking them every frame? If you are, just compare the pixels in an area close to the player (for example, pixels in a radius of 50 pixels around the player). Depending on what you have this can work very well :)
I only check pixels around the player and at some bullets' position. Is that still slow?
All your code are belong to us.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot], Majestic-12 [Bot] and 165 guests