ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
364 stars 75 forks source link

Feature? Delete from TileMap #107

Closed paulloz closed 10 years ago

paulloz commented 10 years ago

Hi there! Wouldn't it be cool if we could delete objects from a TileMap no? Therefore a bunch of functions wourd be welcome:

One more thing to think about. What to do when there's more than one object on a tile? Delete the whole array?..

ippa commented 10 years ago

For simple cases you should be able to just do tile_map.at(x, y).pop() .. at()/cells() returns the internal array. That should work instead of popAsPoint and popFromCell() .. you could also just clear those cells.

popAsRect() is trickier and I think not possible right now, cause tile_map.atRect() returns a new list of objects included in the given rect.

I'm thinking something like: tile_map.cellForObject( your_game_object )...

Then you could do something like: tile_map.atRect(rect).forEach( function(object) { tile_map.cellForObject(object).pop(); // pop one object from each cell in the given rect });

Would break down for objects spanning many cells though.... Brainstorming so we can find the best API that would solve the problem with the least amount of new code/methods.

Can I ask, what's the usecase for "Pop one object from cells spanning this rect" ? Isn't that often a bit indiscriminate? Wouldn't you want to check object-types before you remove them.. or do you Know that the last object is the one you want to remove.

paulloz commented 10 years ago

Actually this is more an absolute reflection than a usecase I have.

I totally agree with you on popAsRect(), even if finding a decent usecase is possible. I.E. I usually work with several tilemaps representing several layers of objects. Let's say I want to implement a simple explosion, poping all objects in a rect (or a circle representing the explosion's range) could be a valid option.

Anyway, I didn't tried to .pop() arrays returned from at(). Seems that it responds to most of cases.

ippa commented 10 years ago

Cool.. then I guess you're set for now :). We can revisit the need for work on TileMap when certain needs pop up or when we get a clear idea how to solve things in the most effective way. Closing issue for now, if something new comes up with regards to this feel free to reopen.