lundi 29 juin 2015

Shouldn't parent Sprite dimensions reflect child content size?

I'm trying to track down a separate issue but I noticed an oddity I don't understand.

I have a Sprite into which I load two Bitmaps as children (code below). Then I have a function which sets size and position based on some XML settings.

I never set the size of the parent Sprite explicitly and so expect it to reflect the overall size of its children.

This is the Console output after setting the children size. The height of the parent is reported as 4 px greater than the child contents. I don't understand this. Both children are at (0,0) and are 200 x 200. Why is the container Sprite 4 px taller?

     canvas 1024 768
     this dimensions 200 204.1 // <--- INCREASE OF 4 PX
     this xy 200 200
     buttonImage dimension 200 200
     buttonImage xy 0 0
     hitSprite dimension 200 200
     hitSprite xy 0 0

Code setting/reporting dimensions:

            this.buttonImage.width = newWidth;
            this.buttonImage.height = newHeight;
            this.hitSprite.width = newWidth;
            this.hitSprite.height = newHeight;

            trace("\t canvas", canvas.width, canvas.height);
            trace("\t this dimensions", this.width, this.height);
            trace("\t this xy", this.x, this.y);
            trace("\t buttonImage dimension", this.buttonImage.width, this.buttonImage.height);
            trace("\t buttonImage xy", this.buttonImage.x, this.buttonImage.y);
            trace("\t hitSprite dimension", this.hitSprite.width, this.hitSprite.height);
            trace("\t hitSprite xy", this.hitSprite.x, this.hitSprite.y);

Creating Sprite children:

                buttonImage = new Bitmap(upImageData);
                buttonImage.smoothing = true;

                hitSprite = createHitArea(upImageData, 4);
                hitSprite.visible = false;
                hitSprite.mouseEnabled = false;
                this.hitArea = hitSprite;

Aucun commentaire:

Enregistrer un commentaire