2014-09-23 65 views
1

我正在通過代碼創建圖形並將它們放置到位圖中。但是它們比這個Bitmap容器更高。位圖對於其內容太小

import flash.display.*; 

function getLine(){   
    var containerWidh:Number =enter code here 300; 
    var containerHeight:Number = 300; 
    var borderWidt:Number = 1; 
    var spriteWrap:Sprite = new Sprite(); 

    var innerContainer:Sprite = new Sprite(); 
    innerContainer.x = 0; 
    innerContainer.y = 0; 

    var line1:Shape = new Shape(); 
    line1.graphics.lineStyle(5, 0x6F4356, 1, false, StageScaleMode.SHOW_ALL, CapsStyle.ROUND); 
    line1.graphics.moveTo(50, 5); 
    line1.graphics.lineTo(50, 800); 
    line1.graphics.endFill(); 

    var line2:Shape = new Shape(); 
    line2.graphics.lineStyle(5, 0x6F4356, 1, false, StageScaleMode.SHOW_ALL, CapsStyle.ROUND); 
    line2.graphics.moveTo(200, 290); 
    line2.graphics.lineTo(200, 300); 
    line2.graphics.endFill(); 

    innerContainer.addChild(line1); 
    innerContainer.addChild(line2); 
    spriteWrap.addChild(innerContainer);  

    return spriteWrap; 
} 

var spriteWrap:Sprite = getLine(); 
var wrapForBitmap:Sprite = new Sprite();    
var drawBitmap:BitmapData = new BitmapData(300, 300, true, 0x00ffaa); 
var goOnStage:Bitmap = new Bitmap(drawBitmap); 
wrapForBitmap.graphics.beginBitmapFill(drawBitmap); 
wrapForBitmap.graphics.lineStyle(1, 0x6F7E84); 
wrapForBitmap.graphics.drawRect(0, 0, 300, 300); 
wrapForBitmap.graphics.endFill(); 
wrapForBitmap.x = 10; 
wrapForBitmap.y = 10; 

drawBitmap.draw(spriteWrap, new Matrix(1, 0, 0, 1, 0, 0)); 

wrapForBitmap.addChild(goOnStage); 
stage.addChild(wrapForBitmap); 

回答

0

你的外形一號線是不是你的位圖的高度(300)高:

line1.graphics.moveTo(50, 5); // begins at x = 50 and y = 5 
line1.graphics.lineTo(50, 800); // begins at x = 50 and y = 800 

用下面的代碼,你會畫一條線從頂部到您的位圖的底部:

line1.graphics.moveTo(50, 0); 
line1.graphics.lineTo(50, 300); 

如果要讓line1在不更改高度的情況下可見,則必須通過修改BitmapData方法的第二個參數來更改Bitmap的高度(800):

var drawBitmap:BitmapData = new BitmapData(300, 800, true, 0x00ffaa); 

你應該在同一時間修改矩形的高度:

當然
wrapForBitmap.graphics.drawRect(0, 0, 300, 800); 
+0

是的,我知道它,但有沒有辦法將位圖高度更改爲800? – 2014-09-23 21:12:18

+0

@СтасПишевский - 我編輯了我的答案。 – helloflash 2014-09-24 05:02:48

+0

@СтасПишевский - 它工作嗎? – helloflash 2014-09-27 07:17:50

1

是。比我用我的雪碧重繪我的位圖

MySprite.graphics.clear(); 
MySprite.graphics.beginBitmapFill(MyBitmap, new Matrix(1, 0, 0, 1, new_XPos, new_YPos), false, false); 
MySprite.graphics.endFill();