Jump to content

how do i get phaser / p2 to calculate only what's visible in the current camera view


valueerror
 Share

Recommended Posts

as i said in the title of this thread i think it could be useful for performance to stop p2 calculating every air and ground enemy even if it's 2000 pixels away from me..

 

in my game (and i think this is true for most jumpNrun platformer games) it would be absolutely ok if the enemies start walking a second before i see them in my current cameraview ..

 

lets say i have 10 enemies and 10 moving platforms on my map..  every step (60 times a second) phaser is calculating all of the objects on the map.. that means 1200 times per second every collision calculation presolve/narrophase whatsoever.. this must be bad for performance ? or are those calculations that simple that this doesn't count?

 

i thought it would be great to tell p2 to only calculate a specific rectangle around my player -- let's say 1000x800 pixels .. every enemy stays on it's place until this rectangle touches it..

 

is this already possible in phaser somehow??

Link to comment
Share on other sites

yeah..that's what i'm asking for.. but is there a phaser way to do that? if not.. how do i do that?

i cant just disable collisions because then the other objects would fall of the screen.. i would ned something general like game.pause for everything outside of a defined rectangle around the player....

Link to comment
Share on other sites

hmmm...  i made a few tests..   i think i was wrong in one point..   the assumption that those p2 calculations of all my moving objects are the reason for the great performance drop on a less powerfull pc seems to be wrong..  p2 (or phaser) can handle quite a bunch of sprites moving around on their own, colliding with each other..  (at least enough for a simple platformer game)

 

i commented out everything in my game world that could waste cpu power (enemies, moving objects, backgrounds (parallax)...  but still - the moment i start moving my player and the camera starts scrolling i've got 30 - 40 frames instead of 60

 

so i thought about whats left..  my tilemap is the only thing left with a bunch of layers..  so i commented out 6 of the 7 layers and performance is top !    i made a special very big tilemap with as much independent tiles as i could get on the screen with only one layer and l... performance drops only 2 or 4 frames.. everything is still perfect..

 

so the outcome of my "research" is :

for json files created in tiled -  the number of layers is responsible for the scrolling performance  2 layers good! 6 layers bad!

 

 

since the original question of this thread seems interesting besides this new encountered problem i'm going to create a separate thread for the "layer problem" 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...