Author Topic: FlxCamera  (Read 2512 times)

mirosurabu

  • Member
  • **
  • Posts: 34
  • Karma: +0/-0
    • View Profile
FlxCamera
« on: Sat, Jun 12, 2010 »
I just made a separate camera class for my project, given that internal Flixel's camera didn't have required functionality.

It's very simple and provides following API:

Code: [Select]
adjustBounds(MinX:Number, MinY:Number, MaxX:Number, MaxY:Number)
Similar to Flixel's FlxG.followAdjustBounds(). This one sets the bounds the camera doesn't look out.

Code: [Select]
lookAt(X:Number, Y:Number)
Looks at specific point

Code: [Select]
simpleFollowSprite(Target:FlxSprite, OffsetX:Number, OffsetY:Number)
Simple follow. Snaps at given sprite (unlike Flixel's camera which can't do this, unless you get lucky with lerp). FlxCamera's focus point is in the top left corner, unlike Flixel's. OffsetX and OffsetY offset the focus point, and by default it's half the width and height of the screen thus making focus point in the middle of the screen.

Code: [Select]
trailFollowSprite(Target:FlxSprite, TrailSpeedX:Number, TrailSpeedY:Number, OffsetX:Number = -1, OffsetY:Number = -1, MatchCallback:Function = null)
Trail follow, something similar to Flixel's follow. It 'runs' for the target sprite. When it meets the target sprite it calls MatchCallback function. You can set the speed of it. No acceleration implemented yet, just velocity. (this however can be easily added)'

Code: [Select]
trailFollowPoint(StartX:Number, StartY:Number, TargetX:Number, TargetY:Number, TrailSpeedX:Number, TrailSpeedY:Number, OffsetX:Number = -1, OffsetY:Number = -1, MatchCallback:Function = null)
The more useful one. Runs to the specified point, useful for camera movements that don't follow an object.

--

Read 'x' and 'y' to get the position of the top-left corner of the camera in relation to origin of the map/layout/state.

NOTE: You have to call the update() method in update() method of your FlxState's in order for camera movements to take effect.

--

Pastebin: http://pastebin.com/Jr2rcqsT
Attachment: FlxCamera.as
« Last Edit: Sat, Jun 12, 2010 by mirosurabu »

xraven13

  • Active Member
  • ***
  • Posts: 213
  • Karma: +0/-0
    • View Profile
    • GemaNeko
Re: FlxCamera
« Reply #1 on: Sat, Jun 12, 2010 »
Wow, this is great !  This should be seriously added to Flixel !

ShooterMG

  • Member
  • **
  • Posts: 71
  • Karma: +0/-0
    • View Profile
Re: FlxCamera
« Reply #2 on: Sat, Jun 12, 2010 »
This looks very useful, thanks!