开发者

AS3 Bitmaps are too large and improperly placed

Alright I'm programming in actionscript 3, using flex as a compiler. I have an 16x16 large PNG file that is basically a square outline like this:

http://wiki.urbandead.com/images/1/1c/Square.gif

But in more noticeable colors.

I want to draw an 11x11 grid of these squares, so I use these for loops:

        for (i1 = 0; i1 < 11; i1 ++) 
        { 
            for (i2 = 0; i2 < 11; i2 ++)
            {
                new OBJECT_tile().CREATE(CONTAINER,32 + 16*i1,32 + 16*i2); 
            }
        }开发者_C百科

Where the CREATE() function makes a new tile object with the container CONTAINER with the given x and y coordinates.

public class OBJECT_tile extends Sprite
{
    public var X:Number;    public var Y:Number;
    public var DEPTH:int = 10 ;
    public var SPRITE:Sprite = new Sprite();
    public var BITMAP:Bitmap;
    public var CONTAINER:Sprite = new Sprite();

    [Embed(source = 'TILE.png')]
    private var CLASS_IMAGE:Class;      
    private var IMAGE:Bitmap = new CLASS_IMAGE();

    public function CREATE(CONTAINER:Sprite,X:Number,Y:Number):void
    {   
        var DATA:BitmapData = new BitmapData(16,16,true,0);
        DATA.draw(IMAGE);
        BITMAP = new Bitmap(DATA);
        BITMAP.smoothing = false;
        addChild(BITMAP);

        this.CONTAINER = CONTAINER;
        (CONTAINER as MAIN).INSTANCE_LIST[(CONTAINER as MAIN).INSTANCE_LIST.length] = this;
        this.X = X; BITMAP.x = this.X;
        this.Y = Y; BITMAP.y = this.Y;
        DRAW();
    }}

However for some reason the tiles are drawn to twice their size (32x32 instead of 16x16) and tend to bunch up or spread out depending on how many tabs I have open in my browser. The bunching up isn't consistent either, for instance the tiles might for a 3x3 group that's perfectly fine but then there will just be a line of messed up tiles next to that group (really hard to describe). Why is this happening?


Okay I figured it out. It turns out as3 will try to scale things behind your back, I'm guessing this is some kind of holdout from Adobe's ide (I detest the thing and program in notepad++). Anyways if you stick this:

stage.scaleMode = StageScaleMode.NO_SCALE;

In your main function it will stop it from scaling unless you say otherwise.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