object positioning changes after adding to container

I don’t understand the positioning of objects once they are added to containers. How do I make the object position stay the same it was b4 it’s added to the container?

--given a screensize of 320 x 180 and you want a container covering the area
group_container=display.newContainer(320,180)
group_container.x=320/2; group_container.y=180/2 --so the container is now centered onscreen instead of from 0,0

Once you add an object it flies all over the place:

local text= display.newText("helloWorld",0,0)
group_container:insert(text) --text,true only brings it closer to the origin of the container if text.x=400 or something

I shouldn’t have to set an object where I want it, add it to a container for a mask, and then have to set the entire object position again this time based on the container offset. I don’t know why the docs keep pushing for you to use translate either, that just makes it worse cause now you have an offset that requires a second set of x/y position to be grabbed via the gameloop which is ridiculous to micro two sets of x,y for every object…I don’t want to make updates to one and then have to update the other relative to it each time nor have two sets continuously updating for the sake of staying relative to eachother.

Similar to : Help with positioning objects / container control - #5 by ToeKnee no solutions there either…fooling around with anchors and anchorChilren=false didn’t do a thing.

I remember being overwhelmed by containers in my game. I believe I solved it by setting anchors and decoupling children. Here’s the code:

containerCredits = display.newContainer( contentWidthSafe, yLimitBottom - display.safeScreenOriginY )
containerCredits.anchorX, containerCredits.anchorY = 0, 0
containerCredits.x, containerCredits.y = 0, display.safeScreenOriginY    containerCredits.anchorChildren = false
containerCredits.moveSpeed = 4
creditsGroup:insert(containerCredits)

You can check the full code on Github if you want. Follow the variable containerCredits.

Can you try and see if it works?

Your first bit of code is just repeating what was said in the OP and in the linked post, it doesn’t work.

jesus on the left is not part of the container; jesus on the right is part of the container (its cropping him out as it should). Problem is I want Jesus in the same position as the left, instead he keeps moving with the container. Jesus is the only text part of the container, so there’s no 3 mask limit occuring.

Can you post sample code?

The code you request is already posted. Grab the code from the OP, or grab the code from the api doc, or the grab the code from the extended containers doc. Solar2D Documentation — Developer Guides | Graphics/Audio/Animation It’s all the same 3 lines of code. You define a container, u put ‘some thing’ in it…the container will work until u want the container’s position to change ( u can do that via :translate or .x/.y), then it changes the position of EVERYTHING in it. I need that to not happen. Setting anchorChildren=false isn’t doing anything. If you set the obj position and container position to the exact same and set container:insert(obj,true) so it centers…it will infact do what u want (center on the object and not affect the obj position)…but this breaks as soon as u add in another object to the container. Containers are stated to be the masks of the engine. It would follow that you can take any set of objects onscreen and apply such a mask to them at their standing position. For the mask to undo all the positions and make you reset them relative to the masks, that makes no sense. The examples of usage all are about defining a container, putting it in the singular position u want an object, then putting the object in the container…well what If I have a dozen objects…a dozen containers is ridiculous… and formatting a dozen objects to position relative to a single offset container is also ridiculous and the very problem this entire thread is dedicated to solving x12.

Here’s my workaround. replace say() and rect() with the generics. You can take any orientation of objects and introduce a container mask at any position.

--problem is containers offset everything with their own position, so assign the obj to a group with a counter offset; make sure everything has the same anchor: .5 ideal
do
	local txt=say("HELLO_FRIENDS",75,10,20) 
	local txtb=say("HELLO_FRIENDS",150,100,30,nil,{1,0,0,.5},.5,.5) 
	local obj={txt,txtb}
	say("HELLO_FRIENDS",150,100,30,_,{1,1,1,.5},.5,.5) 

	group_offset=display.newGroup()
	group_container=display.newContainer(txt.width,txt.height);
	local container_offset_x,container_offset_y=120,90
	group_container.x,group_container.y=container_offset_x,container_offset_y
	group_offset:translate(-container_offset_x, -container_offset_y)
	--containers r drawn by specifying width/height first. they by default draw from the top-left of the screen. so u can either use translate or reassign the values directly to get the same position
	-- group_offset.x,group_offset.y=-container_offset_x, -container_offset_y

	for i=1,#obj do group_offset:insert(obj[i]) end --position should be same when commented out
	group_container:insert(group_offset)

	local j=300
	transition.to( group_container, { width=j,height=500, time=2000 } )
		local rect_outline=rect(group_container.x,group_container.y,group_container.width,group_container.height,{1,0,0,0},{0,1,0},1); rect_outline.anchorX=0.5 rect_outline.anchorY=0.5
		transition.to( rect_outline, {width=j,height=500, time=2000 } )
end