MichaelSinsbeck / platformer

A ninja platformer written in LÖVE
7 stars 0 forks source link

[LE] Get a "selection preview" in background tile panel #174

Closed michalove closed 10 years ago

michalove commented 10 years ago

In the panel for the background tiles, the user can drag a box around multiple tiles. I think the panel should already mark those tiles that would be selected, if the mouse button is released (similar to the behavior of a desktop manager: When you drag a box, then all icons inside are already marked, even before you release the mouse button).

While the mouse button is down, each frame, first all tiles should get unselected and then all those tiles, that are inside the box, should be selected.

Could you implement this?

Germanunkol commented 10 years ago

Done. Feel free to modify the colors to your liking in function "drawPreviewOutline" and "drawOutline" in editor/clickable.lua. It feels a bit weird that the selection preview doesn't appear while selecting stuff on the canvas...

michalove commented 10 years ago

Would it be difficult to add the selection preview to stuff on the canvas?

Germanunkol commented 10 years ago

I think so, yes. I could "cheat" by simply drawing an outline around every tile inside the selection box. But actually checking which tiles are selected is currently done by a brute-force approach (check all tiles against the current positions). This is easily fast enough if only done once the mouse is released. But adding it to every frame while drawing the selection box would be bad - especially since a check is done for every tile inside the box. Hum. At this point during writing I noticed that this could be sped up immensely if I only check once for all objects inside the box, instead of checking every tile inside the box if there's an object on it. Why I didn't do this in the first place is beyond me. Probably because the click-to-select function was already coded and so I just called that for every tile inside the box. Stupid me. Good that you asked.

Maybe I'll try this in the next few days.

michalove commented 10 years ago

Do you know, how often this happens to me? I start writing that something will be difficult and while I explain why, it find out, it is actually very simple....

Germanunkol commented 10 years ago

Done. Let me know if it works for you.

Edit: I should note: At the moment, when there are more objects above each other, then the selection box (green) gets less transparent. This doesn't look perfect, but it gives a quick overview of the places where there are multiple objects behind each other - and I like that, so I left it in there.

michalove commented 10 years ago

It works very well and feels good. We will have to fix the exact position of the highlighting. It is off, for many objects. That will be a separate issue, though.

Good job.