Skip to content

Porting Guide for v1.5x to v2.0

cliveJericho edited this page Sep 13, 2010 · 3 revisions

When I was porting all the demos and example programs (and my own WIP projects) I tried to keep notes on the major changes that you might find when you upgrade to the new version of flixel. This is not a change list (I am uploading one of those too), but something that will help if you get hung up on an annoying error with the new stuff! HERE WE GO

FlxStates

  • It’s important that states now be instantiated in their new create() function, NOT in their constructor. See example games!
  • To change states, just use FlxG.state = new MyGameState(); not the old FlxG.switchState() function.

FlxObject (formerly FlxCore)

  • Now includes all physics and motion code (formerly in FlxSprite)
  • Renamed hitWall() etc to hitTop(), hitBottom(), hitLeft(), hitRight()
  • By default hitRight() simply calls hitLeft(), so you can override hitLeft() and it’ll work for hitRight() automatically.
  • These functions no longer return a boolean, instead use the new Boolean member vars collideLeft, collideRight, etc.
  • Many functions that used to require use of flash.geom.Point have been changed to use the new FlxPoint class.
  • For your convenience, FlxObject now includes a dedicated _point variable that is useful for things like rotating and screen coords.
  • NEW FLAG: solid is used to indicate whether or not an object will collide.
  • dead still exists, but is intended to be used as a state indicator, not as a functional engine assumption.

FlxG & FlxU

  • Most generic utility functions have been moved over to FlxU, including:
  • random(), abs(), floor(), ceil(), openURL(), collide(), overlap(), rotatePoint()

FlxGroup (formerly FlxLayer)

  • Instead of an embarrassing assortment of arrays, layers, and parenting, flixel now uses FlxGroups.
  • Instead of adding sprites to the state AND pushing them into an array, just add them to a group, and add the group to the state.
  • Sometimes arrays are still easier for certain things, FlxGroup.members is perfect for that.
  • Groups can be used for:
  • multi-sprite characters or bosses
  • organizing screens in multi-screen games
  • lumping together enemies of the same type
  • as non-state-members that simply organize OTHER groups to help speed up collisions (meta-groups? see the example games!)
  • Includes lots of utility functions like getRandom(), getFirstExtant(), getFirstAlive(), etc.
  • This is the most important thing about the new flixel!!

Collisions & Overlapping

  • Vastly simplified, massive performance improvements.
  • To overlap one or more objects or groups, call FlxU.overlap(FlxObject,FlxObject).
  • To collide one or more objects or groups, call FlxU.collide(FlxObject,FlxObject).
  • NOTE: Neither of these functions takes scrollFactor into account.
  • A scrollFactor-compatible overlap check is still available in FlxObject.overlap(FlxObject).
  • FlxObject.collide() just redirects to FlxU.collide()
  • objects must be solid to qualify for FlxU.overlap() or FlxU.collide()
  • FULLY ORDER INDEPENDENT, doesn’t matter if you put tilemaps first or second or whatever.

FlxEmitters

  • Instead of FlxEmitter.LoadSprites(), call FlxEmitter.add() on each sprite you create.
  • Don’t add all your sprites to the game state, just add the emitter; it extends FlxGroup now!
  • Must call FlxEmitter.start() to start shooting particles (this has some new parameters too).
  • see FlxBlur for simple example of the changes.

FlxG.fade & FlxG.flash

  • FlxG.fade() should now called by FlxG.fade.start()
  • FlxG.flash() should now be FlxG.flash.start()

Misc Specifics

  • FlxSprite: frame instead of specificFrame(), frameWidth + frameHeight instead of _bw + _bh.
  • FlxObject: no more “last” point, that crap was trouble from the get go
  • FlxTilemap: removed callbacks for now :( hopefully not for too long!