Checking pixels in tmx files
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Checking pixels in tmx files
I want pixel collision so much, but I don't know what to do...
All your code are belong to us.
- 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
The code I gave you is not working? Have you (or me) made something wrong? Because I'm 99% sure this new code should work. Oh, and in this code we check y before x, just so you know...szmol96 wrote:I want pixel collision so much, but I don't know what to do...
Re: Checking pixels in tmx files
I haven't tried it yet, but it looks a bit complicated to me.
All your code are belong to us.
- 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
I tried to make it really simple. All you need to do is replace your current code by this (make a backup, though, for safety):szmol96 wrote:I haven't tried it yet, but it looks a bit complicated to me.
(I also added comments for better understanding)
HugoBDesigner wrote:
On love.load:On love.update:Code: Select all
pixelmap = {} -- This is where the pixels will be stored for y = 1, #map do -- Checks each column for x = 1, #map[y] do -- Checks each line local a = map[y][x] -- Get the pixel from the map you already have if a == 1 then --Checks if the tile is "1" and if it should collide pixelmap[x.."-"..y] = true --Adds the tile to the collision detector, so you don't need to check every time end end end
Code: Select all
for y = math.max(1, playery-50), math.min(#map, playery+50) do --Checks each column around the player for x = math.max(1, playerx-50), math.min(#map[y], playerx+50) do --Checks each line around the player if pixelmap[x.."-"..y] then --Checks if the tile can collide --your collision code here end end end
The rest you already have (I think), so, since you already have a table for the map, it becomes a lot easier to solve problems
Re: Checking pixels in tmx files
OK, I will see it tomorrow. Thanks for your time and effort.
All your code are belong to us.
Re: Checking pixels in tmx files
I have found an alternate solution. Checking pixels in a 640x480 image doesn't lag, does it? So, I came up with the idea of dividing my map to 640x480 segments and only check the segment the player is currently in. I have made a table of the map segments.
How can I efficiently return the current map segment? So I could use it in the maskedPixel function.
Code: Select all
map = {
a1 = {
x = 0,
y = 0,
width = 640,
height = 480,
image = love.graphics.newImage("img/mapa1.png")
}
a2 = {
x = a1.x + a1.width,
y = a1.y,
width = 640,
height = 480,
image = love.graphics.newImage("img/mapa2.png")
}
b1 = {
x = a1.x,
y = a1.y + a1.height,
width = 640,
height = 480,
image = love.graphics.newImage("img/mapb1.png")
}
b2 = {
x = a1.x + a1.width,
y = a1.y + a1.height,
width = 640,
height = 480,
image = love.graphics.newImage("img/mapb2.png")
}
}
All your code are belong to us.
Who is online
Users browsing this forum: Bing [Bot], KayleMaster and 58 guests