Closed phantomxc closed 12 years ago
Hm, I don't see any reasons why it shouldn't. "anchor_y" for example, it basically just used in two places:
this.top_offset = this.height * this.anchor_y
this.bottom_offset = this.height * (1.0 - this.anchor_y)
that's from jaws.Sprite's cacheOffset()
Are you sure you're not doing anything else strange? Or that it works but you don't notice it.
I've pushed an example to the following repo
https://github.com/phantomxc/Boom
in game.html you will see the rotation of the turret is using the default anchor even though I pass in an anchor_x and anchor_y.
in modifiedgame.html the only difference is the inclusion of modifiedjaws.js
I only discovered your awesome library last night so forgive me if I'm missing something :)
Right, looking deeper into jaws.Sprite.prototype.draw() I notice jaws doesn't look at anchor_x/y when rotating, only when drawing the final sprite. We need to do this.context.translate(-this.left_offset, -this.top_offset)
.. Before ... jaws.context.rotate(this.angle * Math.PI / 180)
for that to work.
I'm not 100% sure we want that though. Maybe we want two new properties, rotation_anchor_x, rotation_anchor_y (or similar). For example a simple platformer.. we wan't the players feet to be the anchor for drawing, so we set anchor_y = 1 ... but when he dies you want him to rotate around his own angle (which would mean anchor_x/y = 0.5).
What's your thoughts on this?
I'm not sure I understand why "if(!options.anchor_x == undefined)" couldn't just be modified as that never evaluates. If that evaluates, everything seems to work just fine.
However, an option named rotation_anchor_x/y clearly tells you it's purpose so I wouldn't mind that either.
Fixed in https://github.com/ippa/jaws/commit/faa7787a08a378ab0e8c5f8562f17d0ff722ac44 .. thanks for the report!
I believe you intended for custom sprite anchor points at one time but it doesn't appear the code is working.
lines 1145 and 1146 in jaws.js have the following:
The following code doesn't seem to work without modification: