StageXL icon indicating copy to clipboard operation
StageXL copied to clipboard

getBounds method

Open avstudios opened this issue 12 years ago • 8 comments

getBounds method always adding 2px to width and hight. More details: https://plus.google.com/u/0/109524935899218597554/posts/4u9gU5JMHjD I'm using ToolkitForDart v0.5 and still see the issue.

avstudios avatar Jul 16 '13 10:07 avstudios

The bug is related to StageXL measurement; it's not related to the toolkit.

elsassph avatar Jul 16 '13 10:07 elsassph

Currently i don't have a good idea how to solve this issue. The reason behind this issue is the way how the HTML5 Canvas element draws vector shapes.

Here is a related question on StackOverflow talking about the same problem. http://stackoverflow.com/questions/9311428/draw-single-pixel-line-in-html5-canvas

Here is the stolen picture from the first answer: ygre4

When you draw a rectangle from 0, 0 to 100,100 then the line is actually drawn on the edge of coordinate system. Which means that the line (with width 1) is actually drawn outside of the rectangle.

You would get a better result if you draw the line from 0.5, 0.5 to 99.5, 99.5. With a line width of 1 you would pretty much get the same result as in Flash. It would be easy to change the coordinates for a rectangle in the library, but it is much harder for other generic lines and shapes.

We will keep on thinking about this .....

bp74 avatar Jul 16 '13 16:07 bp74

Let me add one more thing: The "getBounds" method actually returns the "correct" value considering the behavior of the Canvas element. I know this doesn't help much.

bp74 avatar Jul 16 '13 16:07 bp74

That make sense. But so far I tested only shapes without outlines. I have a sprite that contains a simple rectangle or bitmap image 100x200 px. Then I'm getting the sprite size 102x202. In that scenario you include a line even it does not exist?

avstudios avatar Jul 17 '13 10:07 avstudios

Hi Bernhard, Did you have a change to have a look it again. How hard it would be to set bounds to e.g. (x=150, y=250, w=200, h=100) not (x=149, y=249, w=202, h=102) if Sprite has only a basic shape or a bitmap. I don't mind keep current measurement if clip contains outlines. Do you think it's achievable?

avstudios avatar Oct 04 '13 10:10 avstudios

Yes i thought about this every time i looked at the open issues. It is really a hard problem and there is no easy solution without drawbacks.

bp74 avatar Oct 04 '13 14:10 bp74

Thanks for looking at it. I'm sure it's not easy task. I'll try to understand better how stagexl works and maybe I find the solution myself.

avstudios avatar Oct 08 '13 14:10 avstudios

Contributions are highly welcome :+1:

bp74 avatar Oct 08 '13 14:10 bp74