You are not logged in.

#1 2011-03-21 21:53:19

triki
Member

Animation

http://img827.imageshack.us/img827/3393/screenhunter01mar060206.gif

Bonjour,
Je d�but en programmation et travail sur l'affichage d'animation en .png
Je cr�e mon .png avec mes animations sous imagemagick, lorsque je veux les afficher avec grrlib j'ai un souci, celles-ci ne se suivent pas toujours.

Hello,
I 'm a beginer in programation and work on the display of animation .png
I create my .png with my animations under imagemagick, when I want to show them with grrlib I have a some time a bad result

pouvez-vous m'aider?
can you help me?

horizontal and vertical anim like it Good result wink
http://img135.imageshack.us/img135/6162/95370858.png

Bad result how I can do it to work left to right ligne by ligne????
http://img148.imageshack.us/img148/151/danceq.png


I've an other question how I can do to have my musique again and again?
Comment puis-je faire pour avoir ma musique en boucle?

thank you and excuse for my bad English

Last edited by triki (2011-03-22 16:15:32)

Offline

 

#2 2011-03-22 02:51:16

Crayon
Bad Mother Fucker

Re: Animation

Normalement pour faire une animation tu dois te servir de la fonction GRRLIB_DrawTile. Si tu veux un d�mo regarde l'exemple basic_drawing.

Offline

 

#3 2011-03-22 17:00:18

triki
Member

Re: Animation

ok merci j'ai trouv� en faite je mettais une image supl�mentaire ce qui saccadais mon animation

Last edited by triki (2011-03-22 17:00:37)

Offline

 

#4 2011-03-22 21:08:14

killer128
Member

Re: Animation

Code:

#include <stdio.h>
#include <gccore.h>
#include <ogcsys.h>
#include <unistd.h>
// lib principale
#include <grrlib.h>
#include <stdlib.h>
#include <wiiuse/wpad.h>
 

//les images stoqu� .png
#include "demofont.h" //pour afficher le texte.

#include "player1_point.h"
#include "mario.h"
#include "luigi.h"
#include "sols.h"


#include <fat.h> // <- a must


#define HOTSPOTX 48 // Cursor hot spot for x coordinate
#define HOTSPOTY 48 // Cursor hot spot for y coordinate

//#include "vecteurs.c"


/* blitz3d
offmariox=16
offmarioy=16
scl=16  ;taille de la grille
periode=1
pMax=7
*/
u16 offmariox=16;
u16 offmarioy=16;
u16 scl=16;               //taille de la grille
u16 periode=1;
u16 pMax=7;



//GRRLIB_LoadFileJPG(const char *filename)

//old_anim ; anim ;periode ;frame ;frameMax ;no_bg
u32 old_anim;
u32 anim=1;
//u32 periode;
u32 frame=1;
u32 frameMax=1;
u32 no_bg;

//using namespace std;

#define NUM_STARS     2
#define NUM_bloc     86
 
typedef struct {
    u32 pad;
    u32 px;
    u32 py;
    u32 periode;
    u32 frame;
    u32 frameMax;
    u32 old_anim;
    u32 anim;
    u32 no_bg;
} star;

static star stars[NUM_STARS];

/*
Function new_bloc(typ,Gx,Gy,anim,frame,fmax,hdlpnj) ;Gx et Gy commence a 1
    a.bloc =New bloc
    a\typ=typ
    a\Gx=Gx-1
    a\Gy=Gy-1
    a\anim=anim
    a\frame=frame
    a\foff=frame
    a\fmax=fmax
    a\hdlpnj=hdlpnj
    Return Handle(a)
End Function

Type bloc
    Field typ,Gx,Gy,anim,frame,foff,fmax,hdlpnj
End Type
*/

Mtx GXmodelView2D;


typedef struct {
    u8 typ;
    u8 Gx;
    u8 Gy;
    u8 anim;
    u8 frame;
    u8 foff;
    u8 fmax; //,hdlpnj
} Bloc;

static Bloc LstBloc[NUM_bloc];


