Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reparenting a Node while maintaining transformation #8788

Closed
Diaspater opened this issue May 16, 2017 · 3 comments
Closed

Reparenting a Node while maintaining transformation #8788

Diaspater opened this issue May 16, 2017 · 3 comments

Comments

@Diaspater
Copy link

Diaspater commented May 16, 2017

Operating system or device - Godot version:
Windows 10
Godot 2.1.2

Issue description:
Reopening #4008 for a continued request of the feature.
The game I am working on is designed using 2.5d graphics with multiple layers for bridges, cliffs etcetera. In order to make the Y ordering to work all objects need to be placed under the same YSort node or the player needs to be moved between different 'Rooms' YSort nodes. I chose to move the player between rooms as due to other game needs/requirements. However when I tried using the solution offered in #4008 there is a noticeable flickering during room transitions where the player is first drawn with regard to a local position after reparenting and then corrected to a global positioning. If there is a solution to the flickering I am more then willing to accept that the feature request priority is minimal compared to other requests but I was unable to find a solution (browsing issue trackers, google, etc.) or the solution provided did not solve the flickering issue.

Steps to reproduce:
Create two 'Room' Nodes with a Area2d Child Node for body detection. Make sure the rooms are larger than the view port for easy notice of the issue. Populate the rooms with some sprites to help with identify the problem. Attach the following script:

func _fixed_process(delta):
	var bodies  = get_overlapping_bodies()
	if( bodies.size() > 0):
		for b in bodies:
			if( b.has_method("set_room")):
				var parent = b.get_owner()
				if( parent != self):
					b.set_room(self)

Create a 'Player' Node with a KinematicBody2d and a child CollisionShape2d. Write some basic movement code with the following method:

func set_room( node):
	var parent = self.get_parent()
	var transformation = get_global_transform()
	parent.remove_child(self)
	node.add_child(self)
	self.set_owner(node)
	set_global_transform(transformation)

Move the player from one room to another, on transition there is a flicker where the player is first drawn with the position relative to local and then corrected to global.

Link to minimal example project:
READ BEFORE DOWNLOADING
Some of the images/sprites used in this project are licensed by me from their respective copyright holders. I am able to distribute them with my project as part of my project but their use beyond that is prohibited. Basically do not copy, use, modify, or distribute them if you use the provided project for testing.
ErrantDice.zip

@volzhs
Copy link
Contributor

volzhs commented May 16, 2017

I edited OP to look better code sample.

@akien-mga akien-mga changed the title [Feature][Request] Reparenting a Node while maintaining transformation Reparenting a Node while maintaining transformation May 16, 2017
@Diaspater
Copy link
Author

After doing some more testing I found that the flickering is being caused by the child Camera2D node following the player. By detaching the node there was no noticeable player or room flickering while transitioning between rooms however the camera obviously does not follow the player as a consequence. By detaching the camera2d node during the transition the flickering is reduce to a non-seizure inducing level that is definitely caused by the camera re-positioning. I am now looking into how to preserve the camera's global position during room transitions to eliminate the last bit of flickering.

@akien-mga
Copy link
Member

Given the above comment it seems like the original issue was not linked to the need to reparent nodes while keeping transforms, so closing as duplicate of #4008.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants