Anyone experienced with 'Perspective' Virtual Camera?

Hi all. I’ve been having some fun with the Perspective library, which seems to solve a lot of problems in one go… I’d just like a few pointers from someone (anyone), who’s been using it longer than me.

The first thing I’d like to do, is disable vertical tracking, it can get a bit hectic in there.

Secondly, I’d like to create ‘focal inertia’. This is where the camera doesn’t move until the ‘tracked’ object gets within a pre-specified distance from the edge of the screen… So, it’s no always in the EXACT centre.

I didn’t want to start messing with the library itself until I’d asked in here.

All the best

I’m the author of Perspective, glad you’re finding it useful :)!

You can solve your two problems with the setBounds() function. It takes the dimensions of a rectangle as arguments, then clamps tracking to those bounds.

[lua]

camera:setBounds(x1, x2, y1, y2)

[/lua]

x1 is the minimum position the camera can be, x2 is the max, and y1 and y2 are the equivalents in the Y-axis. Dimensions are given as “center of the screen can be at most/must be at least this value”.

So to disable vertical tracking, you can set y1 and y2 to the same value (say, the center of your screen in the Y-axis). Then, just set x1 and x2 to what you want, and you should be good to go.

[lua]

camera:setBounds(0, 500, display.contentCenterY, display.contentCenterY) – Will clamp the camera’s tracking to 0-500 and display.contentCenterY

[/lua]

  • Caleb

Wow, straight from the horses mouth… Thanks Caleb. It really is a spectacular piece of work by the way :slight_smile:

I thought ‘setBounds’ might be what I was looking for, but the comments in your Pseudo-Usage demo, were a bit complicated for me to understand fully… I tried messing with the parameters, but it just seemed to move my viewport around and stop tracking altogether… Now that I know I’m barking up the right tree, I’ll spend more time exploring, thanks.

I’m the author of Perspective, glad you’re finding it useful :)!

You can solve your two problems with the setBounds() function. It takes the dimensions of a rectangle as arguments, then clamps tracking to those bounds.

[lua]

camera:setBounds(x1, x2, y1, y2)

[/lua]

x1 is the minimum position the camera can be, x2 is the max, and y1 and y2 are the equivalents in the Y-axis. Dimensions are given as “center of the screen can be at most/must be at least this value”.

So to disable vertical tracking, you can set y1 and y2 to the same value (say, the center of your screen in the Y-axis). Then, just set x1 and x2 to what you want, and you should be good to go.

[lua]

camera:setBounds(0, 500, display.contentCenterY, display.contentCenterY) – Will clamp the camera’s tracking to 0-500 and display.contentCenterY

[/lua]

  • Caleb

Wow, straight from the horses mouth… Thanks Caleb. It really is a spectacular piece of work by the way :slight_smile:

I thought ‘setBounds’ might be what I was looking for, but the comments in your Pseudo-Usage demo, were a bit complicated for me to understand fully… I tried messing with the parameters, but it just seemed to move my viewport around and stop tracking altogether… Now that I know I’m barking up the right tree, I’ll spend more time exploring, thanks.