NEW 6 years ago
If the image object is deleted then the associated ram buffer is deleted, too.
Deletion of that happens e.g. if they are scoped locally or with the delete
keyword, in case of pointers
void someFunc() { Image img(/* blah *); // do stuff // image gets deleted as it is end of the function }
Image* img_ptr;void init() { img_ptr = new Image(/* stuff */); } // later on in your code delete img_ptr;
Please note that that can easily cause ram fragmentation
NEW 6 years ago
What does this mean for you? PROGMEM is obsolete, the keyword does nothing. By defining something as const it will land already in flash and you can just access it normally, no need to pgm_read_byte or thelike.
Is this why there is only one memory percentage showed when we compile a Gamebuino Meta game, instead of two different percentages in Arduboy? When I made an ebook on Arduboy, I had to use F() to memorise my text with enough space. So, are PROGMEM and F() useless with the Meta?
NEW 6 years ago
Is this why there is only one memory percentage showed when we compile a Gamebuino Meta game, instead of two different percentages in Arduboy?
I'm not sure, as the META still has both flash and ram. They are just in the same addressable space.
So, are PROGMEM and F() useless with the Meta?
Yeah. If a variable is in global namespace you just define it as const
and if it is in local namespace (e.g. inside functions) as static const
and then it'll land in flash
NEW 6 years ago
Ok, but if I want to display a lot of text, I used F() on Arduboy with a print function. How can I do with the Meta? My text is not in a variable.
NEW 6 years ago
It's even easier with the Meta, take a look at this : https://github.com/deeph-z80/META-Picomon/blob/master/sources/picomon/strings.h
All you have to do is call gb.display.print();
most of the time.
And you can even easily make a typing routine like this : https://github.com/deeph-z80/META-Picomon/blob/master/sources/picomon/picomon.ino#L445 ☺
NEW 5 years ago
More importantly, how do you create an image, without the tool?
NEW 5 years ago
You could create, for a flash image, the hex data manually, as described, use a BMP image, or just use a tool to convert it to the hex data. What's wrong with tools to help you create assets?
NEW 5 years ago
What's wrong with the tool is that it doesn't seem to work with fixed colours. So if i get it in your example code for a fixed colours image,
means 1 pixel of colour #0, and one pixel of colour #7 ? I guess I was too tired yesterday, didn't get it, sorry.0x07
NEW 5 years ago
That is correct. As also mentioned, the tool has a bug with indexed images if they have an odd number of pixels as their width, so make sure your images have even numbers!
NEW 5 years ago
Hi,
I'm struggling with the animation of my character.
I'm trying to make him walk to the right. It's not working as I want...
Here are the 2 pictures I'm using :
"marche_avant" for the animation and "debout" when doing nothing.
2 cases with issue for each one (see the code above) :
A. If I use the following data for "marche_avant" >
const uint16_t marche_avantData[] = {10,14,2,1,0xfc3b,0,
* When I load the program, it's displaying "debout", good.
* When I press one time the right arrow, it's displaing "debout" 2 pixels to the right, NOT GOOD.
* When I press again the arrow, it's playing once the animation then stays on displaying "debout", good.
* Each time I press again it's doing this alernately.
* When I press continuously the arrow, it's diplaying alternately "debout" then "marche_avant", NOT GOOD.
B. If I use the following data for "marche_avant" >
const uint16_t marche_avantData[] = {10,14,2,0,0xfc3b,0,
* When I load the program, it's displaying "debout", fine.
* EACH TIME I press the arrow, it's playing the animation "marche_avant" then stays on displaying "debout", very good.
* When I press continuously the arrow, it's only moving the 1st picture of the animation every 2 pixels to the right, NOT GOOD.
How can I make it work fine ?
Here is my code :
#include <Gamebuino-Meta.h>
// Caractéristiques du perso
int perso_X = 22;
int perso_Y = 47;
const uint16_t marche_avantData[] = {
10,14,2,1,0xfc3b,0,
0xfc3b,0xfc3b,0x3211,0x3211, ETC...
};
Image marche_avant = Image(marche_avantData);
const uint16_t deboutData[] = {
8,14,1,0,0xfc3b,0,
0xfc3b,0x3211,0x3211,0x3211, ETC...
};
Image debout = Image(deboutData);
void setup() {
gb.begin();
gb.setFrameRate(5); // otherwise this is too fast for my game
}
void loop() {
while(!gb.update());
gb.display.clear();
if (gb.buttons.repeat(BUTTON_RIGHT,0)) {
gb.display.drawImage(perso_X, perso_Y, marche_avant);
perso_X += 2;
} else {
gb.display.drawImage(perso_X, perso_Y, debout);
}
}
NEW 5 years ago
* Everything inside "void loop() { while(!gb.update()); gb.display.clear();}" is red from top to bottom 25 times each second if no other framerate is set ?
* Also, if I chose to animate a sprite from a vertical sprite sheet image, is it loading an image each loop ? If my animation is 25 images vertically, will it take 25 loops to do it entirely if I set the speed to 1 in "const uint16_t MYANIMATIONData[] = {" ?
* If so, if I use instaed 25 separate pictures that I display within a loop, what will be the frequency of the animation display ?
* This is confusing for me.
> but first I want to fix my issue above :)
NEW 5 years ago
* Everything inside "void loop() { while(!gb.update()); gb.display.clear();}" is red from top to bottom 25 times each second if no other framerate is set ?
------------------------------------
=> yes but in your program, you have set it at 5
Else if you want 25 frames / s and want do something slower, you can use a counter. In setup you set it to 0. In the loop you incease it after the while(!gb.update()); and when it's reach the value that you want for example 5 to do it 5 times slowest, you make that you have to do and set the counter back to 0
-----------------------------------
* Also, if I chose to animate a sprite from a vertical sprite sheet image, is it loading an image each loop ?
----------------------------------
=> Yes if you dont change speed
------------------------------------
* If my animation is 25 images vertically, will it take 25 loops to do it entirely if I set the speed to 1 in "const uint16_t MYANIMATIONData[] = {" ?
--------------------------------
=> Yes if you dont change speed it's will be as that
__
NEW 5 years ago
Pour ton prog, essayes plutôt: if (gb.buttons.pressed(BUTTON__RIGHT)) à la place et dit moi si ça marche mieux
NEW 5 years ago
Merci,
J'avais vu cette possibilité gb.buttons.pressed.
Concrètement cela ne pose plus de problème quand je mets const uint16_t marche_avantData[] = {10,14,2,0,0xfc3b,0, (comme avec gb.buttons.repeat quand j'appuie à chaque fois sur la croix pour faire un pas).
Mais j'aurais aimé pouvoir laisser la croix appuyée pour faire avancer mon personnage.
Dans les données renseignées 10,14,2,0,0xfc3b,0 :
* le 2 correspond au nombre d'images faisant 10x14 pixels, n'est-ce pas ? Mais j'ai remarqué que même en mettant 1 ou 0 cela ne changeait rien (j'ai même testé en mettant 5). En fait comme mon image fait 10x28 il divise automatiquement en 2* 10x14, donc à quoi sert ce chiffre à renseigner ?
* le zéro après le 2 sert pour la vitesse n'est-ce pas ? Avec gb.buttons.pressed, si je mets 0, j'ai mon animation qui se passe bien à chaque appui sur la croix. Si je mets par exemple 10, j'ai 10 animations pour les 10 premier appuis et ensuite si déplacements de 2 pixels de mon image "debout" pour les 10 appuis suivants, et ça recommence ensuite.