PhaserEditor2D / PhaserEditor

A friendly IDE to develop HTML5 games based on the Phaser framework.
https://phasereditor2d.com
Eclipse Public License 1.0
330 stars 45 forks source link

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

Closed puzzud closed 6 years ago

puzzud commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

I will take a look.

PhaserEditor2D commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

I'll put together a small project and attach when time permits.

On Mon, Jun 18, 2018 at 10:35 PM, Phaser Editor notifications@github.com wrote:

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.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/PhaserEditor2D/PhaserEditor/issues/79#issuecomment-398255522, or mute the thread https://github.com/notifications/unsubscribe-auth/AAcyXy-81dytzO_oass9tgLFPCBsvKyYks5t-GNVgaJpZM4Uhv4c .

PhaserEditor2D commented 6 years ago

Ok thanks.

puzzud commented 6 years ago

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

PhaserEditor2D commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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 commented 6 years ago

@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 commented 6 years ago

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.