Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Move objects to another layer
Started by OCG Studios Jun 08 2018 12:22 AM

4 replies to this topic

Best Answer retrofitProductions , 08 June 2018 - 03:48 AM

I see, yes a little more complicated  :D

 

Try this (not tested that well), but it moves an object called "text" from layer "Layer1" to "Layer2"

local myLevel = {}
myLevel= LD_Loader:new()
myLevel:loadLevel("Level01")

local obj = myLevel:getLayerObject("Layer1","text")
print (obj.layerName)

local function moveToLayer(obj,layerTo)
	for k, v in pairs (myLevel.level.layers[obj.layerName].objects) do
		if obj.name == v.name then
			--update LDX internal collections
			table.remove(myLevel.level.layers[obj.layerName].objects,k)
			table.insert(myLevel.level.layers[layerTo].objects,v)
			--move to new display group
			myLevel.level.layers[layerTo].view:insert(obj.view)
			--change reference on object
			obj.layerName = layerTo
			break
		end
	end
end

moveToLayer(obj,"Layer2")
print (obj.layerName)


[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

OCG Studios

[GLOBAL: userInfoPane.html]
OCG Studios
  • Enthusiast

  • 75 posts
  • Enterprise

Hi,

 

Is there a way to move an object to another layer?

 

thanks



[TOPIC: post.html]
#2

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

layers.png

 

As image shows, click on object, and use the 'move to layer' icon to choose which layer to move it to



[TOPIC: post.html]
#3

OCG Studios

[GLOBAL: userInfoPane.html]
OCG Studios
  • Enthusiast

  • 75 posts
  • Enterprise

sorry I meant in code in corona. should've mentioned that



[TOPIC: post.html]
#4

retrofitProductions

[GLOBAL: userInfoPane.html]
retrofitProductions
  • Contributor

  • 318 posts
  • Corona SDK

  Best Answer

I see, yes a little more complicated  :D

 

Try this (not tested that well), but it moves an object called "text" from layer "Layer1" to "Layer2"

local myLevel = {}
myLevel= LD_Loader:new()
myLevel:loadLevel("Level01")

local obj = myLevel:getLayerObject("Layer1","text")
print (obj.layerName)

local function moveToLayer(obj,layerTo)
	for k, v in pairs (myLevel.level.layers[obj.layerName].objects) do
		if obj.name == v.name then
			--update LDX internal collections
			table.remove(myLevel.level.layers[obj.layerName].objects,k)
			table.insert(myLevel.level.layers[layerTo].objects,v)
			--move to new display group
			myLevel.level.layers[layerTo].view:insert(obj.view)
			--change reference on object
			obj.layerName = layerTo
			break
		end
	end
end

moveToLayer(obj,"Layer2")
print (obj.layerName)




[TOPIC: post.html]
#5

OCG Studios

[GLOBAL: userInfoPane.html]
OCG Studios
  • Enthusiast

  • 75 posts
  • Enterprise

this is great! Thank you very much!




[topic_controls]
[/topic_controls]