@James,
The problem is that I have to dynamically build the transition parameters, as I don’t know what they are. I don’t know if its x,y, alpha,So I can’t manage to work with this approach…
tableFirst[1].transitionParams = {db.Param1=db.value1, db.Param2=db.value2, onComplete=function() tableFirst[1].params["onComplete](onCompleteParams) end ;}
It has to be built up like this otherwise I can’t manage to get the params from the db to work.
tst1 = display.newRect(100,100,100,100)
local tableFirst = {}
local test = nil;
test = function(id)
print(id)
end
local params = {
--This would be generated by the recordset from the db....
[db.param] = db.value,
[db.param] = db.value,
["onComplete"] = function(obj) test(db.id) end
}
tableFirst[1] = {}
tableFirst[1].transitionFunction = function() transition.to(tst1,params); end
tableFirst[1].transitionFunction(1);
Thats the only way I could get this to work with data from the db, but the function is still returning nil for me…I am maybe having the wrong approach, but I am looping five objects here and it seems that my original function messes pup all params. So I was thinking that it is maybe better to put all code in tables, and then execute…
This is my original code that seems to lose the params…
[code]
local singleAnimationfromDB = function ( event , imgname )
local no = 1
local group = {}
if isRunning == false then
isRunning = true
local sqlStr = “”
if( event==“TIME”) then
–Börja med att kolla hur många grupper det finns att animera
for row in db:nrows(“select distinct animGroup, count(*) from Animation where refid=” … animalID … " and swap=0 and isTouch=0 group by animGroup, refid") do
group[#group+1] = row.animGroup
end
if #group > 0 then
local ranGroup = math.random(#group)
sqlStr = “SELECT Animation.image, Animation.expression, Stagedata.layer, Animation.xRef, Animation.yRef, Stagedata.tag from Animation join Stagedata on stagedata.refid = Animation.refid where Animation.animGroup = " … group[ranGroup] … " and Animation.swap=0 and Animation.image = Stagedata.img and Animation.refId=” … animalID
end
elseif(event==“TOUCH”) then
–Hämta upp grupperna om det finns några
for row in db:nrows(“SELECT Animation.image, Animation.expression, Stagedata.layer, Animation.xRef, Animation.yRef, Stagedata.tag, Animation.animGroup from Animation join Stagedata on Stagedata.refid = Animation.refID where Animation.image = '” … imgname … “’ and Stagedata.img = '” … imgname … “’ and Animation.refId=” … animalID) do
group[#group+1] = row.animGroup
end
if #group > 0 then
sqlStr = “Select image,expression,layer,xref,yref,Animation.tag from Animation join Stagedata on Stagedata.refid = Animation.refid where animgroup=” … group[1] … " and Animation.refid = " … animalID …" and Stagedata.img = Animation.image"
end
end
if #group > 0 then
for row in db:nrows(sqlStr) do
–splitta ut den i två strängar beroende på lodstrecket |
local s = row.expression
–print(s)
local value = string.find (s, ‘|’,1,false );
local startString = (s:sub(0,value-1))
local endString = (s:sub(value+1,string.len(s)))
–Bygg upp start parametrarna
startParams = {}
for w in string.gmatch(startString, “%S+”) do
–Splitta varje entry vid = och skapa nya
local value = string.find (w, ‘=’,1,false );
local startString = (w:sub(0,value-1))
local endString = (w:sub(value+1,string.len(w)))
startParams[startString] = tonumber(endString)
end
–Kolla om vi ska ändra ankarpunkten
if(row.xRef~=0 or row.yRef~=0) then
startParams[“xReference”] = row.xRef
startParams[“yReference”] = row.yRef
end
–Bygg upp slut parametrarna
endParams = {}
for w in string.gmatch(endString, “%S+”) do
–Splitta varje entry vid = och skapa nya
local value = string.find (w, ‘=’,1,false );
local startString = (w:sub(0,value-1))
local endString = (w:sub(value+1,string.len(w)))
endParams[startString] = tonumber(endString)
end
local function startAnim( child)
local reset = function()
transition.to(child, endParams)
isRunning = false
end
startParams[“onComplete”] = reset
transition.to(child, startParams)
end
for k=1,refGroup.numChildren do
local child = refGroup[k]
if (child.name == “group” … row.layer) then
for l = 1, child.numChildren do
local semiChild = child[l]
if semiChild.name == row.image … “_” … row.tag then
startAnim(semiChild)
break
end
end
end
end
end
end
end
end
[/code] [import]uid: 81188 topic_id: 23310 reply_id: 93465[/import]