int main(int argc, char **argv) {

float alpha=255;
u8 *tex_logo;


    fatInitDefault (); // <- must be there before loading png
 //GRRLIB_texImg 
 *tex_logo = GRRLIB_LoadTextureFromFile("sd:/logo.png"); //FromFile<- here it loads the png, be sure to input where the file is stored in your sd



    GRRLIB_texImg *demo_font = GRRLIB_LoadTexture(demofont);
    GRRLIB_InitTileSet(demo_font, 13, 23, 32);
    
    u32 i;
//    u32 scl=16;    //i,blam; pour plusieurs var
    u32 pressed;
    
    u32 t=1;
    
    //gfh
    /* blitz3d
    For i=1 To 40
        new_bloc(1,i,30,10,2,2,0)
    Next
    */


/*    for(i=0;i<NUM_bloc;i++) {
        LstBloc[i].typ=1;
        LstBloc[i].Gx=i;
        LstBloc[i].Gy=25;
        LstBloc[i].anim=10;
        LstBloc[i].frame=2;
        LstBloc[i].foff=2;
        LstBloc[i].fmax=2;
    }
*/

    for(i=0;i<30;i++) {
        LstBloc[i].typ=1;
        LstBloc[i].Gx=i;
        LstBloc[i].Gy=25;
        LstBloc[i].anim=10;
        LstBloc[i].frame=2;
        LstBloc[i].foff=2;
        LstBloc[i].fmax=2;
    }
    
    for(i=31;i<55;i++) {
        LstBloc[i].typ=1;
        LstBloc[i].Gx=1;
        LstBloc[i].Gy=i-30;
        LstBloc[i].anim=11;
        LstBloc[i].frame=3;
        LstBloc[i].foff=3;
        LstBloc[i].fmax=3;
    }

    for(i=56;i<80;i++) {
        LstBloc[i].typ=1;
        LstBloc[i].Gx=25;
        LstBloc[i].Gy=i-55;
        LstBloc[i].anim=11;
        LstBloc[i].frame=1;
        LstBloc[i].foff=1;
        LstBloc[i].fmax=1;
    }
    

//new_bloc(2,5,28,1,1,1,0)
//new_bloc(2,6,28,1,2,2,0)
//new_bloc(2,7,28,1,3,3,0)
//new_bloc(3,5,29,2,1,1,0)
//new_bloc(3,6,29,2,2,2,0)
//new_bloc(3,7,29,2,3,3,0)
        i=80;
        LstBloc[i].typ=1;
        LstBloc[i].Gx=5;
        LstBloc[i].Gy=23;
        LstBloc[i].anim=1;
        LstBloc[i].frame=1;
        LstBloc[i].foff=1;
        LstBloc[i].fmax=1;
        
        i=81;
        LstBloc[i].typ=1;
        LstBloc[i].Gx=6;
        LstBloc[i].Gy=23;
        LstBloc[i].anim=1;
        LstBloc[i].frame=2;
        LstBloc[i].foff=2;
        LstBloc[i].fmax=2;
        
        i=82;
        LstBloc[i].typ=1;
        LstBloc[i].Gx=7;
        LstBloc[i].Gy=23;
        LstBloc[i].anim=1;
        LstBloc[i].frame=3;
        LstBloc[i].foff=3;
        LstBloc[i].fmax=3;
        
        i=83;
        LstBloc[i].typ=1;
        LstBloc[i].Gx=5;
        LstBloc[i].Gy=24;
        LstBloc[i].anim=2;
        LstBloc[i].frame=1;
        LstBloc[i].foff=1;
        LstBloc[i].fmax=1;
        
        i=84;
        LstBloc[i].typ=1;
        LstBloc[i].Gx=6;
        LstBloc[i].Gy=24;
        LstBloc[i].anim=2;
        LstBloc[i].frame=2;
        LstBloc[i].foff=2;
        LstBloc[i].fmax=2;
        
        i=85;
        LstBloc[i].typ=1;
        LstBloc[i].Gx=7;
        LstBloc[i].Gy=24;
        LstBloc[i].anim=2;
        LstBloc[i].frame=3;
        LstBloc[i].foff=3;
        LstBloc[i].fmax=3;
        

    
    stars[0].pad=1;
    stars[0].px = 100;
    stars[0].py = 200;
    stars[0].periode=1;
    stars[0].frame=1;
    stars[0].frameMax=1;
    stars[0].old_anim=1;
    stars[0].anim=1;
    stars[0].no_bg=0;
    
    stars[1].pad=2;
    stars[1].px = 200;
    stars[1].py = 100;
    stars[1].periode=1;
    stars[1].frame=1;
    stars[1].frameMax=1;
    stars[1].old_anim=1;
    stars[1].anim=1;
    stars[1].no_bg=0;    

    GRRLIB_Init();
 
    //px=400;
    //py=300;


    // chargement des images
    GRRLIB_texImg *Cursor0 = GRRLIB_LoadTexture(player1_point);
    GRRLIB_texImg *marioimg = GRRLIB_LoadTexture(mario);
    GRRLIB_texImg *luigiimg = GRRLIB_LoadTexture(luigi);
    GRRLIB_texImg *solsimg = GRRLIB_LoadTexture(sols);
    
    GRRLIB_SetHandle(Cursor0, HOTSPOTX, HOTSPOTY);// Not needed, by default center is selected
 //
    // Initialise the Wiimotes    
    WPAD_Init();
    WPAD_SetDataFormat(WPAD_CHAN_ALL, WPAD_FMT_BTNS_ACC_IR);
    WPAD_SetVRes(WPAD_CHAN_ALL, rmode->fbWidth, rmode->efbHeight);
 
    // debut de la boucle principale
    while(1) {
        WPAD_ScanPads();  // Scan the Wiimotes
        WPADData *WPadData0 = WPAD_Data(WPAD_CHAN_0);
    
        
        // 34,85,136  // 0x225588FF
        GRRLIB_FillScreen (0x225588FF); //cls color  34,177,76  ;maskimage 0x0022B14C) couleur de fond d'�cran clscolor
        //GRRLIB_Rectangle(0,0,650,650,0x22B14CFF,true); //34,177,76  ;maskimage 0x0022B14C) couleur de fond d'�cran clscolor
        
        
        
        if (WPadData0->btns_d & WPAD_BUTTON_HOME)  break; // si [HOME] de la wiimote est pr�sser alors on retourne au loader
        
        // ---------------------------------------------------------------------
        if(WPadData0->ir.valid){
            GRRLIB_DrawImg(WPadData0->ir.x - HOTSPOTX,
            WPadData0->ir.y - HOTSPOTY,Cursor0 ,
            WPadData0->ir.angle, 1, 1, 0xFFFFFFFF);
        }    
        
        //        if (pressed & WPAD_BUTTON_A){
        //            GRRLIB_DrawPart(150,150,22,22,22,22,fondimg,0,1,1,0xFFFFFFFF);
        //        }else{ 
        //            GRRLIB_DrawPart(150,150,0,0,22,22,fondimg,0,1,1,0xFFFFFFFF);    
        //        }                
        
        /*
        If old_anim<>anim ;r�initialiser la p�riode
            periode=1
            frame=1
        EndIf
        old_anim=anim
        If periode=>15
            periode=1
            If frame<frameMax ;vitess de l'anim
                frame=frame+1
            Else
                frame=1
            EndIf
        Else
            periode=periode+1
        EndIf
        DrawImageRect(img,px,py,(frame-1)*21+frame,(anim-1)*21+anim,20,20)
        */
        

        
        //DrawImageRect(img,px,py,(frame-1)*21+frame,(anim-1)*21+anim,20,20);
        i=0;
        //affichage des objets 2d
        for(i=0;i<NUM_STARS;i++) {
            GRRLIB_DrawPart(stars[i].px,stars[i].py,(stars[i].frame-1)*33+stars[i].frame,(stars[i].anim-1)*33+stars[i].anim,32,32,marioimg,0,1,1,0xFFFFFFFF);

        if (stars[i].old_anim!=stars[i].anim){ //r�initialiser la p�riode
            stars[i].periode=1;
            stars[i].frame=1;
        }
        stars[i].old_anim=stars[i].anim;
        if (stars[i].periode > 14){ //=>15
            stars[i].periode=1;
            if (stars[i].frame<stars[i].frameMax){ //vitess de l'anim
                stars[i].frame=stars[i].frame+1;
            }else{
                stars[i].frame=1;
            }
        }else{
            stars[i].periode=stars[i].periode+1;
        }





if (stars[i].pad==1){

    pressed = WPAD_ButtonsHeld(WPAD_CHAN_0);

        /*
        no_bg=0 ;d�tecte si le joueur est en train d'appuyer sur une touche
        
        If Krgt=1 ;marche vers la droite
            anim=2
            frameMax=2
            no_bg=1
        EndIf
        
        If Klft=1 ;marche vers la gauche
            anim=2
            frameMax=2
            no_bg=1
        EndIf
        
        If Kdwn=1 ;pour se baisser
            anim=3
            frameMax=1
            no_bg=1
        EndIf
        
        If no_bg=0 ;a l'arret
            anim=1
            frameMax=1
        EndIf
        */
        
        stars[i].no_bg=0; //d�tecte si le joueur est en train d'appuyer sur une touche
        //pab a l'horizontal
        if (pressed & WPAD_BUTTON_LEFT)  { //bas
            stars[i].anim=3;
            stars[i].frameMax=1;
            stars[i].no_bg=1    ;
        } 
        
        //   if (pressed & WPAD_BUTTON_RIGHT) { //haut 
        //   }
        if (pressed & WPAD_BUTTON_UP)    { //gauche
            stars[i].anim=2;
            stars[i].frameMax=2;
            stars[i].no_bg=1     ;
            stars[i].px=stars[i].px-1 ;
        }
        
        if (pressed & WPAD_BUTTON_DOWN)  { //doite
            stars[i].anim=2;
            stars[i].frameMax=2;
            stars[i].no_bg=1     ;  
            stars[i].px=stars[i].px+1;
        }
        
        if (stars[i].no_bg==0) {//a l'arret
            stars[i].anim=1;
            stars[i].frameMax=1;
        }

    
}
if (stars[i].pad==2){

    pressed = WPAD_ButtonsHeld(WPAD_CHAN_1);
        
        stars[i].no_bg=0; //d�tecte si le joueur est en train d'appuyer sur une touche
        //pab a l'horizontal
        if (pressed & WPAD_BUTTON_LEFT)  { //bas
            stars[i].anim=3;
            stars[i].frameMax=1;
            stars[i].no_bg=1    ;
        } 
        
        //   if (pressed & WPAD_BUTTON_RIGHT) { //haut 
        //   }
        if (pressed & WPAD_BUTTON_UP)    { //gauche
            stars[i].anim=2;
            stars[i].frameMax=2;
            stars[i].no_bg=1     ;
            stars[i].px=stars[i].px-1 ;
        }
        
        if (pressed & WPAD_BUTTON_DOWN)  { //doite
            stars[i].anim=2;
            stars[i].frameMax=2;
            stars[i].no_bg=1     ;  
            stars[i].px=stars[i].px+1;
        }
        
        if (stars[i].no_bg==0) {//a l'arret
            stars[i].anim=1;
            stars[i].frameMax=1;
        }

        
}
            
        }

        
        i=0;
        //DrawImageRect(sols,a\Gx*scl,a\Gy*scl,(a\frame-1)*(scl+1)+a\frame,(a\anim-1)*(scl+1)+a\anim,scl,scl)
        for(i=0;i<NUM_bloc;i++) {
            GRRLIB_DrawPart(LstBloc[i].Gx*16,LstBloc[i].Gy*16,(LstBloc[i].frame-1)*17+LstBloc[i].frame,(LstBloc[i].anim-1)*17+LstBloc[i].anim,16,16,solsimg,0,1,1,0xFFFFFFFF);
            
            /*
            If periode=>pMax
                If a\frame<a\fmax ;vitess de l'anim
                    a\frame=a\frame+1
                Else
                    a\frame=a\foff
                EndIf
            EndIf
            */
            
            if (periode > pMax-1){
                if (LstBloc[i].frame < LstBloc[i].fmax){ //;vitess de l'anim
                    LstBloc[i].frame = LstBloc[i].frame+1;
                }else{
                    LstBloc[i].frame = LstBloc[i].foff;
                }
            }
            
        }
    
        //GRRLIB_DrawPart(px,py,(frame-1)*21+frame,(anim-1)*21+anim,20,20,fondimg,0,1,1,0xFFFFFFFF);
        
        
        
        
        
GRRLIB_DrawImg(144, 176, tex_logo, 0, 1, 1, alpha );

        
        GRRLIB_Printf(5, 5, demo_font, 0xFFFFFFFF, 1,"anim %i f: %i p: %i Fm: %i",anim,frame,periode,frameMax); //afficher un txt + var int.
//    GRRLIB_DrawPart(30,30,(1-1)*21+1,(1-1)*21+1,20,20,mario_Pimg,0,1,1,0xFFFFFFFF);

        /*
        Color 0,0,0
        Text 0,0,"ctrl gauche pour courir ; up pour sauter" ;"anim "+VectorY#(vecSaut)+" "+saa ;anim+" f: "+frame+" p: "+periode
        Text 0,15,"espace gauche pour afficher la collision du perso sur sa grille"
        Text 0,30,"appuyer sur entrer pour changer de perso mario/luigi"
        Text 0,45,"mario sautte plus haut et luigi peut sauter plusieur fois "
        Text 0,60,">Suite a une erreur de programmation de mario ,j'ai donc fait luigi XD"
        */
        GRRLIB_Render();  // Render the frame buffer to the TV
    } //fin de la boucle principale
 
    GRRLIB_Exit(); // Be a good boy, clear the memory allocated by GRRLIB
    
    GRRLIB_FreeTexture(demo_font);
    GRRLIB_FreeTexture(Cursor0);

    GRRLIB_FreeTexture(marioimg);
 //   GRRLIB_FreeTexture(luigi_Pimg);
 //   GRRLIB_FreeTexture(solsimg);

    exit(0);
}

