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

Rotate viewport #109

Open justgage opened 10 years ago

justgage commented 10 years ago

I'm not sure how hard this would be but I think it would be awesome to be able to rotate view-ports.

hornta commented 10 years ago

Will you provice and example of using a rotated viewport? Maybe a minimap which centers on you?

ippa commented 10 years ago

Do you have a special usecase in mind? Code-wise it probably shouldn't be much work due to the flexibility of the canvas. It would be like 1 line to add here:

https://github.com/ippa/jaws/blob/master/src/viewport.js#L152

I would suggest adding it to your local jaws.js for the time being to get a feel for if we really want it there.. you could of course do your context.rotate before whatever canva draw-call in your game code too.. Also I'm a bit busy with clientwork for 2-3 weeks now.

justgage commented 10 years ago

I think it would be good in many situations such as if you had a racing game that you wanted to view to rotate to face whichever way the car is going, a space game like they need to be fed -> http://gmc.yoyogames.com/index.php?showtopic=469713 (where the view would rotate with it the player) I think there's tons of really cool things you could do with it.

ippa commented 10 years ago

mm.. good examples. One thing with rotation is that you also need an anchorpoint. In jaws.Sprite you have setAnchor("center|top_left|bottom_center|etc..."). Thinking if something similar makes sense for the viewport or you usually want more exact control when rotating it.

justgage commented 10 years ago

More control is always better but I would say that the default would be center.

ippa commented 10 years ago

Looking more into this I think it might not be as straightforward as I first thought. If we put rotate in Viewport.apply basically everything will be rotated (of course not a HUD/opther thigns outside of viewport.apply()). I'm not sure this will lead to the desired behavior, rotating enemies, player, backgrounds around a single point...?

I suggest you test some with a game you're developing to understand what we really want here. Right now I don't have the time to dive deep into this. I would suggest starting by implementing this.angle in Viewport just as Sprite does it.. (as suggested above). It might be what you want but I'm not sure.

justgage commented 10 years ago

I'll have to look into it when I have time.