Hi dudes!
Trying to get my head back into Gideros but still making some rookie mistakes I think..
I'm adding treasure to my game and everything's going well only, I can't remove the treasure body when the player collides... This is what I'm doing:
treasure = GameScene:generateTreasure()
treasure.name = "treasure"
print("I gots points! "..treasure.points)
treasure.isCoin = true
GAME:addChild(treasure)
world:add(treasure, xCoord, yCoord + 15, treasure:getWidth(), treasure:getHeight()) -- x, y, w, h
print(treasure)
function GameScene:generateTreasure()
if GameScene.round == 1 then
treasure = (Bitmap.new(Texture.new("images/gold1.png")))
treasure.points = 400
else
-- Moar points.
end
return treasure
end |
Then in my controls function:
for i = 1, len do -- If more than one simultaneous collision, they are sorted out by proximity
local col = cols[i]
print("Collision with "..col.other.name)
print(col.type)
if col.other.name == "treasure" then
print("Yay! "..col.other.points)
GameScene:collectTreasure(col, col.other.points)
end
end
function GameScene:collectTreasure(treasure, points)
print("Knowledge was their treasure, their treasure was knowledge, treasure. Knowledge. Treasure = "..points)
GameScene:addPoints(points)
GameScene:removeTreasure(treasure)
end
function GameScene:removeTreasure(treasure)
print("HAYA!")
print(treasure)
-- Getting the same table as the one I'm adding here using world:add(treasure ...)
world:remove(treasure) -- DENIED!
treasure:removeFromParent()
treasure = nil
end |
I'm getting the old
"Item table: 0x7f850fbbfd90 must be added to the world before getting its rect. Use world:add(item, x,y,w,h) to add it first." error, not sure what I'm doing wrong.
Comments
https://i.imgur.com/3V4xtjD.png
I must be running low on caffeine.
Likes: antix
Likes: Astirian
Likes: antix