So I'm working on a little game idea that I had last night (and wrote down on a computer mouse box so i wouldnt forget XD) but I've run into a snag.
Basically, im new to Tiled and STI so I dont know how to do this:
I want my player to, when he collides with a colored "door", he also becomes that color, and then when he is the same color as a colored door, he cant pass through any door of the same color. Can someone give me a bit of help?
How to get color from tile
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
How to get color from tile
- Attachments
-
- Sprite Color Test.love
- (494.14 KiB) Downloaded 64 times
Re: How to get color from tile
I didn't look at your code, but i saw bump.lua in there, so i'll assume you're using that for collision.
With bump you'd move the player with something like
"cols" is a table, containing a list of collisions that occured during the move. Each collision is a table containing various information about the collision, one of which is cols.other, That's a reference to the other bump object the player collided with. If your "door" tiles contain their own colors, you can access it with that. As for letting the player only pass through doors of certain colors, that can be done with filters. It's all explained pretty well on github.
With bump you'd move the player with something like
Code: Select all
x, y, cols, len = world:move(player, nx, ny, filter)
Re: How to get color from tile
veethree wrote:I didn't look at your code, but i saw bump.lua in there, so i'll assume you're using that for collision.
With bump you'd move the player with something like"cols" is a table, containing a list of collisions that occured during the move. Each collision is a table containing various information about the collision, one of which is cols.other, That's a reference to the other bump object the player collided with. If your "door" tiles contain their own colors, you can access it with that. As for letting the player only pass through doors of certain colors, that can be done with filters. It's all explained pretty well on github.Code: Select all
x, y, cols, len = world:move(player, nx, ny, filter)
aaye your response came just in time XD I'd decided that I was going to work on this problem till 2 am, then if no one responded or i couldnt figure it out, id go to sleep, its 1:45 am right now
yeah i do use bump and have the x, y, cols, len = world:move(player, nx, ny, filter) in my code, however i dindt have the "len" or "filter" parts added, I just started using bump and STI today, and tiled the day before, so I still have no idea what im doing XD someone on #love helped me set up what i have so far haha.
I'll take a look at the github, hopefully i can get this working
Re: How to get color from tile
veethree wrote:I didn't look at your code, but i saw bump.lua in there, so i'll assume you're using that for collision.
With bump you'd move the player with something like"cols" is a table, containing a list of collisions that occured during the move. Each collision is a table containing various information about the collision, one of which is cols.other, That's a reference to the other bump object the player collided with. If your "door" tiles contain their own colors, you can access it with that. As for letting the player only pass through doors of certain colors, that can be done with filters. It's all explained pretty well on github.Code: Select all
x, y, cols, len = world:move(player, nx, ny, filter)
so would having the doors set as tiles in Tiled, and just doing something like giving them string properties for their color work? I would it be better to add them in with world:add, and just place them at assigned "door" objects or something? Gahh idk ><
Re: How to get color from tile
Vimm wrote:veethree wrote:I didn't look at your code, but i saw bump.lua in there, so i'll assume you're using that for collision.
With bump you'd move the player with something like"cols" is a table, containing a list of collisions that occured during the move. Each collision is a table containing various information about the collision, one of which is cols.other, That's a reference to the other bump object the player collided with. If your "door" tiles contain their own colors, you can access it with that. As for letting the player only pass through doors of certain colors, that can be done with filters. It's all explained pretty well on github.Code: Select all
x, y, cols, len = world:move(player, nx, ny, filter)
so would having the doors set as tiles in Tiled, and just doing something like giving them string properties for their color work? I would it be better to add them in with world:add, and just place them at assigned "door" objects or something? Gahh idk ><
You probably want to do both, or at least add them to bump. How are you notice collisions otherwise?
And string Color properties are a good idea.
Re: How to get color from tile
s-ol wrote:Vimm wrote:veethree wrote:I didn't look at your code, but i saw bump.lua in there, so i'll assume you're using that for collision.
With bump you'd move the player with something like"cols" is a table, containing a list of collisions that occured during the move. Each collision is a table containing various information about the collision, one of which is cols.other, That's a reference to the other bump object the player collided with. If your "door" tiles contain their own colors, you can access it with that. As for letting the player only pass through doors of certain colors, that can be done with filters. It's all explained pretty well on github.Code: Select all
x, y, cols, len = world:move(player, nx, ny, filter)
so would having the doors set as tiles in Tiled, and just doing something like giving them string properties for their color work? I would it be better to add them in with world:add, and just place them at assigned "door" objects or something? Gahh idk ><
You probably want to do both, or at least add them to bump. How are you notice collisions otherwise?
And string Color properties are a good idea.
i ended up just making the objects in tiled and then drawing rectangles for the doors(for now). also managed to get the color swapping, only thing i really need to do now is figure out how to change the Tiled objects "collidable" property to true.
Re: How to get color from tile
well thats what I thought you were doing lol.Vimm wrote:s-ol wrote:You probably want to do both, or at least add them to bump. How are you notice collisions otherwise?Vimm wrote:
so would having the doors set as tiles in Tiled, and just doing something like giving them string properties for their color work? I would it be better to add them in with world:add, and just place them at assigned "door" objects or something? Gahh idk ><
And string Color properties are a good idea.
i ended up just making the objects in tiled and then drawing rectangles for the doors(for now). also managed to get the color swapping, only thing i really need to do now is figure out how to change the Tiled objects "collidable" property to true.
I wouldn't set the a .collidable = true on all the doors every time you change color. Just check in your world:move filter
Code: Select all
world:move(player, ...., function (player.color, other)
if other.type == "door" and other.color ~= player.color then return nil end
return "slide"
end)
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 200 guests