Ive decided to take a look at the director class and am having troubles understanding how to do what Im trying to do. I have a character that can run around screen and touch things. Before I decided to use the director class, I had a version that was capable of touching a money object and have it disappear. Simple. Now that Im trying to use director, things get a little complicated.
So I understand that Im supposed to place everything in localGroup for removal reasons, right? The problem is that Im not sure how Im supposed to go about this for these simple external lua files like this one.
Here are excerpts of my pre-director code from the game.lua
local money = {}
local newMoney = require("money");
local function spawnMoney(x,y)
local m = newMoney.new();
money[m] = m
money[m].x = x
money[m].y = y
money[m].remove = true;
end
spawnMoney(300,250);
spawnMoney(200,200);
And now from money.lua
module(..., package.seeall);
function new()
money = display.newImage("green.png", 0, 0)
physics.addBody ( money, "static", {isSensor = true} )
function getMoney(self,event)
if event.phase == "began" and event.other.type == "player" then
print ("$$$")
money:removeSelf()
elseif event.phase == "ended" and event.other.type == "player" then
end
end
money.collision = getMoney
money:addEventListener( "collision", money )
return money;
end
The purpose is to jump, touch, have it disappear and print $$$ in the terminal. It worked fine pre-director, but now after numerous attempts at getting it to work, the best I can do is have the money at (200,200) disappear, and then it will throw me a “attempt to call method ‘removeSelf’(a nil value)”.
Ive tried to put everything I can think of into the localGroup both inside game.lua and money.lua one at a time, to no avail. Anyone have any ideas as to what Im doing wrong? [import]uid: 67886 topic_id: 11406 reply_id: 311406[/import]