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!
Collision by color
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Collision by color
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/
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/
World needs love.
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 , 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:
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 , 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!'
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Collision by color
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.
The issues are detailed in older posts i don't wish to (most probably errorenously) explain here; maybe someone else will.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
- zorg
- Party member
- Posts: 3468
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Collision by color
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.
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.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re:
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
- Attachments
-
- per-pixel.love
- (39.29 KiB) Downloaded 220 times
World needs love.
-
- Citizen
- Posts: 87
- Joined: Tue Dec 30, 2014 6:07 pm
Re: Collision by color
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.
Code: Select all
character[x][y]
I know you want complicated shapes, but literally anything can be reduced into squares to produce non squares.
Who is online
Users browsing this forum: Ahrefs [Bot] and 7 guests