Apologies, I raised this question at the end of a ‘solved’ post, so if you’ve read this before, again, sorry.
I’m making an endless runner. My ‘floor’ is made up of a table of objects like so:
local tile = {} local groundGroup = display.newGroup() for j = 1,21 do tile[j] = display.newRect( display.contentCenterX, 0, 50, 50) tile[j].x = 20 + (j\*50) tile[j].y = 469 tile[j]:setFillColor(1, 1, 1) tile[j].strokeWidth = 1 tile[j].alpha = 1 tile[j]:setStrokeColor( 0, 0, 0 ) physics.addBody(tile[j], "static",{ density=2, friction=0.3, bounce=0.0 } ) tile[j].collision = bounceEventGround tile[j]:addEventListener( "collision", tile[j] ) groundGroup:insert(tile[j]) end
Thanks
When my ‘character’ hits one of the tiles, I’m applying an event, like this:
local function bounceEventGround(self, event) if event.phase == "began" then self:setFillColor( 0.8, 0.4, 0.3 ) self.apha = 0.5
As you can see, I’m just changing the colour and altering the transparency… What I can’t seem to do, is associate a variable with ‘self’ for further logic… For example, if the same ‘self’ is in another collision, I want to remove it based on it’s alpha value being 0.5… Just an example:
elseif event.phase == "began" and self.alpha == 0.5 then self:removeSelf()
This doesn’t work
It would be nice if I could figure out how to associate variables with ‘tabled’ objects… Like:
self.hasBounced = 0 But this doesn’t work for me either.
I’ve been on this for a few hours, I’m struggling.