module (..., package.seeall);
function new()
local mosca = display.newImage("media/mosca.png");
mosca.x = 0; mosca.y = 100;
mosca.xScale = 0.2; mosca.yScale = 0.2;
local remove\_monster = function( obj )
obj:removeSelf();
end
function touch(e)
if (e.phase == "ended") then
-- mosca.isVisible = false;
transition.to( e.target, { time=1, alpha=0, onComplete=remove\_monster } )
end
end
function animate(e)
local rand\_x = math.random(20,580);
local rand\_y = math.random(20,300);
--mosca.x = rand\_x;
transition.to( mosca { time=500, x=120 } )
end
Runtime:addEventListener("enterFrame", animate);
mosca:addEventListener( "touch", touch );
return mosca;
end
Hi everybody,
I have this code… all it’s ok, but when i call the
function animate(e)
local rand\_x = math.random(20,580);
local rand\_y = math.random(20,300);
--mosca.x = rand\_x;
transition.to( mosca { time=500, x=120 } )
end
in details the function
transition.to( mosca { time=500, x=120 } )
i cannot access to the mosca variable… Someone can help me?
What i need is to animate various enemy in a screen…
I post the main.lua source too…
local mosca = require("mosca");
local enemy = {}
-- populate enemy array and dispose enemy
for a = 1, 2 do
local rand\_x = math.random(0,580);
local rand\_y = math.random(0,300);
enemy[a] = mosca.new(); -- create new instance
-- positioning
--if a \>= 2 then
-- enemy[a].move( (a\*90) )
--end -- end positioning
-- Runtime:addEventListener( "animate", enemy[a].animate );
end -- end for
local function someFunction()
for i=1,#enemy do
local rand\_x = math.random(20,580);
local rand\_y = math.random(20,300);
if (enemy[i].x \< rand\_x) then
enemy[i].xScale = -0.2
else
enemy[i].xScale = 0.2
end
transition.to( enemy[i], { time=1000, transition = easing.inQuad, x=rand\_x, y=rand\_y } )
end
transition.to( enemy[#enemy], { time=500, x=rand\_x, y=rand\_y, onComplete=someFunction } )
end
--someFunction()
P.s. in this code i’m using the someFunction for animate the object, but i DON’T WANT to use this function in the main.lua… I like to have the animation code in the mosca.lua file!!
thanks.
This is the error:
[C]: in function ‘mosca’
…o\documents\corona projects\mosca-cojonera\mosca.lua:24: in function
<…o error> …o\documents\corona projects\mosca-cojonera\mosca.lua:24: attempt to c
all upvalue ‘mosca’ (a table value)
stack traceback:
[C]: in function ‘mosca’
…o\documents\corona projects\mosca-cojonera\mosca.lua:24: in function
<…o error> …o\documents\corona projects\mosca-cojonera\mosca.lua:24: attempt to c
all upvalue ‘mosca’ (a table value)
stack traceback:
[C]: in function ‘mosca’
…o\documents\corona projects\mosca-cojonera\mosca.lua:24: in function
<…o topic_id: reply_id:></…o></…o></…o>
