Hey guys,
I'm working on a project that uses a tilemap, and right now my code creates a rectangle for each tile for the player to collide with. I keep them each small enough that they don't collide with each other to improve framerate, but close enough that the player still cannot pass through them. With only a 20x20 tilemap my framerate drops to 6. (3 if I leave the tiles big enough to collide with each other) Is there something else I need to do? I can upload my .love if you want, but what I am doing is fairly simple, just an extra step that resembles the draw loop to create a rectangle for each tile.
Do I need to write an algorithm to create a single collision object for the whole tilemap (or each clump of collidable tiles)? If that's what I need to do does anyone know how to do that?
Thanks
Hardoncollider with tilemap
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Hardoncollider with tilemap
It was the best of times, it was the worst of times . . .
Re: Hardoncollider with tilemap
There's HC:setPassive(shape, ...).
You should upload the .love anyway, maybe there's something else that could be done better.
Sometimes it will also help to increase the cell size (in the constructor).This enables you to significantly speed up the collision detection. Typical candidates for passive shapes are those which are numerous, but don't act in themselves, e.g. the level geometry.
You should upload the .love anyway, maybe there's something else that could be done better.
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Hardoncollider with tilemap
I found Hardon Collider unsuitable for tiled maps when I was creating a Bomberman clone.
Using groups and settings shapes as ghosts or passive helps a lot though.
Using groups and settings shapes as ghosts or passive helps a lot though.
Re: Hardoncollider with tilemap
OK, I added it to my code so it now looks like this:
Unfortunately, I get this error: Attempt to call method 'setPassive' (a nil value).
Code: Select all
for x = 1, shipmap.width do
for y = 1, shipmap.height do
if shipmap[x][y].type ~= 0 then
shipmap[x][y].col = collider:addRectangle(x*img.tileset1.tilesize, y*img.tileset1.tilesize,
img.tileset1.tilesize, img.tileset1.tilesize)
HC:setPassive(shipmap[x][y].col)
end
end
end
It was the best of times, it was the worst of times . . .
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Hardoncollider with tilemap
Edit: fixed for posterity.
Don't call setPassive on HC, call it on the collider. collider:setPassive(shipmap[x][y].col)
Don't call setPassive on HC, call it on the collider. collider:setPassive(shipmap[x][y].col)
Last edited by tentus on Mon Mar 26, 2012 11:20 pm, edited 2 times in total.
Kurosuke needs beta testers
Re: Hardoncollider with tilemap
The code is correct (as documented), at least with newish HC versions. However, from what you've posted it's not possible to tell what is going wrong. Please post a .love.
Re: Hardoncollider with tilemap
OK, attached a .love.
There are some things there that are only placeholder, or not used yet. You can probably easily tell which parts are mean to be fairly permanent and which are just temporary solutions. Please let me know how my coding style is, I'm still a beginner.
Thanks!
There are some things there that are only placeholder, or not used yet. You can probably easily tell which parts are mean to be fairly permanent and which are just temporary solutions. Please let me know how my coding style is, I'm still a beginner.
Thanks!
- Attachments
-
- tilemap.love
- (47.19 KiB) Downloaded 101 times
It was the best of times, it was the worst of times . . .
- TechnoCat
- Inner party member
- Posts: 1611
- Joined: Thu Jul 30, 2009 12:31 am
- Location: Denver, CO
- Contact:
Re: Hardoncollider with tilemap
To clarify: shapes are separate from HC. Setting a shape passive wouldn't make sense. You tell HC a certain shape that will be hashed to a unique ID to be passive inside of HC.tentus wrote:Don't call setPassive on HC, call it on the thing that is becoming passive. (shipmap[x][y].col)
- tentus
- Inner party member
- Posts: 1060
- Joined: Sun Oct 31, 2010 7:56 pm
- Location: Appalachia
- Contact:
Re: Hardoncollider with tilemap
Sorry, I changed my mind about how I wanted to word my post and posted it without finishing my changes (I really don't know why).
As is often the case, collider and HC have gotten mixed around. If you change line 136 of world.lua to this: you won't get a bluescreen.
As is often the case, collider and HC have gotten mixed around. If you change line 136 of world.lua to this:
Code: Select all
collider:setPassive(shipmap[x][y].col)
Kurosuke needs beta testers
Re: Hardoncollider with tilemap
Thanks so much, it works!
It was the best of times, it was the worst of times . . .
Who is online
Users browsing this forum: No registered users and 206 guests