sq / JSIL

CIL to Javascript Compiler
http://jsil.org/
Other
1.73k stars 241 forks source link

SpriteBatch Draw Origin #275

Open iamthefaker opened 11 years ago

iamthefaker commented 11 years ago

The interpretation of SpriteBatch Draw function's Origin parameter is intuitive in JSIL, but it is not the same as the original XNA 4 interpretation.

In the XNA 4 version, this parameter is specified relative to the original size of the texture being supplied to the Draw method of SpriteBatch.

So if you want to position the origin half way down a texture that is 20 pixels tall, you set:

Vector2 origin = new Vector2(0, 10f);

If you run code that is written in this way through the JSIL compiler process, positioning of the rotation origin causes things to end up in the wrong places.

If instead you interpret the origin parameter as relative to the size of the drawn rectangle (which I find more intuitive, but not the way XNA 4 does it) your locations come out wrong in XNA 4, but appear correctly in a JSIL version of the same game.

In other words the same code doesn't work the same way in XNA 4 as it works in a JSIL compilation of the XNA 4 game.

You have to code it one way for XNA4, but then code it deliberately wrongly for the JSIL to produce code that works correctly in the browser.

kg commented 11 years ago

Interesting, thanks.