Camera bounds resistant to zooming and window sizing

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

Camera bounds resistant to zooming and window sizing

Postby foolmoron » Fri Dec 27, 2013 2:56 am

**UPDATE: Check my reply to this post for a new version of this package of camera-related goodies**

Here's something that I worked on quite a bit for my current game's camera system: A component for limiting the panning of the camera to a certain rectangle of pixels, regardless of current zoom level or window size. I also threw in my simple mouse scroll zooming component

Basically it allows you to provide a rectangle that determines exactly what the user can see. The component controls panning and zooming such that the player will NEVER be able to escape that rectangle, no matter how much he screws with the window or zoom.

The attached package contains a demo and the two components. You can use it like this:
Code: Select all
self.vp1 = new IgeViewport()
   .addComponent(IgeMousePanComponent)
   .addComponent(ScrollZoomComponent)
   .addComponent(LimitZoomPanComponent, {
      boundsX: 0,
      boundsY: 1056,
      boundsWidth: 2784,
      boundsHeight: 1968,
   })
   .mousePan.enabled(true)
   .scrollZoom.enabled(true)


NOTE: The LimitPanZoomComponent is modified to work with the new breaking changes in the 1.4.5 version of the engine (viewtopic.php?f=15&t=98). If you're using the master version of the engine, change all the "_bounds2D" references in the component to "_geometry".
Attachments
Fool's Camera Stuff.zip
(203.66 KiB) Downloaded 684 times
Last edited by foolmoron on Wed Mar 26, 2014 6:35 pm, edited 1 time in total.
foolmoron
 
Posts: 57
Joined: Thu Oct 24, 2013 7:20 pm

Re: Camera bounds resistant to zooming and window sizing

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

VERSION 2.0!

Attached is an update to this camera stuff. It has a new ScaleToPoint component, and a PinchZoom component, along with an updated ScrollZoom component that uses the ScaleToPoint functionality if it has been added to the viewport.

The LimitZoomPan component has not been changed since the original post in this topic, though. But these extra camera goodies should be useful to some!
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 669 times
foolmoron
 
Posts: 57
Joined: Thu Oct 24, 2013 7:20 pm

Re: Camera bounds resistant to zooming and window sizing

Postby Doidel » Thu Mar 27, 2014 11:08 am

Thanks for all the custom codes, much appreciated :)
User avatar
Doidel
 
Posts: 59
Joined: Tue Jan 14, 2014 5:05 pm


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 1 guest
cron