How to create/work with layered images using Lua/Corona SDK?

主宰稳场 提交于 2019-12-08 11:31:53

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!