premier jeu, Last Defenders (nom provisoire) : aides en tout genre

General

Steph

NEW 4 years ago

JFT JFT

I just reread the discussion... and I realize that I had already given you the solution on the right way to proceed, with setFrame() function...

All this is explained in the tutorial, which I encourage you to read... or to reread it again!

Steph

NEW 4 years ago

JFT JFT

I just wanted to say that, from now on, you could use the new Image Transcoder, which a priori is not buggy like the gouz tool was.

Image Transcoder allows you to encode spritesheets or tilesets for all META display modes... including high resolution for use with gb.tft.

JFT

NEW 4 years ago

Reinventing the Wheel, that's what I thought too. I'll reread what you gave me and try to apply it. But is there a way to put an image name as an argument in a function ?

Steph

4 years ago

I don't quite understand the question... your image is not a file... it's an array of 16-bits integers uint16_t stored in Flash memory and referenced by an IMAGE_DATA variable (for example). So you can quite easily pass your variable as an argument of a function. I don't see where your difficulty is?

Steph

NEW 4 years ago

JFT JFT

I don't quite understand the question... your image is not a file... it's an array of 16-bits integers uint16_t stored in Flash memory and referenced by an IMAGE_DATA variable (for example). So you can quite easily pass your variable as an argument of a function. I don't see where your difficulty is?

JFT

NEW 4 years ago

.

JFT

NEW 4 years ago

My game is working fine with the code I created, it's just that I wanted to do another way.
So I tried to create a function but it returned errors, I'll show you later if needed.

example :

void myfunction (ANIM, short start_X, short start_Y, short number_of frames, /+other stuff/) {
//code
gb.display.drawImage(X,Y, ANIM[number
of _frames]);
//code
}

// main code

Image enemy_anim[4]={aen1, aen2, aen3, aen4};
//code
myfunction (enemy_anim, 60, 25, 4);

JFT

NEW 4 years ago

And why the following is not working ?

short x = 4;
Image enemy_anim[x]={aen1, aen2, aen3, aen4};

> I got an error when transfering to the Gamebuino

Steph

4 years ago

This is valid with c99... but not with c++11 (which is the standard used by Arduino IDE). You must specifiy a static size, or simply write:

Image enemy_anim[]={aen1, aen2, aen3, aen4};

And... to answer your previous question... provided that your ANIM image is a stack of each frame:

gb.display.drawImage(X,Y, ANIM[numberof _frames]); // NO !

ANIM.setFrame(frame_number);     // YES !
gb.display.drawImage(X,Y, ANIM);

I don't understand the point of separating your images...

Steph

NEW 4 years ago

JFT JFT

This is valid with c99... but not with c++11 (which is the standard used by Arduino IDE). You must specifiy a static size, or simply write:

Image enemy_anim[]={aen1, aen2, aen3, aen4};

And... to answer your previous question... provided that your ANIM image is a stack of each frame:

gb.display.drawImage(X,Y, ANIM[numberof _frames]); // NO !

ANIM.setFrame(frame_number);     // YES !
gb.display.drawImage(X,Y, ANIM);

I don't understand the point of separating your images...

JFT

NEW 4 years ago

When doing following, I've got this error message :
"variable or field 'animation' declared void"

void myfunction (/which data type?/ ANIM, short X, short Y, short frame_number, /+other stuff/)  {
//code
ANIM.setFrame(frame_number);
gb.display.drawImage(X,Y, ANIM);
//code
}

Steph

4 years ago

void myfunction(uint16_t* ANIM, ...) { ... }

Steph

NEW 4 years ago

JFT JFT

void myfunction(uint16_t* ANIM, ...) { ... }

JFT

NEW 4 years ago

I already tried this but then I had an issue when calling my function, I'll send the error.

Steph

4 years ago

If you sent me a link on GitHub or Gist to check what's wrong... it would be easier...

Steph

NEW 4 years ago

JFT JFT

If you sent me a link on GitHub or Gist to check what's wrong... it would be easier...

JFT

NEW 4 years ago

Ok I fixed the problem :

//image
const uint16_t myimageData[] = {8,6,1,1,0xfc3b,0,
0xfc3b,0x180,0xfc3b, /etc/};
Image myimage = Image(myimageData);

//function
void myfunction(uint16_t* image, ...) { ... }

//calling the function
//I was doing this (not working) :
myfunction(myimage, ...);

//instead of doing this (working) :
myfunction(myimageData, ...);

JFT

NEW 4 years ago

So what is the point to add this line "Image myimage = Image(myimageData);" when creating an image ?
Is it regarding the memory usage ?

> I start to understand better as I do different tests, so I go on and will come back later if really needed :)

Steph

4 years ago

myimageData is an array that simply describes the data to be displayed.

myImage is an instance of the Image class, which will use the myImageData array to build an object that can be displayed on the screen.

An array is not a displayable object!

You can take a look at this Gist to understand how to implement sprite animation from a spritesheet that embeds all the images of the animation.

This is what you will get by compiling the code:

Here is the spritesheet I used (magnified 8 times) based on the official Gamebuino META palette:

And I used the indexed display mode for this demo (see config-gamebuino.h).

You can see that the animation is done by controlling the display of the right frame from the spritesheet, with the setFrame() function.

I used ImageTranscoder tool to build the data array automatically.

I hope it's clear enough this time....

Steph

4 years ago

Sorry... the online editor is buggy!
I couldn't update my message with the spritesheet image....
So here it is:

EDIT: Well, that's it!..... I did it! I had to do it all over again, 10 times!.....

Steph

NEW 4 years ago

JFT JFT

myimageData is an array that simply describes the data to be displayed.

myImage is an instance of the Image class, which will use the myImageData array to build an object that can be displayed on the screen.

An array is not a displayable object!

You can take a look at this Gist to understand how to implement sprite animation from a spritesheet that embeds all the images of the animation.

This is what you will get by compiling the code:

Here is the spritesheet I used (magnified 8 times) based on the official Gamebuino META palette:

And I used the indexed display mode for this demo (see config-gamebuino.h).

You can see that the animation is done by controlling the display of the right frame from the spritesheet, with the setFrame() function.

I used ImageTranscoder tool to build the data array automatically.

I hope it's clear enough this time....