How to get color from tile

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

How to get color from tile

Post by Vimm »

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? :)
Attachments
Sprite Color Test.love
(494.14 KiB) Downloaded 64 times
User avatar
veethree
Inner party member
Posts: 875
Joined: Sat Dec 10, 2011 7:18 pm

Re: How to get color from tile

Post by veethree »

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

Code: Select all

x, y, cols, len = world:move(player, nx, ny, filter)
"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.
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: How to get color from tile

Post by Vimm »

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

Code: Select all

x, y, cols, len = world:move(player, nx, ny, filter)
"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.


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 :P

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 :D
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: How to get color from tile

Post by Vimm »

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

Code: Select all

x, y, cols, len = world:move(player, nx, ny, filter)
"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.


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 ><
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to get color from tile

Post by s-ol »

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

Code: Select all

x, y, cols, len = world:move(player, nx, ny, filter)
"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.


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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Vimm
Party member
Posts: 113
Joined: Wed Mar 16, 2016 8:14 pm

Re: How to get color from tile

Post by Vimm »

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

Code: Select all

x, y, cols, len = world:move(player, nx, ny, filter)
"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.


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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: How to get color from tile

Post by s-ol »

Vimm wrote:
s-ol wrote:
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 ><
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.
well thats what I thought you were doing lol.

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)

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 200 guests