transition.pause a specific value of a table ?

hi,

i would pause an animation of a specific character from a table view (the Character[“1”]) but when i do :

transition.pause( Character[“1”] )

it’s all my character that are paused.

how do you do to pause this character and not the others ?

thanks for your help.

CHARACTER------------------------------------------------------------------------------------------------------------------------------------------ ------------------------------------------------------------------------------------------------------------  local sheetData = { width=280, height=210, numFrames=4, sheetContentWidth=1120, sheetContentHeight=210 }     local mySheet = graphics.newImageSheet( "besprite.png", sheetData )     local sequenceData1 = {     { name = "kill", frames={ 4 }, time=1 },     { name = "runLeft", frames={ 1,2,3,2,1 }, time=40 }     }    local sheetData2 = { width=280, height=210, numFrames=4, sheetContentWidth=1120, sheetContentHeight=210 }     local mySheet2 = graphics.newImageSheet( "besprite.png", sheetData )     local sequenceData2 = {     { name = "kill", frames={ 4 }, time=1 },     { name = "runLeft", frames={ 1,2,3,2,1 }, time=40 }     }   local sheetData3 = { width=280, height=210, numFrames=4, sheetContentWidth=1120, sheetContentHeight=210 }     local mySheet3 = graphics.newImageSheet( "besprite.png", sheetData )     local sequenceData3 = {     { name = "kill", frames={ 4 }, time=1 },     { name = "runLeft", frames={ 1,2,3,2,1 }, time=40 }     }    local sheetData4 = { width=280, height=210, numFrames=4, sheetContentWidth=1120, sheetContentHeight=210 }     local mySheet4 = graphics.newImageSheet( "besprite.png", sheetData )     local sequenceData4 = {     { name = "kill", frames={ 4 }, time=1 },     { name = "runLeft", frames={ 1,2,3,2,1 }, time=40 }     }   local Character = {}   Character["1"] = display.newSprite( mySheet, sequenceData1 ) Character["1"].x = 240 Character["1"].y = 160 Character["1"].alpha = 1 Character["1"].xScale = 1 Character["1"].yScale = 1 Character["1"]:setSequence( "runLeft" ) Character["1"]:play() Character["1"].myId = "1" --Set the buttons id   Character["2"] = display.newSprite( mySheet2, sequenceData2 ) Character["2"].x = 140 Character["2"].y = 160 Character["2"].xScale = 1 Character["2"].yScale = 1 Character["2"]:setSequence( "runLeft" ) Character["2"]:play() Character["2"].myId = "2" --Set the buttons id   Character["3"] = display.newSprite( mySheet3, sequenceData3 ) Character["3"].x = 340 Character["3"].y = 160 Character["3"].xScale = 1 Character["3"].yScale = 1 Character["3"]:setSequence( "runLeft" ) Character["3"]:play() Character["3"].myId = "3" --Set the buttons id   Character["4"] = display.newSprite( mySheet4, sequenceData4 ) Character["4"].x = 440 Character["4"].y = 160 Character["4"].xScale = 1 Character["4"].yScale = 1 Character["4"]:setSequence( "runLeft" ) Character["4"]:play() Character["4"].myId = "4" --Set the buttons id     local function displacementitself()   local function displacement() transition.to(Character["1"], { tag="displacement1", time=1000, x=100, y=200, yScale = .4, xScale = .4, onComplete=displacementitself })    transition.to(Character["2"], { tag="displacement2", time=1000, x=120, y=220, yScale = .3, xScale = .3, onComplete=randomposition2 })    transition.to(Character["3"], { tag="displacement3", time=1000, x=140, y=240, yScale = .2, xScale = .2, onComplete=randomposition3 })    transition.to(Character["4"], { tag="displacement4", time=1000, x=160, y=280, yScale = .15, xScale = .15})    end displacement() end     --   displacementitself()   local function killCharacter()         Character["1"]:setSequence( "kill" )         Character["1"]:play()         print( "You touched the object!" )         return true end   local function transCanceled()         transition.pause( Character["1"] ) end   local function touchCharacter(event)      target = event.target        --Handle action for each different button      if target.myId == "1" then         killCharacter()         transCanceled()      elseif target.myId == "2" then         print("character 2")      elseif target.myId == "3" then          print("character 3")      elseif target.myId == "4" then         print("character 4")          ---Retry      end             return true end       Character["1"]:addEventListener("tap", touchCharacter)     Character["2"]:addEventListener("tap", touchCharacter)     Character["3"]:addEventListener("tap", touchCharacter)     Character["4"]:addEventListener("tap", touchCharacter)

