Log in
Please log in or register.
Pages: [1] 2
  Print  
Author Topic: B-FLIXEL: A Flixel branch [ v1.25-C ]  (Read 3788 times)
nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« on: Wed, Sep 23, 2009 »

B-FLIXEL
A Flixel Branch [ v1.25-C ]


Documentation Wiki (If it's not there read the CHANGELOG.txt or investigate the .as files).

Download links are also there. Just check if they're from 2bam.com or tbam.com.ar.



In accordance with Adam, I'm posting my extension to flixel.
It's a modified version of flixel and has some useful extra stuff.

The idea is to have more frequent (xD) updates, maybe more hackish or with temporary workarounds;
Keeping vanilla flixel pure and easy, while still having a place to go for if you need a quick fix or a bit more advanced stuff.

It should work seamlessly with your game if it uses the unmodified flixel (except for the space key, read below)



================================================================================================
B-FLIXEL: A Flixel branch - v1.25-B
================================================================================================

--- Added 2 fonts ---
Added 2 free-license fonts I fancy: small (5px font) and blobby (reminds me of bubble bobble).

--- Wordwrapping in FlxText ---
FlxText.wordWrap [Boolean]
BlxInputText.multiline removed. Use FlxInputText.wordWrap instead (inherited from FlxText)

--- Avoding multi-handling of the same mouse click ---
FlxG.wasClickHandled()   Returns if a mouse click was already handled.
         Implemented in FlxButton. Avoids double clicks on buttons.
FlxG.handleClick()   Allows you to mark the click as handled and avoid buttons being pressed.

--- Alpha on FlxText/FlxButton ---
Community user mklee's alpha for FlxText & FlxButton.

--- Save data locally ---
Community user Merve's "FlxG.saved" shared object to save data locally
Usage (strict mode):
Save:
   FlxG.saved["highscore"] = highscore;
   FlxG.saved.flush();
Load:
   highscore = FlxG.saved["highscore"];

--- Kongregate API ---

Included AdamAtomic's FlxKong


--- FlxFactory better site-locking ---
More secure site-locking
Instead of just checking if it contains a string, it's checked from the beginning.
Of course it remains backward compatible if you don't set the sitelockURLs variable.

protected var sitelockURLs:Array;
   You assign this array on your preloader.
   You add stuff like "yoursite.com" and then is prefixed with "http://" and "https://" in combination with "www." prefix and just plain link.
   i.e. ["mysite.com"] will check against:
   http://mysite.com
   http://www.mysite.com
   https://mysite.com
   https://www.mysite.com

protected var playableFromHarddisk:Boolean = true;
   Adds ["file://", "http://localhost", "https://localhost" ] to the sitelocked list. It's the best for debugging (also "release testing") sitelocked versions on your own pc.
   Perhaps someone wants to disable this to avoid players downloading the game and forcing them back to their portal?...

protected var myLinkURL:String;
   this is the link showed in the sitelock screen (instead of using myURL)
   Two reasons
   1. If someone steals your flash game, you might want to point to your own site instead of the portal.
   2. If you are using sitelockURLs, well, you have to choose a link to show anyway.
   By default is equal to myURL if not set, or to sitelockURLs[0] if it's not empty.


================================================================================================
B-FLIXEL: A Flixel branch - v1.25-A
================================================================================================
Synopsis of B-Flixel elements
================================================================================================
(The reasons and specifics for all these are below...)

Debugging utilities: _DEBUG, ASSERT()
Button that work with links
Sub states + manager
Flags for internal functionality
Input text field
Custom logo on loading screen
"MochiPreloader" already setup to work with MochiAds


FlxArray: update/render/remove/cleanupNonexistent

FlxButton: setText(), fix for scroll factors != 1, no triggering if hovering while mouse button pressed.
FlxCore: keep track of owner layer, blinking ("slow flickering") and patched with AdamAtomic's speed fix
FlxG: open URL in new window, game background color, save data across levels with custom "*" reference.
FlxLayer's internal FlxArray made public
FlxSprite: find/remove animations. Fixed randomFrame()/specificFrame() to work with facing
Hack for FlxText  that tries to remove blurring
Dynamic FlxTilemap: changable during gameplay, overlap()/overlapArrays(), export as CSV, create empty if no CSV.
Z key also triggers "B button".
Space has it's own FlxG.kSpace/FlxG.SPACE. No longer SPACE/TAB/ESC bindings nor fullscreen mode.
FlxG.log saves data if no console present, then shows it (after FlxGame was setup, i.e. super() called)


================================================================================================
New classes and stuff in B-Flixel v1.25-A
================================================================================================

_DEBUG
   Global _DEBUG variable to know if the game was compiled in debug or release mode.

ASSERT(Cond, Msg=null)
   Global function to add pre- and post-condition checks to your code in debug mode.

MochiPreloader
   Ready to set up mochi preloader.
   You must change a line in your compiled ".as"
   from
   [Frame(factoryClass="Preloader")]
   to
   [Frame(factoryClass="MochiPreloader")]

com.tbam.bflixel.BlxURLButton
   Gets around popup-blockers by adding handling mouse events directly.
   Works with cascaded-layers seamlessly.
   Construct it as a regular FlxButton and call FlxG.openURL without worries.

com.tbam.bflixel.BlxSubState

com.tbam.bflixel.BlxG
   A sort of grabbag for any left over functionality (like FlxG, you know...)

   Functions:
   .randomInt(A, B): returns a random integer number between A and B (inclusive)
   .randomNum(A, B): returns a random decimal number between A and B (exclusive, but really near)

   User changeable constants:
   .IF_MULTIPLE_LAYER_ADDITIONS = DO_NOTHING or ADD_TRACE or RAISE_DEBUG_ERROR (default)
      Adds a check to FlxLayer.add code to avoid double core inclusions (that will call double updates/renders)
   .ENABLE_TEXT_ANTI_BLUR_HACK = true(default) | false
      Enable/disable anti blur hack
   .ENABLE_LOST_FOCUS_PAUSE = true(default) | false
      Enable/disable pausing if the game loses focus
   .STAGE_FRAMERATE = 90 (default)
      If you're gonna disable pausing I suggest you tweak this value so the player
      can do other stuff in their computer besides leaving the game on.
      I found Caverns to work better on 60FPS
   .SHOW_INPUT_HELP_ON_PAUSE = true
      If you're using your own input system, you better disable the A/B/mouse/arrows help on the pause
      menu. This flag facilitates that.

com.tbam.bflixel.BlxTextInput
   A text input field that goes with the flixel workflow (layer-cascade friendly)
   You can filter keys (Alpha/Number/Custom...), set it multiline, as password field,
   max length, uppercase forcing (e.g. for submitting only 3 uppercase initials for a hiscore),
   readonly (but selectable-copyable), background color, border, etc.
   More info on the .as file itself.

com.tbam.bflixel.BlxSubState
   SubState, for example for an inventory window or a (non-standard) paused screen
   You can override update and render for customized behaviour.
   This actually derives from a FlxLayer, so you can ".add()" stuff to it to show when enabled
   .enable()/disable():   Enables/disables it (shows/hides it)
   .toggle():      Toggles between enabled and disabled states
   See below everything for a usage example.

com.tbam.bflixel.BlxSubStateManager
   You .add() BlxSubStates to this (first one added has highest priority)
   See below everything for a usage example.

================================================================================================
Differences between Flixel 1.25 (vanilla) and B-flixel v1.25-A
================================================================================================

@ FlxFactory:
Custom logo for loading screen (you _need_ to put a "loading_logo.png" in your src folder). It will show up on top of the loading bar
Some stuff to make it work with MochiAds

@ FlxArray
.cleanNonexistent(): Removes non existing cores from the array (i.e. if core.exists == false)
.update():   FlxLayer's update functionality has been put in FlxArray, for convenience (if you update some cores manually)
.render():   FlxLayer's render functionality has been put in FlxArray, for convenience (if you render some cores manually)
.remove(core):   Call this to remove

@FlxButton
.setText(textBoth):      Sets the button's text
.setText(textOff, textOn):   Sets the button's on and off texts separatly
FIX: If sweeping the cursor over the FlxButton while the mouse button was down no longer triggers it.
FIX: It works correctly with scrolled states (if it's scrollfactor != (1;1))

@FlxCore
.ownerLayer [FlxLayer]: If it was added with FlxLayer.add(), it holds the last layer to which the core was added to
         Usually it should be only one (for render/update purposes)
         If removed with the new FlxLayer.remove() function, this gets reset to null.


.blink(Duration, BlinkPeriod):
         This avoids the ultra-fast flickering when you call flicker().
         (If you ask me it looks much better for a character "invulnerable" state)
         This is "built on top of flicker", so you can't be flickering and blinking at the same time.
.blinking()   Same as flickering(), to know if the core is blinking

FIX: It has been patched with AdamAtomic's speed fix (see the official Flixel help thread)

@FlxG
.openURL(URL, newWindow=true): Now openURL allows you to select if it opens a new window or not.
      Thanks to BlxURLButton the NEW DEFAULT mode is set to true (to avoid quitting the game).
.bgColor [uint]: Set the game's background color
.levelData [ * ]: You can assign anything you want to this variable (like an object with properties)
.log() now works regardless of the gamestate (it saves the log messages if no console is present)
   BUT it must be called after FlxGame's derived class "super()" call
   Also traces() whatever it's passed
   I had to do it due to a failure of trace capturing on the first moments of the app run
.kSpace/.SPACE
   Instead of binding

@FlxGame
now the "Z" key is also binded to FlxG.kB/B, to allow the "flipped" configuration
   (for people used to jump/fire the other way, can use ZX instead of XC)
SPACE and TAB are no longer binded to button A/B
SPACE is now binded to FlxG.kSpace / FlxG.SPACE
There is no more experimental fullscreen mode on ESC.

FALTAN RETOQUES!

@FlxLayer
.children (FlxArray): "_children" replaced by "children" and made public. Useful for collide and overlap functions (to avoid separate array/layer)
.update()/render(): Now calls children.update()/render().

@FlxSprite
findAnimation(name):   Find an internal animation, in case you want to change it's framerate or something (For different speeds)
         (Just in case: I recommend you cache it instead of calling findAnimation all the time)
removeAnimation(name):   In case you want to CHANGE an animation, you need to remove it first (useful for extending classes, like special enemies with a changed behaviour)
FIX: randomFrame/specificFrame() now can work with "facing" (before it returned to frame 0 always). Useful for random debris objects that can change direction if held (like Spelunky's debris)

@FlxState
_layer (FlxLayer): Now the state's internal layer is protected so you can access it if you need.

@FlxText
HACK: To make blurry centered/right justified texts look less blurry
   (The font size must NOT blur in left-align mode. Only sort of works ok for single line texts)

@FlxTilemap
UPGRADE: It can now be changed dynamically during gameplay.
UPGRADE: It has overlap and overlapArray functions to check against overlapping cores.

.widthInTiles [uint]: Now public
.heightInTiles [uint]: Now public
.tileSize [uint]: The tile dimensions, now public

.setTile(tileX, tileY, Index): Set the tile at X/Y to Index
.getTile(tileX, tileY, Index): Get the tile index at X/Y
[constructor] FlxTilemap(MapData, ..., WidthInTiles=0, HeightInTiles=0, FillIndex=0):
   Now if MapData==null, you to create an empty tilemap (e.g. to procedurally generate it using setTile)
   WidthInTiles, HeightInTiles and (optionally) FillIndex will create the tilemap accordingly.

.asCSVString(): Returns a CSV string of the map, in case you want to save it. ( FlxG.log(myMap.asCSVString()); )
.overlap(Core, Callback): Overlaps the tilemap gainst a core.
   The callback function format is:
   callbackFunc(core:FlxCore, tileIndex:uint, tileX:uint, tileY:uint, block:FlxBlock):void
   block is a TEMPORARY block, just so you can use pixel data (block.x/y/width/height). Don't do anything to it.
   Call this before FlxTilemap.collide()/collideArrays().
.overlapArray(CoreArray, Callback): Same as above but for an array of FlxCores
   




================================================================================================
BlxSubStateManager/BlxSubState USAGE EXAMPLE (not compile-tested, but to have an idea)
================================================================================================

Code:
class MyState extends FlxState {
private var _substMgr:BlxSubStateManager;
private var _substInventory:BlxSubState;
private var _substPaused:BlxSubState;

MyState() {
super();

//Create a sub state manager
_substMgr = new BlxSubStateManager;

//Paused will have the highest priority because it's added first
_substPaused = _substMgr.add(new BlxSubState);
_substPaused.add(new FlxText(... "PAUSED" ...));

//Then (if not paused) the inventory will have more priority than the game
_substInventory = _substMgr.add(new MyCustomBlxSubState);
_substInventory.haltsGame = false; //inventory shouldn't make the game stop

//...game stuff here...
}

override public function render():void {
super.render();
_substMgr.render(); //rendered after the state
}

override public function update():void {
//FIRST DO STUFF THAT ALWAYS NEEDS TO GET EXECUTED
if(FlxG.justPressed(FlxG.A))
_substInventory.toggle();

if(...something...)
_substPaused.toggle();

if(_substMgr.handle()) //if true, some substate was handled
return;

//IF NO SUB STATE WAS HANDLED, DO THE REGULAR GAME STUFF
super.update();
}
}

   
« Last Edit: Fri, Nov 6, 2009 by nitram_cero » Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
Merve
Newbie
*
Posts: 39


View Profile
« Reply #1 on: Wed, Sep 23, 2009 »

This is pretty damn epic, I love the substate stuff.
Logged
mklee
Jr. Member
**
Posts: 68


View Profile
« Reply #2 on: Wed, Sep 23, 2009 »

Sweet Nitram, go right ahead and throw in any modifications you want!
Logged
allenp
Jr. Member
**
Posts: 54


View Profile WWW
« Reply #3 on: Thu, Sep 24, 2009 »

Lots of great stuff in here! I'm definitely going to try out some of that substate goodness!
Logged
nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« Reply #4 on: Thu, Sep 24, 2009 »

Thank you guys  Smiley

On release "B" I'll be adding
  • * mklee's alpha stuff on FlxText/Button
  • * Merve's "FlxG.saved" approach to locally save data
  • * I'll pass FlxInputText.multiline to FlxText.wordWrap (got the idea from EstoyPensando)
  • * And probably some other goodies of my own  Smiley

I'm really happy with the FlxTilemap modification, be sure to check it out!
Any bugs you find, please post them on this thread!

Regards
-Martín
« Last Edit: Thu, Sep 24, 2009 by nitram_cero » Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
Titch
Sr. Member
****
Posts: 251


Thing with the guy in the place.


View Profile
« Reply #5 on: Thu, Sep 24, 2009 »

Oho this is neat. I might try and hook it up to Level Up. Some of the text and framerate control stuff would be really handy.
Logged

Free cake whippings every day at #flixel on irc.freenode.net.
nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« Reply #6 on: Sat, Sep 26, 2009 »

The framerate const doesn't control the framerate in real time. It's just the base framerate before everything is created.
If you want to change it dynamically you can do something like this (if I remember right):

Code:
FlxG.state.frameRate = FlxG.state.parent.frameRate = FlxG.state.parent.parent.frameRate = SOMETHING
Because children Sprites (Flash Sprites) inherit the parent's framerate (apparently) this is the only way I found that works.
« Last Edit: Sat, Sep 26, 2009 by nitram_cero » Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« Reply #7 on: Tue, Sep 29, 2009 »

B-FLIXEL [ v1.25-B ] RELEASED!

Changelog

================================================================================================
B-FLIXEL: A Flixel branch - v1.25-B
================================================================================================

--- Added 2 fonts ---
Added 2 free-license fonts I fancy: small (5px font) and blobby (reminds me of bubble bobble).

--- Wordwrapping in FlxText ---
FlxText.wordWrap [Boolean]
BlxInputText.multiline removed. Use FlxInputText.wordWrap instead (inherited from FlxText)

--- Avoding multi-handling of the same mouse click ---
FlxG.wasClickHandled()   Returns if a mouse click was already handled.
         Implemented in FlxButton. Avoids double clicks on buttons.
FlxG.handleClick()   Allows you to mark the click as handled and avoid buttons being pressed.

--- Alpha on FlxText/FlxButton ---
Community user mklee's alpha for FlxText & FlxButton.

--- Save data locally ---
Community user Merve's "FlxG.saved" shared object to save data locally
Usage (strict mode):
Save:
   FlxG.saved["highscore"] = highscore;
   FlxG.saved.flush();
Load:
   highscore = FlxG.saved["highscore"];

--- Kongregate API ---

Included AdamAtomic's FlxKong


--- FlxFactory better site-locking ---
More secure site-locking
Instead of just checking if it contains a string, it's checked from the beginning.
Of course it remains backward compatible if you don't set the sitelockURLs variable.

protected var sitelockURLs:Array;
   You assign this array on your preloader.
   You add stuff like "yoursite.com" and then is prefixed with "http://" and "https://" in combination with "www." prefix and just plain link.
   i.e. ["mysite.com"] will check against:
   http://mysite.com
   http://www.mysite.com
   https://mysite.com
   https://www.mysite.com

protected var playableFromHarddisk:Boolean = true;
   Adds ["file://", "http://localhost", "https://localhost" ] to the sitelocked list. It's the best for debugging (also "release testing") sitelocked versions on your own pc.
   Perhaps someone wants to disable this to avoid players downloading the game and forcing them back to their portal?...

protected var myLinkURL:String;
   this is the link showed in the sitelock screen (instead of using myURL)
   Two reasons
   1. If someone steals your flash game, you might want to point to your own site instead of the portal.
   2. If you are using sitelockURLs, well, you have to choose a link to show anyway.
   By default is equal to myURL if not set, or to sitelockURLs[0] if it's not empty.

« Last Edit: Tue, Sep 29, 2009 by nitram_cero » Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
Vexhel
Newbie
*
Posts: 19


Huh?


View Profile
« Reply #8 on: Wed, Sep 30, 2009 »

Wow amazing work.
Btw: while merging your files with my own, I noticed that in FlxTilemap's render function you forgot to delete some useless operations tied to the old rendering system without rectsPerType. They are just a few lines, but since they are inside the render function (and some of them even within for loops) they could have a minimal impact on performances and there's no reason why they should be left there Smiley
I commented them out so that you can see clearly to which lines I'm referring

FlxTilemap.as, Line 115:
Code:
//////var ri:int = ty*widthInTiles+tx;
_p.x += tx*tileSize;
_p.y += ty*tileSize;
var opx:int = _p.x;
var c:uint;
//////var cri:uint;
for(var r:uint = 0; r < _screenRows; r++)
{
//////cri = ri;
for(c = 0; c < _screenCols; c++)
{
var tile:uint = _data[c+tx+(ty+r)*widthInTiles];
if(tile >= _drawIndex)
FlxG.buffer.copyPixels(_pixels,_rectsPerType[tile],_p,null,null,true);

/*if(_rects[cri] != null)
FlxG.buffer.copyPixels(_pixels,_rects[cri],_p,null,null,true);*/
//////cri++;
_p.x += tileSize;
}
/////ri += widthInTiles;
_p.x = opx;
_p.y += tileSize;
}
Logged

nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« Reply #9 on: Wed, Sep 30, 2009 »

You're right! thanks for the fix, I'll patch it in version "...-C"
Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
Socapex
Full Member
***
Posts: 155


View Profile
« Reply #10 on: Fri, Oct 2, 2009 »

Will these changes be merged into flixel 1.3?
Logged

Free cake every day at #flixel on irc.freenode.net.
Use your favorite IRC client or  http://webchat.freenode.net/
nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« Reply #11 on: Sat, Oct 3, 2009 »

Yup, that's the idea.

The versioning is like this: Flixel version number + B-Flixel version letter.

I'll do my best to keep my interface (and trace a DEPRECATED log on the call or something) if the original changes (Like if Adam implementas a FlxButton with URL functionality... I would just extend an empty class from it)

Regards!
Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
Socapex
Full Member
***
Posts: 155


View Profile
« Reply #12 on: Sat, Oct 3, 2009 »

Sweeeeeeet Smiley
Logged

Free cake every day at #flixel on irc.freenode.net.
Use your favorite IRC client or  http://webchat.freenode.net/
beef
Newbie
*
Posts: 9



View Profile
« Reply #13 on: Tue, Oct 20, 2009 »

great work, man  Grin
Logged
nitram_cero (2bam)
Sr. Member
****
Posts: 473



View Profile WWW
« Reply #14 on: Tue, Oct 20, 2009 »

I have a bunch of fixes for B-Flixel (specially in FlxFactory), but want to start using github so it's more confortable for everybody.

Also I'm working on two games and on Flan for the fricking Mac xD, please sorry for the delays.
Logged

2BAM
I Hate Islands, SpaceCoffee, Finding Her, Caverns, Explosive Cats, The Duke, Run, A View on Relationships, RabbitClock's Quest
Pages: [1] 2
  Print  
 
Jump to: