Skip to content

Commit

Permalink
Fix #355, Update texture with .asSprite() method
Browse files Browse the repository at this point in the history
  • Loading branch information
eonarheim committed Nov 14, 2014
1 parent 9e5f53a commit ffdae12
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/engine/Loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module ex {
public height: number;
public loaded: Promise<any> = new Promise<any>();
private _isLoaded: boolean = false;
private _sprite: Sprite = null;

/**
* Populated once loading is complete
Expand All @@ -33,6 +34,7 @@ module ex {

constructor(public path: string) {
super(path, 'blob');
this._sprite = new Sprite(this, 0, 0, 0, 0);
}


Expand All @@ -59,6 +61,8 @@ module ex {
this.image = new Image();
this.image.addEventListener("load", ()=>{
this._isLoaded = true;
this.width = this._sprite.swidth = this._sprite.width = this.image.naturalWidth;
this.height = this._sprite.sheight = this._sprite.height = this.image.naturalHeight;
this.loaded.resolve(this.image);
complete.resolve(this.image);
});
Expand All @@ -71,6 +75,10 @@ module ex {
return complete;
}

public asSprite(): Sprite {
return this._sprite;
}

}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/engine/Sprite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ module ex {
this.spriteCanvas.height = sheight;
this.spriteCtx = this.spriteCanvas.getContext('2d');
this.texture.loaded.then(()=>{
this.spriteCanvas.width = this.spriteCanvas.width || this.texture.image.naturalWidth;
this.spriteCanvas.height = this.spriteCanvas.height || this.texture.image.naturalHeight;
this.loadPixels();
this.dirtyEffect = true;
}).error((e)=>{
Expand Down

0 comments on commit ffdae12

Please sign in to comment.