-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable different ways of rendering frames:
* Traditionally, with a single bitmapData for every frame * By drawing a rect from one single bitmap data * Using tilesheets For this render targets are introduced, which render into a "graphics" object. For now the graphics object is the "graphics" member of the AnimatedSprite. Also: Introduced flag for rendering with "ADD" blendMode. Due to some issue, rendering with blendmode "Add" works only using tilesheets on C++ targets and by setting "blendMode" of the sprite on flash target.
- Loading branch information
1 parent
d458e1d
commit 81453cd
Showing
7 changed files
with
188 additions
and
28 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package spritesheet.render; | ||
|
||
import spritesheet.data.SpritesheetFrame; | ||
import spritesheet.AnimatedSprite; | ||
|
||
interface IRenderTarget { | ||
function drawFrame(frame : SpritesheetFrame, offsetX : Float, offsetY : Float, smoothing : Bool) : Void; | ||
function enableFlag(flag : Flag) : Void; | ||
function disableFlag(flag : Flag) : Void; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package spritesheet.render; | ||
|
||
import spritesheet.data.SpritesheetFrame; | ||
import flash.display.Sprite; | ||
import flash.display.BlendMode; | ||
import spritesheet.AnimatedSprite; | ||
|
||
class RenderBitmapRectToGraphics implements IRenderTarget { | ||
private var sprite : Sprite; | ||
public function new(o : Sprite) {this.sprite = o;} | ||
public function drawFrame(frame : SpritesheetFrame, offsetX : Float, offsetY : Float, smoothing : Bool) { | ||
var m = new flash.geom.Matrix(); | ||
m.translate(offsetX + frame.offsetX - frame.x, offsetY + frame.offsetY - frame.y); | ||
sprite.graphics.clear(); | ||
sprite.graphics.beginBitmapFill(frame.bitmapData, m, false, smoothing); | ||
sprite.graphics.drawRect(offsetX + frame.offsetX,offsetY + frame.offsetY,frame.width, frame.height); | ||
sprite.graphics.endFill(); | ||
} | ||
public function enableFlag(flag : Flag) { | ||
switch(flag) { | ||
case BLEND_ADD: | ||
sprite.blendMode = BlendMode.ADD; | ||
} | ||
} | ||
public function disableFlag(flag : Flag) { | ||
switch(flag) { | ||
case BLEND_ADD: | ||
sprite.blendMode = BlendMode.NORMAL; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package spritesheet.render; | ||
|
||
import openfl.display.Tilesheet; | ||
import spritesheet.data.SpritesheetFrame; | ||
import flash.display.Sprite; | ||
import spritesheet.AnimatedSprite; | ||
|
||
class RenderTilesheetToGraphics implements IRenderTarget { | ||
private var sprite : Sprite; | ||
private var tilesheet : Tilesheet; | ||
private var flags : Int = 0; | ||
public function new(o : Sprite, tilesheet : Tilesheet) { | ||
this.sprite = o; | ||
this.tilesheet = tilesheet; | ||
} | ||
public function drawFrame(frame : SpritesheetFrame, offsetX : Float , offsetY : Float, smoothing : Bool) { | ||
sprite.graphics.clear(); | ||
tilesheet.drawTiles(sprite.graphics, [offsetX + frame.offsetX,offsetY + frame.offsetY, frame.tilesheetIndex], smoothing, flags); | ||
} | ||
public function enableFlag(flag : Flag) { | ||
switch(flag) { | ||
case BLEND_ADD: | ||
flags = flags | Tilesheet.TILE_BLEND_ADD; | ||
} | ||
} | ||
public function disableFlag(flag : Flag) { | ||
switch(flag) { | ||
case BLEND_ADD: | ||
flags &= 0xFFFFFFF - Tilesheet.TILE_BLEND_ADD; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package spritesheet.render; | ||
|
||
import flash.display.Sprite; | ||
import flash.display.BlendMode; | ||
import spritesheet.AnimatedSprite; | ||
|
||
class RenderWholeBitmapToGraphics implements IRenderTarget { | ||
private var sprite : Sprite; | ||
public function new(o : Sprite) {this.sprite = o;} | ||
public function drawFrame(frame : spritesheet.data.SpritesheetFrame, offsetX : Float, offsetY : Float, smoothing : Bool) { | ||
var m = new flash.geom.Matrix(); | ||
m.translate(offsetX + frame.offsetX, offsetY + frame.offsetY); | ||
sprite.graphics.clear(); | ||
sprite.graphics.beginBitmapFill(frame.bitmapData, m, false, smoothing); | ||
sprite.graphics.drawRect(offsetX + frame.offsetX, offsetY + frame.offsetY ,frame.width, frame.height); | ||
sprite.graphics.endFill(); | ||
} | ||
public function enableFlag(flag : Flag) { | ||
switch(flag) { | ||
case BLEND_ADD: | ||
sprite.blendMode = BlendMode.ADD; | ||
} | ||
} | ||
public function disableFlag(flag : Flag) { | ||
switch(flag) { | ||
case BLEND_ADD: | ||
sprite.blendMode = BlendMode.NORMAL; | ||
} | ||
} | ||
} |