ippa / jaws

Jaws - HTML5 canvas javascript 2D Game Framework
https://jawsjs.ippa.se
GNU Lesser General Public License v3.0
364 stars 75 forks source link

Cannot rotate sprite properly #105

Open EliasZ opened 10 years ago

EliasZ commented 10 years ago

Great library but I am finding difficulties with rotating a sprite properly. I used to work with this:

context.save();
context.beginPath();
context.translate(xCenter, yCenter);
context.scale(1, 0.5);
context.scale(2.75, 2.75);
context.rotate(-rot);
context.translate(-128, -128);
context.drawImage(image, 0, 0);
context.closePath();
context.restore();

The result is an isometric rotation.

But with JawsJS I find it hard to invoke these methods on the context in that order because the draw function is very limited. What would be a correct approach?

ippa commented 10 years ago

With jaws you just do sprite = new jaws.Sprite({anchor: "center"})

and

jaws.angle = xxx

On 2013-10-06 11:29, EliasZ wrote:

Great library but I am finding difficulties with rotating a sprite around its center. Looking at Sprite its draw() function, this is currently not possible - am I correct?

Example http://www.williammalone.com/briefs/how-to-rotate-html5-canvas-around-center/

— Reply to this email directly or view it on GitHub https://github.com/ippa/jaws/issues/105.

ippa commented 10 years ago

http://jawsjs.com/jawsjs/examples/example5.html <-- different anchors visualized

EliasZ commented 10 years ago

Yes, but I couldn't get it to do isometric rotation properly due to the limitations the Sprite.draw function has. So I overrode the draw method in setup.

ippa commented 10 years ago

You do have detail-control over the rotation-point with sprite.anchor_x and sprite.anchor_y. But I've never done isometric rotations so I can't comment on that.

On 2013-10-06 14:57, EliasZ wrote:

Yes, but I couldn't get it to do isometric rotation properly due to the limitations the Sprite.draw function has.

— Reply to this email directly or view it on GitHub https://github.com/ippa/jaws/issues/105#issuecomment-25767634.

EliasZ commented 10 years ago

For now, I will just override the specific draw method. Thanks for the help.

Another question which doesn't really need a new topic: there is this jaws.Text helper system but in all the demos traditional text rendering is used (directly performing textual stuff on jaws.context). Does this have a reason? Should jaws.Text only be used if you want more control?

ippa commented 10 years ago

Text was a late addition to jaws, most of the existing small examples was done by then. It's a free choice if you want to use it or not. Text was a contribution to jaws .. and I've started using it more and more myself :)