Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1.  
  2.  
  3.  
  4. Phaser.BitmapData.prototype.generateTexture = function(key) {
  5.  
  6. var copyCanvas = PIXI.CanvasPool.create(this, this.width, this.height);
  7. var copyContext = copyCanvas.getContext('2d', {
  8. alpha: true
  9. });
  10. copyContext.putImageData(this.ctx.getImageData(0, 0, this.width, this.height), 0, 0);
  11. var texture = PIXI.Texture.fromCanvas(copyCanvas);
  12.  
  13. // PIXI.Texture.addTextureToCache(texture, key); //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  14. return texture;
  15. };
  16.  
  17. Phaser.Component.LoadTexture.prototype.loadTexture = function(key, frame, stopAnimation) {
  18.  
  19. if (key === Phaser.PENDING_ATLAS) {
  20. key = frame;
  21. frame = 0;
  22. } else {
  23. frame = frame || 0;
  24. }
  25.  
  26. if ((stopAnimation || stopAnimation === undefined) && this.animations) {
  27. this.animations.stop();
  28. }
  29.  
  30. this.key = key;
  31. this.customRender = false;
  32. var cache = this.game.cache;
  33.  
  34. var setFrame = true;
  35. var smoothed = !this.texture.baseTexture.scaleMode;
  36.  
  37. if (Phaser.RenderTexture && key instanceof Phaser.RenderTexture) {
  38. this.key = key.key;
  39. this.setTexture(key);
  40. } else if (Phaser.BitmapData && key instanceof Phaser.BitmapData) {
  41. this.customRender = true;
  42.  
  43. this.setTexture(key.texture);
  44.  
  45. if (cache.hasFrameData(key.key, Phaser.Cache.BITMAPDATA)) {
  46. setFrame = !this.animations.loadFrameData(cache.getFrameData(key.key, Phaser.Cache.BITMAPDATA), frame);
  47. } else {
  48. setFrame = !this.animations.loadFrameData(key.frameData, 0);
  49. }
  50. } else if (Phaser.Video && key instanceof Phaser.Video) {
  51. this.customRender = true;
  52.  
  53. // This works from a reference, which probably isn't what we need here
  54. var valid = key.texture.valid;
  55. this.setTexture(key.texture);
  56. this.setFrame(key.texture.frame.clone());
  57. key.onChangeSource.add(this.resizeFrame, this);
  58. this.texture.valid = valid;
  59. } else if (Phaser.Tilemap && key instanceof Phaser.TilemapLayer) {
  60. // this.customRender = true;
  61. this.setTexture(PIXI.Texture.fromCanvas(key.canvas));
  62. } else if (key instanceof PIXI.Texture) {
  63. this.setTexture(key);
  64. } else if (typeof PIXI.TextureCache[key] !== "undefined") //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  65. {
  66. this.setTexture(PIXI.TextureCache[key]);
  67. } else {
  68. var img = cache.getImage(key, true);
  69.  
  70. this.key = img.key;
  71. this.setTexture(new PIXI.Texture(img.base));
  72.  
  73. if (key === '__default') {
  74. this.texture.baseTexture.skipRender = true;
  75. } else {
  76. this.texture.baseTexture.skipRender = false;
  77. }
  78.  
  79. setFrame = !this.animations.loadFrameData(img.frameData, frame);
  80. }
  81.  
  82. if (setFrame) {
  83. this._frame = Phaser.Rectangle.clone(this.texture.frame);
  84. }
  85.  
  86. if (!smoothed) {
  87. this.texture.baseTexture.scaleMode = 1;
  88. }
  89.  
  90. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement