位图对于其内容来说太小了

时间:2014-09-23 16:45:09

标签: image actionscript-3 graphics bitmap actionscript

我通过代码创建图形并将它们放入位图。但它们高于此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);

2 个答案:

答案 0 :(得分:1)

当然可以。比我使用我的精灵重绘我的位图

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

答案 1 :(得分:0)

您的Shape line1高于Bitmap的高度(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方法的第二个参数来更改位图的高度(800):

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

您应该同时修改矩形的高度:

wrapForBitmap.graphics.drawRect(0, 0, 300, 800);