Author Topic: Camera Share Angle Code.  (Read 1453 times)


  • Member
  • **
  • Posts: 32
  • Karma: +0/-0
    • View Profile
Camera Share Angle Code.
« on: Sat, Dec 3, 2011 »
Let's say you're making a co-op game, but you don't want to use flixel's multi-camera feature to do the camera display job, and you want people to see more without being limited. Here's a piece of code I whipped up just now to solve this simple issue.

First, make a FlxSprite, it doesn't need to have a image, nor does it have to be visible.

I named mine "_cameraAngleSpr".

The rest is explained through the comments.

Code: [Select]
// We're making _cameraAngleSpr's x coordinate equal to player1's and player2's x coordinates combined, then divided by 2.

_cameraAngleSpr.x = (_player1.x + _player2.x) / 2;

// Same for this, only it's for the y coordinate.

_cameraAngleSpr.y = (_player1.y + _player2.y) / 2;

This goes on the "update" function in your FlxState.

Now, if you want a smooth effect, I suggest using any one of the greensock tweening classes.

Code: [Select], 0.75, { x:(_player1.x + _player2.x) / 2, y:(_player1.y + _player2.y) / 2 } );

These codes are free to use on any of your projects, credits are not necessary, but it would be nice if given.

I forgot to say that it doesn't stop the camera from panning out, and making only one player visible, I'm still working on it.
« Last Edit: Sat, Dec 3, 2011 by TahGamer »