2016-04-01 34 views
0

是否可以在Phaser中使用位圖創建圖像?Phaser位圖圖像

我想要做的是將sprite變換/重新塑造成梯形。

  1. 負載精靈圖譜
  2. 添加精靈畫布
  3. 重繪子畫面的位圖數據
  4. 重繪的位圖數據使用以下函數變換成梯形 :

    /** 
    * 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; 
        } 
    } 
    

問題是這樣的,函數使用圖像重繪。我只有位圖數據。 是否有可能從bitmapdata像bitmapdata.generateImage();那樣創建圖像?

回答

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

這樣簡單。如果你想要一個精靈而不是一個圖像,也是一樣:game.add.sprite(0, 0, bitmapdata)