Zoom camera to a specific point

A place to post your custom classes and engine extensions to share with the community.

Zoom camera to a specific point

Postby foolmoron » Wed Mar 26, 2014 6:23 pm

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();
      this._entity.camera.scaleTo(scaleX, scaleY, 0);
      ige.input._updateMouseData({igeX: pointX, igeY: pointY});
      var newMousePos = this._entity.mousePosWorld();
      this._entity.camera.translateBy(
         oldMousePos.x - newMousePos.x,
         oldMousePos.y - newMousePos.y,
         0
      );
   },
});


You just use AddComponent to add it to your viewport, and then call it like so:
Code: Select all
viewport.scaleToPoint.scaleTo(
      newScaleX,
      newScaleY,
      zoomPointX,
      zoomPointY
);


An example project is attached (along with other camera goodies)
Attachments
Fool's Camera Stuff 2.0.zip
Example project with scrollwheel zooming, pinch zooming, zoom-to-point, and advanced camera bounds
(185.63 KiB) Downloaded 763 times
foolmoron
 
Posts: 57
Joined: Thu Oct 24, 2013 7:20 pm

Re: Zoom camera to a specific point

Postby robaldred » Thu Apr 10, 2014 11:47 am

Really interesting. Thank you for sharing!
I'm very interested in your "advanced camera bounds"

Just going to checkout the app now.
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England

Re: Zoom camera to a specific point

Postby robaldred » Thu Apr 10, 2014 12:10 pm

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.
I don't work for Irrelon. All comments are my own.
I would strongly encourage anyone building production projects with Isogenic to buy a premium licence, it costs very little and will help towards continued development of the engine. Irrelon have spent thousands of hours developing this wonderful platform with many features found in AAA game engine.
User avatar
robaldred
 
Posts: 243
Joined: Wed Oct 23, 2013 8:09 pm
Location: Manchester, England

Re: Zoom camera to a specific point

Postby foolmoron » Sat Apr 12, 2014 4:43 pm

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!
foolmoron
 
Posts: 57
Joined: Thu Oct 24, 2013 7:20 pm


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 0 guests
cron