Skip to content

Wrong bounds in scaled objects #16

@eXponenta

Description

@eXponenta

Related AwayFL.

getBounds return twice scaled bounds rectangle when Sprite is scaled.

AS3 test code:

import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.display.MovieClip;
import flash.geom.Point;

var node: Sprite = new Sprite();
var dot: Sprite = new Sprite();
var bounds: Sprite = new Sprite();

bounds.graphics.lineStyle(2, 0x0000ff);

addChild(node);
addChild(dot);
addChild(bounds);

dot.x = 100;
dot.y = 0;

dot.graphics.beginFill(0x0);
dot.graphics.drawCircle(0,0, 10);

node.scaleX = 0.5;
node.scaleY = 0.5;

node.graphics.beginFill(0x00ff00);
node.graphics.drawCircle(0,0, 100);

node.x = 275;
node.y = 200;


const t: Timer = new Timer(500);

var p0;
var p1;

t.addEventListener(TimerEvent.TIMER, function(e: *) {
	node.rotation += 45;
	
	var pos = node.localToGlobal(new Point(100,0));
	
	dot.x = pos.x;
	dot.y = pos.y;
	
	var r = node.getBounds(null);
	p0 = new Point(r.x,r.y);
	p1 = new Point(r.x + r.width, r.y + r.height);
	
	p0 = node.localToGlobal(p0);
	p1 = node.localToGlobal(p1);
	
	bounds.graphics.clear();
	bounds.graphics.lineStyle(2, 0x0000ff);
	
	bounds.graphics.drawRect(p0.x, p0.y, p1.x - p0.x, p1.y - p0.y);
})

t.start();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions