Created
August 29, 2014 19:59
-
-
Save lardratboy/437007799a573541226a to your computer and use it in GitHub Desktop.
my default base types for creating Phaser.Sprite and Phaser.Image prefabs for use with bpt_prefab.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Author Brad P. Taylor (bradptaylor+github@gmail.com) license MIT | |
///<reference path="../../../../bower_components/phaser-official/build/phaser.d.ts"/> | |
///<reference path="./prefab.ts"/> | |
module bpt { | |
// ------------------------------------------------------------------------ | |
export class SpritePrefab extends Phaser.Sprite { | |
config():any { return "SpritePrefab.json"; } | |
constructor(game, x?, y?, key?, frame?) { | |
super( game, x, y, key, frame ); | |
bpt.prefab.configPrefab( this, 'Prefab.json' ); | |
bpt.prefab.configPrefab( this, this.config() ); | |
} | |
get animationFrame():any { return 0; } | |
set animationFrame( frame:any ) { | |
if ( this.animations ) { | |
var hack:any = this.animations; | |
if ( !hack.loadFrameData(this.game.cache.getFrameData(this.key), frame) ) { | |
this.resetFrame(); | |
} | |
} | |
} | |
} | |
bpt.prefab.Factory.add( "SpritePrefab", SpritePrefab, undefined, | |
bpt.prefab.helper_transformed_named_args_to_config ); | |
export class ImagePrefab extends Phaser.Image { | |
config():any { return "ImagePrefab.json"; } | |
constructor(game, x?, y?, key?, frame?) { | |
super( game, x, y, key, frame ); | |
bpt.prefab.configPrefab( this, 'Prefab.json' ); | |
bpt.prefab.configPrefab( this, this.config() ); | |
} | |
} | |
bpt.prefab.Factory.add( "ImagePrefab", ImagePrefab, undefined, | |
bpt.prefab.helper_transformed_named_args_to_config ); | |
// ------------------------------------------------------------------------ | |
// aliases for smaller json files | |
bpt.prefab.Factory.addAlias( 'image', 'Phaser.Image' ); | |
bpt.prefab.Factory.addAlias( 'sprite', 'Phaser.Sprite' ); | |
bpt.prefab.Factory.addAlias( 'group', 'Phaser.Group' ); | |
bpt.prefab.Factory.addAlias( 'spriteBatch', 'Phaser.SpriteBatch' ); | |
bpt.prefab.Factory.addAlias( 'batch', 'Phaser.SpriteBatch' ); | |
bpt.prefab.Factory.addAlias( 'text', 'Phaser.Text' ); | |
bpt.prefab.Factory.addAlias( 'tileSprite', 'Phaser.TileSprite' ); | |
bpt.prefab.Factory.addAlias( 'button', 'Phaser.Button' ); | |
bpt.prefab.Factory.addAlias( 'emitter', 'Phaser.Particles.Arcade.Emitter' ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My prefab.json basically sets the anchor to 0.5 by default