Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Can't remove bump body... — Gideros Forum

Can't remove bump body...

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.
Tagged:

Comments

Sign In or Register to comment.