ForgeableSum

3,000 Animated Sprites w/pathfinding in Phaser

Recommended Posts

Amazing! What GPU are you using?

The game will be available on github?

What database solution you will be using?

I want to play it now :D ! Looks like AoE!

For the video, I was using a modest macbook air - 1.4 GHZ and an integrated Intel HD Graphics 5000 1024 MB GPU - definitely not a gaming PC. Gaming PCs will be able to perform much better of course but I wanted to make my game accessible for even casual gamers.

 

You'll be able to play the map editor within the month as I plan on releasing a public demo. The code isn't on git hub though - it's closed-source for now.  

Share this post


Link to post
Share on other sites

I'm impressed by the amount of moving units, have you had to make many optimizations, or is the good performance due to a simplified approach? as far as I can tell, you have avoided collisions, but do avoid other static forces. I assume that pathfinding does not get calculated in every frame, to ensure the path is still the best/valid?

 

I'm using webgl in my project too and I'm very happy with it's performance. but on a macbook it does not run as nicely as I would like, although I have far fewer moving objects. shaders and webaudio seem to be the main culprits, but the game logic also does its part. I'm still looking for ways to improve performane, maybe you have a trick or two up your sleeve ;) ?

Share this post


Link to post
Share on other sites

I'm impressed by the amount of moving units, have you had to make many optimizations, or is the good performance due to a simplified approach? as far as I can tell, you have avoided collisions, but do avoid other static forces. I assume that pathfinding does not get calculated in every frame, to ensure the path is still the best/valid?

 

I'm using webgl in my project too and I'm very happy with it's performance. but on a macbook it does not run as nicely as I would like, although I have far fewer moving objects. shaders and webaudio seem to be the main culprits, but the game logic also does its part. I'm still looking for ways to improve performane, maybe you have a trick or two up your sleeve ;) ?

Performance with webgl vs canvas varies so greatly that I've decided to make both modes options in my game. Fact is, a lot of older gpus aren't cutout for webgl. On older macs (like 2010 and earlier), you'd best stick with canvas 2d. The newer macs with the new integrated radeon gpus are good with webgl though.

 

But in regards to pathfinding, I'm using a lot of tricks, including:

  1. Ray casting between the object and destination. if nothing intersects the ray, there is no need to find a path and a simple straight line to the destination is used.
  2. When a new destination is set (with the pointer), all selected units search for a path in a relative grid created on-the-fly that is only as big as it needs to be. it's approximately the size of the distance between the sprite and destination squared. each unit uses these small, relative grids to search for a path because it's a lot smaller than a grid proportionate to the full world size. if i used a grid proportionate to the full world size, forget it - I'd be limited to tiny maps and even then, pathfinding would use up 10x more memory/cpu. 
  3. I set a delay so when a group of units looks for a path, they don't all look for a path at once. the first one will look for a path in 50 milli, then after 50 milli, the next, etc. this actually gives the appearance of a more natural movement in some scenarios because they don't all end up on the same path at the same time. it has the added benefit of better performance because memory can be re-allocated each time a new path is found. 
  4. Units don't look for a path around objects that are moving. it wouldn't make sense to waste processing power on this because if the object is moving, there's no telling where it will be when the unit comes near it. 

 

Anyway, that's the basics. Eventually, I plan on writing a more in-depth and detailed explanation of how my pathfinding system works on my dev blog

Share this post


Link to post
Share on other sites

Incredible!

 

Is it a phaser game engine capability to render so many sprites or it was done only due to the "pathfinding tricks" which you used?

 

I have made the RTS scetch on Construct 2 and node-webkit:

win64
win32
mac64 
mac32 

 

I have "bumped into" the quantity of game objects. If I have 8 formations of 480 units the FPS is normal but wnen I increase the number of formations to 20 (1200 units)  the perfomance is very low. May be Phaser can re-energise my RTS sketch?

Share this post


Link to post
Share on other sites

It's definitely Phaser and Pixi doing most of the heavy-lifting. You just have to code wisely within the framework. Experiment with auto-cull. Don't use physics unless you really need to (instead, use pathfinding). Minimize the number of updates - do your game objects need to be updated every game loop (60 times per second) or once every 100 milliseconds or so? All of the tools are there, within the framework. You just need to learn how to use them :).

BTW, this video is ancient. Here's an updated video:

 

You can also play the demo at feudalwars.net.  

 

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

  • Recently Browsing   0 members

    No registered users viewing this page.