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

Cannot control order in which objects under Prefab Group are instantiated #79

Closed
puzzud opened this issue Jun 10, 2018 · 13 comments
Closed

Comments

@puzzud
Copy link

puzzud commented Jun 10, 2018

The order in which objects are listed in a Canvas' list of objects in Design seems to indicate the order in which they are instantiated in code.

The order in which objects are listed in a Prefab Group's list of objects in Design seems to be nearly uncontrollable--after fiddling with it a bit, I could not determine a way to work around this issue. It's using some internal logic to determine order of instantiation.

It would be ideal if this instantiation order was consistent with how it's done directly under a Canvas.

@puzzud
Copy link
Author

puzzud commented Jun 10, 2018

Looking at this further, I suppose Canvas Design object order does not work as I expected either. In which case, I guess this issue is an enhancement request.

I would expect an in-order traversal of the Design Objects tree to determine the order in which all objects are ordered in groups and thus rendered (Z depth).

The Z depth is what is most important to me. It would reduce the amount of grouping and reordering necessary to get the compositing effects I want.

@PhaserEditor2D
Copy link
Owner

I will take a look.

@PhaserEditor2D
Copy link
Owner

Hello @puzzud,

Please, can you show here an image with the wrong order? Look this image I attach here. It shows the order of the objects in a prefab scene and the order in code of the objects of the same scene.

In code, the object in the bottom is created first.

image

@puzzud
Copy link
Author

puzzud commented Jun 18, 2018

Hmm. You're right in that is the order I get.

Perhaps I'm encountering a Phaser bug or some intended behavior that I did not expect.
In my scenario, my #7 (brazo2) is a tilemap while all the others are bitmap text. Despite the order, the tilemap appears on top.

My workaround is to add all objects into the prefab group this.add(_object); and then send my tilemap to back.

Alternatively, if Phaser Editor were to automatically add these objects as children of the prefab, sending the tilemap to the back is not necessary. However, I suppose there is a good reason to not necessarily add these objects as children? Perhaps some of the children need to be in other groups?

@PhaserEditor2D
Copy link
Owner

I am trying to reproduce your behavior but I can't. Please can you show an image of your code and scene? I have interest on find the bug or make clear what is happening. If you cannot show an image maybe you can do a small project where the error is reproduced and attach it here.

@puzzud
Copy link
Author

puzzud commented Jun 19, 2018 via email

@PhaserEditor2D
Copy link
Owner

Ok thanks.

@puzzud
Copy link
Author

puzzud commented Jun 27, 2018

Added a small project that illustrates this issue:
TilemapBitmapTextCompositing.zip

@PhaserEditor2D
Copy link
Owner

Hi @puzzud

Please, can you tell me what's the problem with that project? I see some Canvas files but I don't know where to look.

Thanks.

@puzzud
Copy link
Author

puzzud commented Jul 1, 2018

@PhaserEditor2D, the order of objects defined under a prefab group does not have an impact on the order in which they are drawn.

Running this project, you'll see some examples where text should be see on top of a tilemap.

Maybe I'm misinterpreting behavior or maybe Phaser Editor can insert more code. I'm not entirely sure on this one. I'll defer to your best judgement and Phaser knowledge.

@PhaserEditor2D
Copy link
Owner

Hi @puzzud,

We are too busy migrating the editor to Phaser 3, but we are going to do a pause to release a new version of the v1 series. I will take a look at this issue again.

@PhaserEditor2D
Copy link
Owner

@puzzud It is a Phaser Editor bug. The tilemap layer should be added to the prefab group, something like this:


function PopupMessage(aGame, aParent, aName, aAddToStage, aEnableBody, aPhysicsBodyType) {
	
	Phaser.Group.call(this, aGame, aParent, aName, aAddToStage, aEnableBody, aPhysicsBodyType);
	
... 
	var _map = this.game.add.tilemap('map', 8, 8, this);
	_map.addTilesetImage('tiles');

	var _map_layer = _map.createLayer(0); // actual code, it is wrong!	       
	var _map_layer = _map.createLayer(0, null, null, this); // we should generate this
	_map_layer.resizeWorld();
...
	
}

PhaserEditor2D added a commit that referenced this issue Sep 7, 2018
The tilemap layer was added always to the world group and not the real
group. In addition, the `fixedToCamera` property is set to `true` by
default, as it is in Phaser v2.
@PhaserEditor2D
Copy link
Owner

Done. Now the layer is added to the prefab group. But also take in consideration that it is fixed to the camera by default, so if you want to move it to other position you should set the fixedToCamera false, or change the cameraOffset of the layer.

@PhaserEditor2D PhaserEditor2D moved this from In Progess to Done in Development v1.5.3 Sep 7, 2018
@PhaserEditor2D PhaserEditor2D removed this from Done in Development v1.5.3 Sep 20, 2018
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

2 participants