GMS 2.3+ Buffers and surface layers

mikix

Member
I have surface layers in my painting app. If I use buffer_grow, it only loads the last layer that was drawn on. And if I use buffer_seek_start it loads the first layer that was drawn on. But I want to load every single layer that has been drawn on.

Here's the code. What do I do?

GML:
var pos = buffer_seek(buffersurf, buffer_grow, 0);
buffer_load_ext(buffersurf,fileload,pos)

if surface_exists(global.final_surf)
{
buffer_set_surface(buffersurf,global.final_surf,0)
}
 

GMWolf

aka fel666
Your code only calls buffer_set_surface once, and on one surface. So it's only going to load that one surface.

What you need is some sort of loop to call buffer_set_surface on all your surfaces with the right offset.
 

GMWolf

aka fel666
That would mean you are continually reading the same portion of the buffer.
For each surface, you need to calculate where in the buffer to read from.

A surface will use width × height × 4 bytes of memory.
 

mikix

Member
Like this?

buffersurf1 = buffer_create(room_width * room_height, buffer_grow, 1);
buffersurf2 = buffer_create(room_width * room_height, buffer_grow, 1);
buffersurf3 = buffer_create(room_width * room_height, buffer_grow, 1);
 

GMWolf

aka fel666
Do you know about arrays?
Also, how familiar are you with buffers?
You could have a single buffer large enough for all surfaces, and use the right offset in buffer_set_surfave.


Like this?

buffersurf1 = buffer_create(room_width * room_height, buffer_grow, 1);
buffersurf2 = buffer_create(room_width * room_height, buffer_grow, 1);
buffersurf3 = buffer_create(room_width * room_height, buffer_grow, 1);
Have you tried this?
What happens?

Best advice I can give you is: write stuff. See what happens.
 
Top