melanke / CascadeCanvas

A framework for canvas that follows the Javascript patterns you already know
6 stars 0 forks source link

Chunks. The whole stage will be divided by a matrix of chunks and will make area searches faster. #42

Closed melanke closed 9 years ago

melanke commented 10 years ago

But they will be optional

To use chunks we need to create them

CC.buildChunks();

CC will use chunks when available, and has to check if there is chunks

CC.hasChunks();

If we don't need to use chunks anymore, we can destroy them all, but the elements will stay in stage

CC.destroyChunks();

We can get the element list inside the chunks of an area

CC.getChunks({x: 10, y: 10, w: 300, h: 300}); //w and h are optional

If the element change it's position, is a good idea to fix it's chunk, it will remove the element from the wrong chunk and put in the right chunk

el.fixChunk();
melanke commented 10 years ago

Actually I think it could be more subtle:

Chunks are always enabled, depends on user to put elements in it:

//lazy will make the element to be put on a chunk
CC.new("Class1 #ElId", { x: 12, y: 13, lazy: true });

and elements that are not sedentary will be placed on a special chunk that is checked everytime

so if you use

CC.areaSearch({ x: 0, y: 10, w: 30, h: 30 });

we search elements inside the right chunk and inside special chunk

CC.clear();

will clear chunks as well