问题
Suppose I want an animated smiley face composed to 2 layers: the face background + face foreground.
The background layer is a simple color/texture. The foreground layer is the animated layer (animated smiling, crying, laughing...etc).
How can i write this up in Lua such that Corona will treat these layers as a single object/entity? I would like a single entity to work with (for collision, animated movements, ...etc).
回答1:
I would do this with a displayGroup.
Something like this:
local smiley = display.newGroup()
local emotion = display.newImage("happy.png")
local background = display.newImage("background.png")
smiley:insert(background)
smiley:insert(emotion)
-- moving smiley will also move background and emotion
-- because they are attached to the smiley displayGroup
smiley.x = 100
smiley.y = 100
回答2:
Hope this helps you out.
smiley:insert(1,background)
smiley:insert(2,emotion)
Greater the number more upfront is the image
来源:https://stackoverflow.com/questions/10378308/how-to-create-work-with-layered-images-using-lua-corona-sdk