Closed jigglycrumb closed 10 years ago
Ok this is fixed now for objects that have fixedToCamera set. But I cannot think of a clean way to do it for camera follow targets - the camera never changes the position of the target, it just focuses on it, but the object has gone 'off screen' because the camera is only displaying a zoomed-in portion of what it can normally see. It /thinks/ the rest is still there, it doesn't know it's hidden off the side of the canvas.
I have tried shrinking the deadzone based on scale, but that doesn't stop the target object wandering off, although it possibly could in combination with adjusting the worlds pivot point. If you change the pivot of the world then all kinds of interesting and screwy things happen. My solution honestly would be to create a Group (or DisplayObjectContainer) that sits above the World on the Stage, and you pivot and rotate that as needed. Not ideal I know, sorry - but at least fixedToCamera was resolved! (unless pivot changes of course.. damnit)
Sorry to comment on a closed issue, but this issue has not been properly resolved in my opinion.
I also need to zoom in/out on a object that the camera follows. I tried following the advice of grouping everything except camera in a group and scaling that, but I still have the problem of the camera losing track of the object it follows.
I made an implementation myself using Pixi that handles zooming in/out on a moving object. I do it something like this:
var halfWidth = (canvas.width / 2) / camera.zoom;
var halfHeight = (canvas.height / 2) / camera.zoom;
// clamping the camera within the bounds of the world
var clampedX = clamp(followObject.position.x, halfWidth, world.width - halfWidth);
var clampedY = clamp(followObject.position.y, halfHeight, world.height - halfHeight);
camera.x = (-clampedX * camera.zoom + canvas.width / 2);
camera.y = (-clampedY * camera.zoom + canvas.height / 2);
layer.scale.set(camera.zoom, camera.zoom);
layer.position.set(camera.x, camera.y);
The result:
There are still a lot of unanswered questions about zooming in the Phaser forums (http://www.html5gamedevs.com/forum/14-phaser/) so I think this issue be reconsidered.
It's been resolved in the sense that you're doing something the camera was never designed to handle, so the fact it can't cope with it isn't surprising. Realistically this won't get revisited until we look at replacing the camera entirely with a multiple camera system.
If someone wants to provide a pull request that solves it (without modifying the core API) then I'd always look at that in the meantime.
This should at the very least throw an exception then, not show weird behavior.
On Wed, Mar 19, 2014 at 6:34 PM, Richard Davey notifications@github.comwrote:
It's been resolved in the sense that you're doing something the camera was never designed to handle, so the fact it can't cope with it isn't surprising. Realistically this won't get revisited until we look at replacing the camera entirely with a multiple camera system.
If someone wants to provide a pull request that solves it (without modifying the core API) then I'd always look at that in the meantime.
Reply to this email directly or view it on GitHubhttps://github.com/photonstorm/phaser/issues/512#issuecomment-38115802 .
I'm not sure exactly what is and what isn't designed to be the responsibility of the camera system.
However, it would be very nice if the camera had some of the functionality similar to e.g. the HaxeFlixel camera. Example: http://haxeflixel.com/demos/FlxCamera/
There are lots of things that would be nice for it to do, but it's trivial for flixel because it can just happily work away on a single bitmap. We don't have that luxury in WebGL. The first ever version of Phaser had the most advanced camera of all - multicams, rotation, scaling, positioning anywhere. Something we had to drop all of in order to use Pixi.
Anyway I loathe frameworks throwing exceptions, that should only ever happen in truly nuclear situations, of which this isn't one.
+1, cameras should zoom.. if @anissen could share that clamp function, maybe it can be implemented in Phaser.
There are lots of things it would be nice for the Camera to do, but it doesn't alter the fact it can't actually do it yet. It's why we wrote them entirely for Phaser 3.
How many cameras do you own which can't zoom?
Irrelevant. The only one that matters here is the Phaser one, and it doesn't claim to be able to support it anywhere. It's not that the feature doesn't work, it's that it doesn't exist. Feel free to add it.
See live example here: http://phasercamera.hpcodecraft.me
Holding down the right arrow key makes the mushroom leave the screen and the camera does not follow. Also, the UI at the top starts to wander off screen. If globalScale is set to 1 everything works as expected.