phaserjs / phaser

Phaser is a fun, free and fast 2D game framework for making HTML5 games for desktop and mobile web browsers, supporting Canvas and WebGL rendering.
https://phaser.io
MIT License
37.23k stars 7.1k forks source link

Drop from SceneA to SceneB #5332

Closed MadDogMayCry0 closed 4 years ago

MadDogMayCry0 commented 4 years ago

Hi, Richard!

My game from point ang click adventures world. :)

Month ago i writed a post "Drop objects between different scenes" https://phaser.discourse.group/t/drop-objects-between-different-scenes/6969

When i drag objects from SceneB to SceneA, then SceneA.input.activePointer.worldX -> will have value from SceneB.input.activePointer.worldX (i think this goingon, becuse game object from SceneB in focus on moment, when event "dragend" has been called).

It's veary needed to drop object between different scenes (gamescene, UI, inventory). I can't use Scrollfactor for my UI and Inventory, becuse of camera zoom that i use.

UPDATE Today i found out and writed a slolution to calculate offset between two scenes.

(SceneMain.input.activePointer.x/cam._zoom)+(cam.worldView.x/cam._zoom)*cam._zoom;

next step is executing an regular overlaping function and it's works for rectangles. When camera will be rotated, it’s will stop working and i have no idea how to calculate this too! /UPDATE

The easiest way would be to have the ZoomFactor's setting together with ScrollFactor. This would solve all my problems without having to create several scenes. Then I would also using a drop zones too. Oh, those dreams. :)

Or, if not possible to obtain ZoomFactor, can you pls do something to get dropzones works when object dropeed from SceneA to SceneB?

Pls, help :)

Thank you for attention! Have a nice Day!

photonstorm commented 4 years ago

What do you mean by "have the ZoomFactor's setting together with ScrollFactor" ?

MadDogMayCry0 commented 4 years ago

What do you mean by "have the ZoomFactor's setting together with ScrollFactor" ?

container.setScrollFactor(0,0,[, updateChildrens], [,ADD_ZOOM_FACTOR_RIGHT_HERE]); or container.preventZoom(true);

Have a nice day :+1:

photonstorm commented 4 years ago

But they’re completely unrelated. A camera can not zoom different objects at different levels, no game engine offers that (because it doesn’t really make logical sense). If you need varying levels of zoom then treat the camera zoom as the base level and factor around that with scaled containers.

On Mon, 28 Sep 2020 at 21:04, Maddogmaycry notifications@github.com wrote:

What do you mean by "have the ZoomFactor's setting together with ScrollFactor" ?

container.setScrollFactor(0,0,[, updateChildrens], [,ADD_ZOOM_FACTOR_RIGHT_HERE]);

Have a nice day 👍

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/photonstorm/phaser/issues/5332#issuecomment-700252451, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABIE7FGZLRXRVX3Z73GND3SIDT6NANCNFSM4R3YE67Q .

-- Photon Storm Ltd. http://www.photonstorm.com

Twitter: @photonstorm

Registered in England and Wales. Company ID: 8036404 VAT Number: 136 4333 27

MadDogMayCry0 commented 4 years ago

Hi.

But how about drop objects between scenes in dropzones? How to realise this then for now?

photonstorm commented 4 years ago

Between Scenes? A Game Object can only belong to one single Scene at once, ever. So you cannot drag it from one Scene and drop it on another. Instead, you'll need to handle all of the drag and drop on your UI Scene and when the Game Object is dropped, re-create it in the other Scene with a brand new Game Object. Depending on how complex your cameras are, depends on how easy or difficult this becomes, but there are plenty of translation functions built into the Camera / Input classes that help with converting points between world/local spaces.

This isn't a feature request or a bug, so I'm going to close this off. Follow-up on the forum / Discord for further suggestions.

MadDogMayCry0 commented 4 years ago

Thank you, I have already been there, on the forum. Judging by the activity, no one has any ideas how this could be implemented. And of course I re-create objects in other scenes when they falling there.

You can read last topic where a explane the last solution on do this. https://phaser.discourse.group/t/drop-objects-between-different-scenes/6969/13

Have a nice Day