-
Notifications
You must be signed in to change notification settings - Fork 435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Efficient FlxKey#toString, FlxTileblock#setTile, overridable FlxState#open/close #1300
Changes from 9 commits
aadbb60
92b12d9
2d35156
fa8029b
412adff
c31b20f
e68a3b0
b2f5559
f430250
1b447a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import flixel.system.FlxAssets.FlxGraphicAsset; | |
import flixel.system.layer.DrawStackItem; | ||
import flixel.math.FlxAngle; | ||
import flixel.math.FlxRandom; | ||
import flixel.util.FlxDestroyUtil; | ||
import flixel.util.FlxSpriteUtil; | ||
|
||
/** | ||
|
@@ -15,6 +16,8 @@ import flixel.util.FlxSpriteUtil; | |
*/ | ||
class FlxTileblock extends FlxSprite | ||
{ | ||
private var tileSprite:FlxSprite; | ||
|
||
/** | ||
* Creates a new FlxBlock object with the specified position and size. | ||
* | ||
|
@@ -32,6 +35,11 @@ class FlxTileblock extends FlxSprite | |
moves = false; | ||
} | ||
|
||
override public function destroy():Void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
tileSprite = FlxDestroyUtil.destroy(tileSprite); | ||
super.destroy(); | ||
} | ||
|
||
/** | ||
* Fills the block with a randomly arranged selection of graphics from the image provided. | ||
* | ||
|
@@ -48,21 +56,21 @@ class FlxTileblock extends FlxSprite | |
} | ||
|
||
// First create a tile brush | ||
var sprite:FlxSprite = new FlxSprite().loadGraphic(TileGraphic, true, TileWidth, TileHeight); | ||
var spriteWidth:Int = Std.int(sprite.width); | ||
var spriteHeight:Int = Std.int(sprite.height); | ||
var total:Int = sprite.frames + Empties; | ||
tileSprite = new FlxSprite().loadGraphic(TileGraphic, true, TileWidth, TileHeight); | ||
var spriteWidth:Int = Std.int(tileSprite.width); | ||
var spriteHeight:Int = Std.int(tileSprite.height); | ||
var total:Int = tileSprite.frames + Empties; | ||
|
||
// Then prep the "canvas" as it were (just doublechecking that the size is on tile boundaries) | ||
var regen:Bool = false; | ||
|
||
if (width % sprite.width != 0) | ||
if (width % tileSprite.width != 0) | ||
{ | ||
width = Std.int((width / spriteWidth + 1)) * spriteWidth; | ||
regen = true; | ||
} | ||
|
||
if (height % sprite.height != 0) | ||
if (height % tileSprite.height != 0) | ||
{ | ||
height = Std.int((height / spriteHeight + 1)) * spriteHeight; | ||
regen = true; | ||
|
@@ -94,9 +102,9 @@ class FlxTileblock extends FlxSprite | |
{ | ||
if (FlxG.random.float() * total > Empties) | ||
{ | ||
sprite.animation.randomFrame(); | ||
sprite.drawFrame(); | ||
stamp(sprite, destinationX, destinationY); | ||
tileSprite.animation.randomFrame(); | ||
tileSprite.drawFrame(); | ||
stamp(tileSprite, destinationX, destinationY); | ||
} | ||
|
||
destinationX += spriteWidth; | ||
|
@@ -107,8 +115,13 @@ class FlxTileblock extends FlxSprite | |
row++; | ||
} | ||
|
||
sprite.destroy(); | ||
dirty = true; | ||
return this; | ||
} | ||
|
||
public function setTile(x:Int, y:Int, index:Int):Void { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The usefulness of this function might be a bit limited considering that Useful nevertheless. :) |
||
tileSprite.animation.frameIndex = index; | ||
stamp(tileSprite, x * Std.int(tileSprite.width), y * Std.int(tileSprite.height)); | ||
dirty = true; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm... this is getting a bit excessive with two maps, should probably use a macro for this. The
FlxColor
macro already does something very similar.Btw,
FlxAndroidKey
would need the same fix.