Skip to content
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

Avoid copyPixels for full-sheet frames. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions spritesheet/Spritesheet.hx
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,35 @@ class Spritesheet {

var frame = frames[index];

var bitmapData = new BitmapData (frame.width, frame.height, true);
var sourceRectangle = new Rectangle (frame.x, frame.y, frame.width, frame.height);
var targetPoint = new Point ();

bitmapData.copyPixels (sourceImage, sourceRectangle, targetPoint);

if (sourceImageAlpha != null) {
if ( ( frame.x == 0 ) &&
( frame.y == 0 ) &&
( frame.width == sourceImage.width ) &&
( frame.height == sourceImage.height ) &&
( sourceImageAlpha == null ) ) {

// This is the full source image, and no alpha needs to be merged in;
// just reference directly.
//trace( "Spritesheet.generateBitmap: full sheet reused for " + name + " frame " + index );
frame.bitmapData = sourceImage;

} else {

var bitmapData = new BitmapData (frame.width, frame.height, true);
var sourceRectangle = new Rectangle (frame.x, frame.y, frame.width, frame.height);
var targetPoint = new Point ();

bitmapData.copyChannel (sourceImageAlpha, sourceRectangle, targetPoint, 2, 8);
bitmapData.copyPixels (sourceImage, sourceRectangle, targetPoint);

if (sourceImageAlpha != null) {

bitmapData.copyChannel (sourceImageAlpha, sourceRectangle, targetPoint, 2, 8);

}

frame.bitmapData = bitmapData;

}

frame.bitmapData = bitmapData;

}


Expand Down