I write the game in the style of supermario (2d, man runs left-up, avoiding obstacles). All obstacles are stored in the json file.

The question is: is it possible to immediately build all the obstacles on the canvas when you open the level and then move it or will they all not fit into the memory / be buggy and therefore they need to be loaded gradually?

ps levels by the size of 'normal', roughly speaking ~ 20 screens of the phone (wide part)

  • 3
    I think it will be right to load the "map of obstacles and pictures to them" into the array. and then, as necessary, draw pieces on the screen. - KoVadim
  • Well, on the canvas all at once just do not load. load better into some spatial tree and load as needed - PaulD

2 answers 2

Canvas is a very powerful thing. I doubt very much that you will have even a few thousand objects in json there, which is a spit for a canvas. So it makes no sense to “paint on” just for the sake of saving power - there is no, do as it is more convenient.

We have on the graphs ( http://iguanacharts.com/ ) in the canvas without problems sticks out 1/2 thousand objects and all this is redrawn for every sneeze. An order of magnitude or even two orders of magnitude more resources eats up receiving and parsing data from the server.

So I would recommend getting all the objects at once, but redrawing the entire visible world on the fly.

    Perhaps the best solution would be to load objects dynamically when the nearest edge of the screen (to the object) approaches this object at a distance that the character can run at his maximum speed in 0.5-1 second. Similarly, unload (if you can not return, you can unload forever).