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

Scaled world confuses camera follow, breaks fixedToCamera #512

Closed
jigglycrumb opened this issue Mar 5, 2014 · 10 comments
Closed

Scaled world confuses camera follow, breaks fixedToCamera #512

jigglycrumb opened this issue Mar 5, 2014 · 10 comments

Comments

@jigglycrumb
Copy link

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.

photonstorm added a commit that referenced this issue Mar 6, 2014
@photonstorm
Copy link
Collaborator

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)

indiejones pushed a commit to indiejones/phaser that referenced this issue Mar 8, 2014
@anissen
Copy link

anissen commented Mar 19, 2014

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:
alt text

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.

@photonstorm
Copy link
Collaborator

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.

@hilts-vaughan
Copy link
Contributor

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//issues/512#issuecomment-38115802
.

@anissen
Copy link

anissen commented Mar 20, 2014

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/

@photonstorm
Copy link
Collaborator

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.

@hayesmaker
Copy link

+1, cameras should zoom.. if @anissen could share that clamp function, maybe it can be implemented in Phaser.

@photonstorm
Copy link
Collaborator

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.

@hayesmaker
Copy link

How many cameras do you own which can't zoom?

@photonstorm
Copy link
Collaborator

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.

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

No branches or pull requests

5 participants