thanks, I tried implimenting the code you suggested but I’m getting an error ‘)’ expected near ‘:’ on line 165 (line 8 below) which is the line with “local function b:touch(e)”
[code]
local function spawn(e)
if(ready == true) then
i = i + 1;
local rand = m.random(1,6);
local colour = beanColours[rand];
local b = bean.newBean(colour);
local function b:touch(e)
if(e.target.touchEnabled == true) then
local t = e.target
local phase = e.phase
if “began” == phase then
– Make target the top-most object
local parent = t.parent;
parent:insert( t );
display.getCurrentStage():setFocus( t );
– Spurious events can be sent to the target, e.g. the user presses
– elsewhere on the screen and then moves the finger over the target.
– To prevent this, we add this flag. Only when it’s true will “move”
– events be sent to the target.
t.isFocus = true;
– Store initial position
t.x0 = e.x - t.x;
t.y0 = e.y - t.y;
elseif t.isFocus then
if “moved” == phase then
– Make object move (we subtract t.x0 so that moves are
– relative to initial grab point, rather than object “snapping”).
t.x = e.x - t.x0;
–t.y = e.y - t.y0;
elseif “ended” == phase or “cancelled” == phase then
display.getCurrentStage():setFocus( nil );
t.isFocus = false;
end
end
– Important to return true. This tells the system that the event
– should not be propagated to listeners of any objects underneath.
return true;
end
end
local function b:collision(e)
if (e.other.type == “floor” or e.other.type == “bean”) then
e.target.touchEnabled = false;
end
touchCheck(e);
matchCheck(e);
end
b:addEventListener(“collision”, b);
b:addEventListener(“touch”, b);
beans[i] = b;
foreground:insert(beans[i]);
end
end
[/code] [import]uid: 31694 topic_id: 18324 reply_id: 91237[/import]