Page 1 of 1
Collision by color
Posted: Sat Aug 05, 2017 10:43 am
by Hitsuji
Hi lövilin ones! Newcomer here.
Startin this week, when wrote my first '
Hellö Löve!', did advanced little by little, until this bump which made me claim for your knowledge.
The thing is, after some efforts I could make my character (a 32x32 rectangle) to say: when he steps in
white and when he steps in
black on a .png picture. Now been tryin to make the
white color be collidible (to only walks in black), but couldn't do it!
Just read a lot of tutorial about collisions and stuff, and a lot of tests... The majority is about tile/grid movement with I'd
dislike.
Hope to get a clue here!
This my first time programming something, can't give up, yet!
![Confused :?](./images/smilies/ms-confused.png)
Re: Collision by color
Posted: Sun Aug 06, 2017 12:15 am
by Мэтю
I suggest you to use some libraries that are made by community. A example is bump.lua by Kikito, which can be found here:
https://github.com/kikito/bump.lua
If you are willing to do your own collision system, you should read about AABB collision. Here are something that may help you:
https://www.gamedev.net/articles/progra ... nse-r3084/
Posted: Sun Aug 06, 2017 4:37 am
by Hitsuji
Afraidin that I was not clear.
I want help to make a collision in the colors of picture. This picture may contains polygonals forms, even formless, that's why the general collision tutorials won't help (they're mostly to non-circular shapes).
So, theres any way to declare a color a collision?
Don't send me tutorials
![Confused :?](./images/smilies/ms-confused.png)
, cause they're not specific to my issue.
Show how to compare a player position with a color in a picture, if it's possible.
This is how I did to get color by the character:
Code: Select all
if character then
local r, g, b = imgdata:getPixel(character.x, character.y)
if r == 255 then
print 'red!'
Re: Collision by color
Posted: Sun Aug 06, 2017 10:09 am
by zorg
The links provided shows you how you should code collisions, since doing it per-pixel has tons of issues to go with it.
The issues are detailed in older posts i don't wish to (most probably errorenously) explain here; maybe someone else will.
Posted: Sun Aug 06, 2017 5:35 pm
by Hitsuji
Erroneously?
![Huuh... :huh:](./images/smilies/ms-huh.png)
Well, checked this forum by a week, I may be missin a keyword in particular.
In my search, only found stuff about collidin Fixture and Tile-based objects.
So, problably, theres no way to call a color as collision, in Lua/Löve.
![Sad :(](./images/smilies/ms-sad.png)
Re: Collision by color
Posted: Sun Aug 06, 2017 6:13 pm
by zorg
i meant that if i were to detail why pixel-color based logic is bad i'd probably mess up in my explanation.
If you're adamant, there are ways; like loadig an image as an imagedata, and creating a table of pixels colors however you want, and using that table for collision checking; that does assume your image will be the only "map" so to speak, and it won't be modified.
Then again, i think image objects still have a refresh function that rebuilds them from the imagedata they were created from, so in that way, i guess you could update your "map" as well, though calling it every frame may be a bit hard on the framerate.
Re:
Posted: Sun Aug 06, 2017 6:15 pm
by Мэтю
Hitsuji wrote: ↑Sun Aug 06, 2017 5:35 pm
...
So, problably, theres no way to call a color as collision, in Lua/Löve.
There's a way, but maybe it has not a good performance. Btw, I was toying around with some code to try to satiate your doubt.
Then I come to a code that tries to do a collision pixel-per-pixel for a certain color. I'll attach it here, then you download and analyze if that is what you looking for.
It's a .love file, just rename it to "whateveryouwant.zip" and extract
Hope it helps you
![:Ultraglee :ultraglee:](./images/smilies/ms-ultra-glee.png)
Re: Collision by color
Posted: Sun Aug 06, 2017 8:54 pm
by Skeletonxf
If you want to get collisions from premade image files rather than whatever is on the screen you can make the images, then load them and then query over the entire image using
https://love2d.org/wiki/ImageData:getPixel in two for loops going through the x and y to decode them into a 1 pixel sized grid of squares using a nested table data structure you then use in the conventional way. You would be able to have something resembling
after decoding the images.
I know you want complicated shapes, but literally anything can be reduced into squares to produce non squares.