Page 1 of 1

Zoom camera to a specific point

PostPosted: Wed Mar 26, 2014 6:23 pm
by foolmoron
Here's a component I wrote for zooming a viewport around a certain focus point on the screen, like in classic-style top-down RPGs:
Code: Select all
var ScaleToPointComponent = IgeEventingClass.extend({
   classId: 'ScaleToPointComponent',
   componentId: 'scaleToPoint',

   init: function (entity, options) {
      var self = this;
      this._entity = entity;
   scaleTo: function (scaleX, scaleY, pointX, pointY) {
      ige.input._updateMouseData({igeX: pointX, igeY: pointY}); // this function expects a mouse event but only really needs these 2 values
      var oldMousePos = this._entity.mousePosWorld();, scaleY, 0);
      ige.input._updateMouseData({igeX: pointX, igeY: pointY});
      var newMousePos = this._entity.mousePosWorld();
         oldMousePos.x - newMousePos.x,
         oldMousePos.y - newMousePos.y,

You just use AddComponent to add it to your viewport, and then call it like so:
Code: Select all

An example project is attached (along with other camera goodies)

Re: Zoom camera to a specific point

PostPosted: Thu Apr 10, 2014 11:47 am
by robaldred
Really interesting. Thank you for sharing!
I'm very interested in your "advanced camera bounds"

Just going to checkout the app now.

Re: Zoom camera to a specific point

PostPosted: Thu Apr 10, 2014 12:10 pm
by robaldred
Hey Dude.
This is really awesome.
I noticed one issue with the CameraPan limiter.
I don't believe affects your game, however. I use trackTranslate.
So the camera moves with my player character.

The LimitZoomPanComponent i release is only for dealing with setting a limit when panning and zooming, however it would be really awesome if it would also override the camera translation when the camera is panning automatically when tracking another entity like a player.

Might involve hooking into the camera's updateTransform method.

Re: Zoom camera to a specific point

PostPosted: Sat Apr 12, 2014 4:43 pm
by foolmoron
Ah, yeah, the camera stuff wasnt tested at all with entity tracking. I wonder how hard it would be to get that working...

Anyways, thanks for trying it out, and the kind words!