How do I load sprites in realtime from array?

Get help using Construct 2

Post » Mon Jan 05, 2015 11:44 pm

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:
scrollingmethod.PNG


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


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...
You do not have the required permissions to view the files attached to this post.
B
13
S
2
Posts: 33
Reputation: 771

Post » Mon Jan 05, 2015 11:55 pm

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?
B
74
S
19
G
9
Posts: 377
Reputation: 9,258

Post » Tue Jan 06, 2015 12:05 am

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!
B
13
S
2
Posts: 33
Reputation: 771

Post » Tue Jan 06, 2015 12:32 am

You should look at the Tilemap object!
ImageImageImage
B
71
S
22
G
249
Posts: 3,763
Reputation: 138,577

Post » Tue Jan 06, 2015 6:15 pm

Blackhornet,

I checked the tilemap object at it really doesn't fit well with a procedural game.
B
13
S
2
Posts: 33
Reputation: 771

Post » Tue Jan 06, 2015 6:16 pm

Duplicate Post...
Last edited by endless409 on Tue Jan 06, 2015 9:57 pm, edited 1 time in total.
B
13
S
2
Posts: 33
Reputation: 771

Post » Tue Jan 06, 2015 7:19 pm

It actually fit perfectly. A single instance, with very few draw calls. Much better than multiple sprites !
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735

Post » Tue Jan 06, 2015 10:01 pm

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?
B
13
S
2
Posts: 33
Reputation: 771

Post » Tue Jan 06, 2015 10:18 pm

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.
B
75
S
31
G
27
Posts: 1,000
Reputation: 20,735


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 19 guests