2016-04-01 9 views
0

フェイザーでビットマップから画像を作成することは可能ですか?画像へのフェイザービットマップ

私がしようとしていたのは、スプライトを台形に変形/再形成することでした。

/** 
* Created by Ken Fyrstenberg/Epistemex 
* License: CC3.0-Attr. 
* 
*/ 

function drawTrapezoid(ctx, img, x, y, w, h, factor) { 
    var startPoint = x + w * 0.5 * (factor * 0.01), 
      xi, yi, scale = img.height/h, 
      startLine = y, 
      endLine = y + h; 

    for(; y < endLine; y++) { 

     xi = interpolate(startPoint, y, x, endLine, (y - startLine)/h); 
     yi = (y * scale + 0.5) | 0; 

     ctx.drawImage(img, 0, yi, img.width, 1, xi, y, w - xi * 2, 1); 
    } 

    function interpolate(x1, y1, x2, y2, t) { 
     return x1 + (x2 - x1) * t; 
    } 
} 

  1. ロードスプライトアトラス
  2. 以下の機能を使用して台形 に変換するビットマップデータを再描画ビットマップデータにスプライトを再描画キャンバス

  3. にスプライトを追加します

問題はこれです。関数はimageを使用して再描画します。私はビットマップデータしか持っていません。 bitmapdata.generateImage();のようなビットマップデータから画像を作成することは可能ですか?

答えて

0
var image = game.add.image(0, 0, bitmapdata); // x, y, key for the image 

シンプルなものです。画像の代わりにスプライトが必要な場合は同じです:game.add.sprite(0, 0, bitmapdata)

関連する問題