/*
int Level[] = {
//------------------------ Map du niveau -------------------------------------------------
    0,0,0,0,0,0,0,0,
    0,0,1,0,1,0,0,0,
    0,0,0,0,0,1,0,1,
    0,0,1,0,1,1,0,1
};
*/

/*
u8 * GRRLIB_LoadFileJPG(const char *filename) {

    FILE *fd = fopen(filename, "rb");

    // obtain file size:
    fseek(fd , 0 , SEEK_END);
    long lSize = ftell(fd);
    rewind(fd);

    // read the file
    unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lSize);
    fread (buffer, 1, lSize, fd);
    fclose(fd);

    // load data into a texture
    u8 *tex = GRRLIB_LoadJPG(buffer, (unsigned int)lSize);
    
    free(buffer);
    return tex;
}


*/

GRRLIB_texImg *GRRLIB_LoadTextureFromFile(const char *filename) {
    GRRLIB_texImg *tex = NULL;
    fatInitDefault();
    FILE *fd = fopen(filename, "rb");
    if(fd != NULL) {
        fseek(fd, 0, SEEK_END);
        long lsize = ftell(fd);
        rewind(fd);
    
        unsigned char *buffer = (unsigned char*) malloc (sizeof(unsigned char)*lsize);
        if(buffer) {
            fread (buffer, 1, lsize, fd);
            tex = GRRLIB_LoadTexture(buffer);
            free(buffer);
        }
        fclose(fd);
    }
    return tex;
}

Voici mon 1er code source
j'utilise notamment des animations de mario sur snes  364/452
sa commence a l'animation 1 et la frame 1
chaque animation sont dans un rectangle de 34/34 et dans ce rectangle accol� les un au autre il y a frame en elle m�me qui fait 32/32
j'utilise "p�riode" et "Pmax" pour d�finir la vitesse des animations.
j'utilise une structure "star" pour pouvoir cr�e plusieurs joueurs.
amuse toi bien a chercher dans mon code ^^.

Offline

 

#5 2011-03-23 17:41:38

triki
Member

Re: Animation

merci a toi je vais matter

Offline

 

Board footer

Powered by FluxBB