Try changing where you start and pause the transition to this:

Character["1"].transition = transition.to(Character["1"], { tag="displacement1", time=1000, x=100, y=200, yScale = .4, xScale = .4, onComplete=displacementitself } transition.pause( Character["1"].transition )

Transition.pause() takes a transition variable as it’s parameter, not the object that is having the transition applied. Since you are passing in the display object as a param and this is not a valid argument, it is doing the same thing it would do if you passed no params and cancels all transitions.

By attaching the transition as a property of the object, you can then call the transition for that particular object later on.

thank you for your help it works now
I take this opportunity to little because I do not see how to solve this unless so too complex …
I reserve enemies symbolized by my table “character” from 1 to 10
as soon as the number 2 dies I would put a flag flagkill2 = false

the problem is that eg 2-3-7 will die but I need to call another enemi, I would have to happen to code the first character in my 1A10 table that has different flagkill of false returns to game …

can you help me about it … ?

ps: my native language is not English so be gentle :slight_smile:

local function killCharacter1()     if CharacterisonLife1 then           CharacterisonLife1 = false         transition.pause( Character["1"].transition ) end         return true, CharacterisonLife1 end

local function enterCharacter()     if CharacterisonLife# then --the first who have the flag Characterisonlife# true enters the screen of the game  Character#.transition = transition.to(Character[#], {tag="displacement1", time=1000,x=sidex1, y=sidey1, yScale=.4, xScale =.4, onComplete=displacementitself}) end end

i search to simplify the snippet to avoid to copy the same snippet if i have 100 enemy !!!

to explain a little more :

if Character[a number between 1 and 10].CharacterisonLife == true --if in the list 1-10 you find the first number of the character who have the flag"Characterisonlife" true then --print the exact number in this case 4 Character[4].ingame = true end

Try changing where you start and pause the transition to this:

Character["1"].transition = transition.to(Character["1"], { tag="displacement1", time=1000, x=100, y=200, yScale = .4, xScale = .4, onComplete=displacementitself } transition.pause( Character["1"].transition )

Transition.pause() takes a transition variable as it’s parameter, not the object that is having the transition applied. Since you are passing in the display object as a param and this is not a valid argument, it is doing the same thing it would do if you passed no params and cancels all transitions.

By attaching the transition as a property of the object, you can then call the transition for that particular object later on.

thank you for your help it works now
I take this opportunity to little because I do not see how to solve this unless so too complex …
I reserve enemies symbolized by my table “character” from 1 to 10
as soon as the number 2 dies I would put a flag flagkill2 = false

the problem is that eg 2-3-7 will die but I need to call another enemi, I would have to happen to code the first character in my 1A10 table that has different flagkill of false returns to game …

can you help me about it … ?

ps: my native language is not English so be gentle :slight_smile:

local function killCharacter1()     if CharacterisonLife1 then           CharacterisonLife1 = false         transition.pause( Character["1"].transition ) end         return true, CharacterisonLife1 end

local function enterCharacter()     if CharacterisonLife# then --the first who have the flag Characterisonlife# true enters the screen of the game  Character#.transition = transition.to(Character[#], {tag="displacement1", time=1000,x=sidex1, y=sidey1, yScale=.4, xScale =.4, onComplete=displacementitself}) end end

i search to simplify the snippet to avoid to copy the same snippet if i have 100 enemy !!!

to explain a little more :

if Character[a number between 1 and 10].CharacterisonLife == true --if in the list 1-10 you find the first number of the character who have the flag"Characterisonlife" true then --print the exact number in this case 4 Character[4].ingame = true end