Laumark Posted May 11, 2016 Share Posted May 11, 2016 I'm making a game with Asteroid like controls, but I'm in doubt about how to move the sprite in the direction it is facing. What's the easiest way to do this? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted May 11, 2016 Share Posted May 11, 2016 Sorry for the short answer but have a look at using vectors and vector-based maths rather than cartesians points to move your sprites around, it greatly simplifies this type of movement. Many physics libraries can help you out. Quote Link to comment Share on other sites More sharing options...
Laumark Posted May 11, 2016 Author Share Posted May 11, 2016 Cool, thanks. I will. Pixi doesn't have anything like that? Quote Link to comment Share on other sites More sharing options...
mattstyles Posted May 11, 2016 Share Posted May 11, 2016 Nope, pixi just draws stuff really really fast! Actually it does interactive stuff too but thats by-and-by. I can vouch for P2 and also matterJS, both allow any rendering front-end to be bolted on (not all physics libraries do, some like to be tied to the rendering, which, in my opinion is plain wrong, do one thing well), in my experience P2 was easier to integrate, its a very powerful package. Both libraries have a pixi example in their source repos. You should be able to find examples of bolting either physics lib and pixi together, or if you know phaser then phaser packages P2 if you dont mind using slightly older versions. If you want to roll your own though, a simplified physics library just to help you move stuff around, its not too difficult (if you know your maths a bit) and a good exercise. The physics only gets hard when you want a fairly realistic simulation, stuff like collisions and everything can get hairy, just moving around isn't too difficult. Quote Link to comment Share on other sites More sharing options...
Sebi Posted May 12, 2016 Share Posted May 12, 2016 You don't need a physics library for that. Simple trigonometry is enough. function move(object, distance) { object.x = object.x + distance * Math.cos(object.rotation); object.y = object.y + distance * Math.sin(object.rotation); } https://jsfiddle.net/11av8s0m/ coelacanth 1 Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted May 12, 2016 Share Posted May 12, 2016 Better use Ticker and mutiply that thing on delta time. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.