How do I load sprites in realtime from array?

0 favourites
  • 9 posts
From the Asset Store
Supports 1D, 2D, 3D arrays. Import and export arrays in JSON format
  • Hi all. I'm hoping someone can lend me a hand. I'm placing sprites on my layout using data from an array using the miner method. All is fine and dandy, except for the amount objects loaded to memory once the screen is drawn. Right now, I load each "page" from the array in approximately 30x16 sprites at a time to avoid the CPU load issues, which works for now... However I would like to use the Scroll To behavior and load the tiles on the fly, as the player moves around the screen.

    Here's my work in progress to get an idea. Use the arrow keys to move around and mine through the terrain.

    http://www.imgfeed.co/c2proj/PocGen32x32/index.html

    Here is the scrolling method I'm using now:

    [attachment=1:2dpesfrz][/attachment:2dpesfrz]

    Here is how I populate the sprites using an array and draw only the area necessary. ( see the "between values")

    [attachment=0:2dpesfrz][/attachment:2dpesfrz]

    I'm in the process of trying lerp/scrollxy, however I would have to load 8 times the number of tiles to make the scene ready to scroll to...

  • Looks like a neat demo! So if I understand you correctly, you're trying to load sprites for only the current screen that you're on to cut down on cpu usage?

  • Exactly! And it does that as it right now, but scrolling around instead of flipping through pages would be so much better. Especially if you're exploring caves!

  • You should look at the Tilemap object!

  • Blackhornet,

    I checked the tilemap object at it really doesn't fit well with a procedural game.

  • Duplicate Post...

  • It actually fit perfectly. A single instance, with very few draw calls. Much better than multiple sprites !

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I tried out the tilemap object and guess what? The CPU usage went down considerably, beyond my expectation. This has caused a few more challenges that I can't seem to get past. While using sprites, the player would collide and destroy the blocks. With tilemaps, there doesn't seem to be a straight forward way to check for collisions at an offset. Any care to shed some light?

  • If you consider all tiles as obstacle, it's pretty much straightforward; you have to test tile IDs under the object you want to test collision for, when an ID <> -1, it's a collision with that tile. The only drawback with this is that you are limited to bounding boxes for collision testing... it's usually not an issue in those kind of games though.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)