Hi, i’m animating different images that share the same properties. This is my code:
local composer = require( “composer” )
local scene = composer.newScene()
local A_image_01, A_image_02, A_image_03, A_image_04, B_image_01, B_image_02, B_image_03,
C_image_01, D_image_01, D_image_02
local sheetInfo_111 = require(“assets.sprites.sprite_111”)
local myImageSheet_111 = graphics.newImageSheet( “assets/sprites/sprite_111.png”, sheetInfo_111:getSheet() )
local sizeX = 100
local sizeY = 300
– create()
function scene:create( event )
local sceneGroup = self.view
A_image_01 = display.newImage( myImageSheet_111, 2 , sizeX, sizeY )
A_image_01.alpha = 0
sceneGroup:insert(A_image_01)
A_image_02 = display.newImage( myImageSheet_111, 1 , sizeX, sizeY )
A_image_02.alpha = 0
sceneGroup:insert(A_image_02)
A_image_03 = display.newImage( myImageSheet_111, 10 , sizeX, sizeY )
A_image_03.alpha = 0
sceneGroup:insert(A_image_03)
A_image_04 = display.newImage( myImageSheet_111, 6 , sizeX, sizeY )
A_image_04.alpha = 0
sceneGroup:insert(A_image_04)
B_image_01 = display.newImage( myImageSheet_111, 5 , sizeX, sizeY )
B_image_01.alpha = 0
sceneGroup:insert(B_image_01)
B_image_02 = display.newImage( myImageSheet_111, 4 , sizeX, sizeY )
B_image_02.alpha = 0
sceneGroup:insert(B_image_02)
B_image_03 = display.newImage( myImageSheet_111, 7 , sizeX, sizeY )
B_image_03.alpha = 0
sceneGroup:insert(B_image_03)
C_image_01 = display.newImage( myImageSheet_111, 3 , sizeX, sizeY )
C_image_01.alpha = 0
sceneGroup:insert(C_image_01)
D_image_01 = display.newImage( myImageSheet_111, 8 , sizeX, sizeY )
D_image_01.alpha = 0
sceneGroup:insert(D_image_01)
D_image_02 = display.newImage( myImageSheet_111, 9 , sizeX, sizeY )
D_image_02.alpha = 0
sceneGroup:insert(D_image_02)
end
– show()
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == “will” ) then
– Code here runs when the scene is still off screen (but is about to come on screen)
elseif ( phase == “did” ) then
local function imageAnimation()
transition.to(A_image_01, {time=1470, alpha=1, transition=easing.inOutExpo })
transition.to(A_image_02, {time=1470, alpha=1, transition=easing.inOutExpo, delay=200 })
transition.to(A_image_03, {time=1470, alpha=1, transition=easing.inOutExpo, delay=400 })
transition.to(A_image_04, {time=1470, alpha=1, transition=easing.inOutExpo, delay=600 })
transition.to(B_image_01, {time=1470, alpha=1, transition=easing.inOutExpo, delay=2300 })
transition.to(B_image_02, {time=1470, alpha=1, transition=easing.inOutExpo, delay=2500 })
transition.to(B_image_03, {time=1470, alpha=1, transition=easing.inOutExpo, delay=2700 })
transition.to(C_image_01, {time=1470, alpha=1, transition=easing.inOutExpo, delay=3500 })
transition.to(D_image_01, {time=1470, alpha=1, transition=easing.inOutExpo, delay=4500 })
transition.to(D_image_02, {time=1470, alpha=1, transition=easing.inOutExpo, delay=4700 })
end
imageAnimation()
end
Can I optimize this code adding the objects to a display group? How can I do that? I have read the documentation about groups, but I don’t know how to code that.
Thanks in advance
Xavi