hi amateus and the rest,
I'm trying to improve your foregrounds example to another one more complex.
Specifically, I'm trying to build a screen with several foreground-tiles (instances) repeated. I mean same graphic in several positions.
And I try to remove them (reset the screen) after. But I have doubts about the best way to do it.
Some changes from the amateus code in github:
main:
Code: Select all
create_foreground(); // create scene
clear_foreground(); // delete scene
create_foreground(); // create scene
clear_foreground(); // delete scene
while(1) { // We should watch a black screen with the bubble
get_movement();
sp1_MoveSprPix(bubble.s, &full_screen, 0, bubble.x, bubble.y);
intrinsic_halt();
sp1_UpdateNow();
}
create foreground:
Code: Select all
void create_foreground() {
//I want to create a screen with the same foreground-tile repeated in several positions
sp1_InitCharStruct(&window_object, SP1_DRAW_MASK2NR, SP1_TYPE_2BYTE, &window, 5);
bricks_update = sp1_GetUpdateStruct(11, 10);
sp1_InsertCharStruct(bricks_update, &window_object);
sp1_InitCharStruct(&window_object, SP1_DRAW_MASK2NR, SP1_TYPE_2BYTE, &window, 5);
bricks_update = sp1_GetUpdateStruct(12, 10);
sp1_InsertCharStruct(bricks_update, &window_object);
sp1_InitCharStruct(&window_object2, SP1_DRAW_MASK2NR, SP1_TYPE_2BYTE, &window, 5);
bricks_update = sp1_GetUpdateStruct(11, 13);
sp1_InsertCharStruct(bricks_update, &window_object2);
sp1_InitCharStruct(&window_object2, SP1_DRAW_MASK2NR, SP1_TYPE_2BYTE, &window, 5);
bricks_update = sp1_GetUpdateStruct(12, 13);
sp1_InsertCharStruct(bricks_update, &window_object2);
sp1_Invalidate(&full_screen);
sp1_UpdateNow();
}
clear foreground:
Code: Select all
void clear_foreground() {
//After, I want to figure out how I can reset the screen as easily as possible
//... otherwise sp1 reset the machine
/*
// 1.- KO: This is the established call to do it, but when you have several repetitions it only removes the last one
sp1_RemoveCharStruct(&window_object);
sp1_RemoveCharStruct(&window_object2);
*/
/*
// 2.- KO: I try to repeat the call to figure out if the first instance can be deleted, but not
sp1_RemoveCharStruct(&window_object); sp1_RemoveCharStruct(&window_object);
sp1_RemoveCharStruct(&window_object2); sp1_RemoveCharStruct(&window_object2);
*/
/*
// 3.- OK: Using the API, I reset every used position of the screen => But, I need to note all positions
bricks_update = sp1_GetUpdateStruct(11, 10); sp1_RemoveUpdateStruct(bricks_update); sp1_RestoreUpdateStruct(bricks_update);
bricks_update = sp1_GetUpdateStruct(12, 10); sp1_RemoveUpdateStruct(bricks_update); sp1_RestoreUpdateStruct(bricks_update);
bricks_update = sp1_GetUpdateStruct(11, 13); sp1_RemoveUpdateStruct(bricks_update); sp1_RestoreUpdateStruct(bricks_update);
bricks_update = sp1_GetUpdateStruct(12, 13); sp1_RemoveUpdateStruct(bricks_update); sp1_RestoreUpdateStruct(bricks_update);
*/
/*
// 4.- KO: Trying to simplify case 2, I make a loop to reset all the screen positions
for(uint8_t y=0; y<22; y++) {
for(uint8_t x=0; x<32; x++) {
bricks_update= sp1_GetUpdateStruct(y, x);
sp1_RemoveUpdateStruct(bricks_update);
sp1_RestoreUpdateStruct(bricks_update);
}
}
*/
sp1_Invalidate(&full_screen);
sp1_UpdateNow();
}
In the below link you can find the complete source code of my exercise:
https://ufile.io/0hncx0oi
I'll appreciate any help or idea. Thanks in advance,