New creation : Handling images on the Gamebuino META - by Steph

Ha ha ha… Tu peux déjà commencer à t’en imprégner. Lis quelques paragraphes tous les soirs… Tu peux dès à présent instiller les prémisses de la connaissance dans ton système cognitif. Tu sais, c’est comme quand on nous faisait écouter de l’anglais à l’école primaire :joy:

You must be impatient! It won’t be long now.

Have you tested the latest version of Andy’s emulator? Although this is a prototype, it seems to me that this is the most accomplished version, which supports sound and full 160x128 resolution with 65k colors.

2 Likes

Thanks for recommending it. That’s the one I have been using and it is indeed great!

Gamebuino has arrived, though! :grin:

1 Like

Incredible tutorial Steph.
Thank you very much for taking the time to do it, it’s really clear, you don’t forget anything, it’s great.

Btw you mention using tiled for tile maps, how do you import maps into your gamebuino game?

3 Likes

Thank you so much for your feedback @Darenn. I’m very happy that you liked the tuto, and it’s important for me to get feedback from my readers.

Tiled uses the TMX format, which is based on XML, to encode tilemaps. This format is very verbose and is not ideal to be inserted in your C++ code. You will have to convert it to another format, lighter, and more suitable for Gamebuino programming.

Rather than working directly on the XML format, Tiled offers other file formats for export.

Among the available formats, there is the JSON format, which is lighter, and can be easily processed by many programming languages, which usually have a JSON format parser.

This is the case, for example, of PHP or Python, and of course of JavaScript (since JSON is the native format for serialization of JavaScript objects).

The next step is to choose one of these programming languages to transcode the JSON structure of your tilemaps into a collection of byte arrays that are directly usable by your C++ code for the Gamebuino.

This could be the subject of a new tutorial… :wink:

3 Likes

Thanks for helping me @Steph !
I’ll explore your solution.

Yes, it’s a good subjet for a game with levels:
Create levels on Tiled, convert level done, import level in your game and manage a collection of levels…
It’s in fact one of the never done important subject never done on a tuto at this moment.

2 Likes

Salut,
J’ai enfin pu lire ton atelier @Steph… et c’était un plaisir à lire :slight_smile: L’atelier est très complet !

J’ai vu au cours de l’atelier que tu fais une multiplication par 0.5 au lieu d’une division par 2. C’est pour une raison d’optimisation ? De mémoire (mes cours de micro contrôleur remontent un peu) mais en terme d’opération la multiplication est plus rapide.

Amicalement,

1 Like

Peut-être que le code utilise la division euclidienne (en entier avec un reste). D’où la différence entre / et %.

1 Like

Bien vu Chris,
Ce doit être ce code :

void loop() {
    gb.waitForUpdate();
    gb.display.clear();
    gb.display.drawImage(
        .5*(SCREEN_WIDTH  - AVATAR_WIDTH),  // x
        .5*(SCREEN_HEIGHT - AVATAR_HEIGHT), // y
        avatar                              // image
    );
}

En effet, multiplier par 0.5 force implicitement le calcul en nombre flottant.
Une division par 2 serait plus efficace, et donnerait exactement le même résultat.
Attention à ne pas être tenté de multiplier par 1/2 :wink:

Petit exemple :

#include <Gamebuino-Meta.h> 

const uint8_t SCREEN_WIDTH = 80;
const uint8_t AVATAR_WIDTH = 40;

void setup() {
  // put your setup code here, to run once:
  gb.begin(); 
  
}

void loop() {
  gb.display.clear();
  uint8_t u8_X;
  u8_X = 0.5*(SCREEN_WIDTH-AVATAR_WIDTH);    // OK: SCREEN_WIDTH = 80, AVATAR_WIDTH = 40, u8_X = 20
  gb.display.println(u8_X);  
  u8_X = (SCREEN_WIDTH-AVATAR_WIDTH)/2;      // OK: SCREEN_WIDTH = 80, AVATAR_WIDTH = 40, u8_X = 20
  gb.display.println(u8_X);  
  u8_X = 1/2*(SCREEN_WIDTH-AVATAR_WIDTH);    // KO: SCREEN_WIDTH = 80, AVATAR_WIDTH = 40, u8_X = 0
  gb.display.println(u8_X);  
  while ( !gb.update() );
}


3 Likes

Comme mentionné par beaucoup de personnes, excellent tuto qui devrait faire parti de la doc officielle! Beaucoup plus explicite que la doc API pour comprendre le fonctionnement interne des fonctions de la librairie graphique gamebuino. Bravo pour ce travail pédagogique!

3 Likes

Merci beaucoup pour ton retour @lezardo :slightly_smiling_face:

1 Like