Jour 22 - Les Splash Screen

Ajouter un splash screen

Pour commencer, je vais vous montrer la première fonction de Xiaopa qui charge un splash. Voyons plus en détail ce que fait cette fonction :

  • Rend tout ce qu’il y a à l’écran invisible
  • Charge le fond “splah1” sur l’écran du bas.
  • Fait un fondu vers le fond.
  • Attend que 3 secondes (180 frames) soient écoulées ou que l’utilisateur presse A ou touche l’écran.
  • Fait disparaître le fond en fondu.
  • Supprime le fond
  • Charge le fond “splash2” sur l’écran du bas
  • Fondu vers le fond
  • Attend que 3 secondes (180 frames) soient écoulées ou que l’utilisateur presse A ou touche l’écran.
  • Fait disparaître le fond en fondu
  • Supprime le fond
  • Fait un fondu et appelle la fonction MainMenu()
void MySplash()
{
   s32 i;
   s32 time;
   
   PA_SetBrightness(1, -31);
   PA_SetBrightness(0, -31);
   
   PA_EasyBgLoad(0, 0, splash1);
   
   for(i = -31;i<=0;i++){
      PA_SetBrightness(1, i);
      PA_SetBrightness(0, i);
      PA_WaitForVBL();
   }
   
   while(time && !(Pad.Newpress.A || Stylus.Newpress)){
      time--;
      PA_WaitForVBL();
   }
   
   for(i=0;i >= -31;i--){
      PA_SetBrightness(1, i);
      PA_SetBrightness(0, i);
      PA_WaitForVBL();
   }
   
   PA_DeleteBg(0, 0);
   PA_EasyBgLoad(0, 0, splash2);
   
   for(i = -31;i<=0;i++){
      PA_SetBrightness(1, i);
      PA_SetBrightness(0, i);
      PA_WaitForVBL();
   }
   
   while(time && !(Pad.Newpress.A || Stylus.Newpress)){
      time--;
      PA_WaitForVBL();
   }
   
   for(i=0;i >= -31;i--){
      PA_SetBrightness(1, i);
      PA_SetBrightness(0, i);
      PA_WaitForVBL();
   }
   
   PA_DeleteBg(0, 0);
   
   for(i = -31;i<=0;i++){
      PA_SetBrightness(1, i);
      PA_SetBrightness(0, i);
      PA_WaitForVBL();
   }
}

Et voilà, vous avez un simple splash screen pour votre projet !

Ajouter un splash screen ( Alternative )

J’ai essayé le code presenté ci-dessus mais j’ai rencontré quelques bugs. Par conséquent, j’ai réécrit un peu ce code Je suis nouveau en C. .. Donc, si quelque chose est mauvais s’il vous plaît modifier le code.

Changements:

Le code original etait très apprecié... surtout par moi, mais comme je disais, ce code comporte quelques bugs.

  • Tout d’abord, 31 comme valeur pour la luminosité provoque des bugs pour certaines raisons... c’est pourquoi je l’ai changé à 16.Cela provoque un degradé entre la luminosité faible et la luminosité haute, sans défauts notables. à 31, cela serait faussé.
(Note: Ceci est un problème aussi connu avec **PA_SetSFXAlpha**)
  • La vérification de la pression d’une touche a été enfermé dans une boucle “while”, vous fesant attendre la fin du Splash-creen.
  • Dans le code original, si vous vouliez non pas 2 mais 4 Splash-Screen il vous fallait recopiez deux fois le même code, la il ne vous en faudrat plus que 3 lignes supplémentaires

J’ai ajouté des commentaires pour que vous compreniez bien le système de proses et maths utilisé,dans ce dernier point je crois que j’ai échoué pour la plupart. Si vous pensez que vous pouvez la rendre plus intuitive n’hesitez pas à la modifier s’il vous plaît.

Vous pouvez directement faire un Copier/Coller dans votre projet. Pensez quand même à modifier le noms des BGs

PA_EasyBgLoad(0, 0, BottomSplash1);	// call it like this...
PA_EasyBgLoad(1, 0, TopSplash1);	// Load BGs and call
MySplash();	         		//  the function.
 
PA_EasyBgLoad(0, 0, BottomSplash2);	// a second splash
PA_EasyBgLoad(1, 0, TopSplash2);	//  would be called
MySplash();	         		//  like this.
 
PA_EasyBgLoad(0, 0, BottomSplash3);	// third...
PA_EasyBgLoad(1, 0, TopSplash3);	// 
MySplash();	         		// 
 
void MySplash()
{
   u8 a = 1;				// true-false switch
   s32 b = -16;				// (see first if loop)
   s32 i = -16;				// counter
   s32 time = 182;			// three seconds (this does not change)
   
   PA_SetBrightness(1, -16);		// set brightness to completely faded out.
   PA_SetBrightness(0, -16);		//  (only -16 realy works)
   
   while ( a == 1 ) {			// while the switch is flipped...
 
      if( i <= 0 ){			// untill 'i' (our assigned value
         PA_SetBrightness(1, i);	//  between -16 and 0) is zero,
         PA_SetBrightness(0, i);	//  it fades in (0 is no fade and
	 b = i;				//  -16 is complete fade.
      }					// 'b' remembers where i was at.
   
      if ((Pad.Newpress.Anykey || Stylus.Newpress) && (i < time)){
         i = time - b;			// Over here, if the pad or screen are
      }					//  pressed, 'i' becomes the necesary value
					//  for fade out. otherwise it slowly works
					//  up to 182. (notice that in the first
					//  loop i was -16 to 0. if the pad is pressed
					//  at 'i = -10', here i = 182 + 10.
					//  this stops it in mid fade)
   
      if((i <= 16 + time) && (i >= time - b)){
         PA_SetBrightness(1, time - i - b);	//quick calculations...
         PA_SetBrightness(0, time - i - b);
 
      }
 
      if(i > 16 + time) {a = 0;}	// set the switch to 0 after fading out exiting the
					//  while loop after only one run 
 
      i++;				//counter up!
      PA_WaitForVBL();			// notice this needs be done only once...
 
   }
 
   PA_ResetBgSys();			// clean up.
   					//
 
   PA_SetBrightness(1, 0);		// restore brightness...
   PA_SetBrightness(0, 0);
 
   return 0;
 
}

Des splash Screens si simple pour vos projets.

Ajouter un splash screen ( Alternative 2 )

Ceci est une version beaucoup plus optimisée pour l’affichage de Splash Screen multiple. Il ne devrait pas être trop difficile à comprendre, donc je vais inclure l’ensemble du projet, totuefois je l’ai un peu commenté. Vous pouvez Copier/Coller directement(à l’exclusion des fonds ... vous pouvez télécharger le code source complet, si nécessaire). S’il ya une erreur dans ce code s’il vous plaît stratton.sloane@gmail.com.

// Includes
//--------------------------------------------------------------------------------------------------
 
#include <PA9.h>               // Include for PAlib
 
#include "gfx/all_gfx.h"       // Our backgrounds and/or sprites
#include "gfx/all_gfx.c"     
 
// Functions
//--------------------------------------------------------------------------------------------------
 
void mySplash();
void fadeIn();
void fadeOut();
 
 
//--------------------------------------------------------------------------------------------------
int main(int argc, char ** argv) {
//--------------------------------------------------------------------------------------------------
   
	PA_Init();                   // Initializes PA_Lib
	PA_InitVBL();                // Initializes a standard VBL
	
	mySplash();
	
	PA_InitText(0, 0);           // Initialize text on the top screen
	PA_InitText(1, 0);           // Initialize text on the bottom screen
	
	PA_OutputText(0, 1, 1, "Splash screen finished!");
	      
        fadeIn();
 
	while (1)                    // Our main loop
	{	   
		PA_WaitForVBL();
	}
	
	return 0;
} // End of main()
 
 
//--------------------------------------------------------------------------------------------------
void mySplash() {
//--------------------------------------------------------------------------------------------------
 
   int i;                       // Our timer, used for the splash auto-continuation
   
   // Set the initial brightness
   //-----------------------------------------------------------------------------------------------
   PA_SetBrightness(0, -31);
   PA_SetBrightness(1, -31); 
 
 
   // Splash 1
   //-----------------------------------------------------------------------------------------------
   PA_EasyBgLoad(1, 3, splashTop);
   PA_EasyBgLoad(0, 3, splashBottom);
   
   fadeIn();
   
   for (i = 0; i < 60*3; i++)
   {
      if(Pad.Newpress.A || Stylus.Newpress) break;	
      PA_WaitForVBL();
   }   
   
   fadeOut();
   
   
   // Clear all loaded data
   //-----------------------------------------------------------------------------------------------
   PA_ResetBgSys();
   PA_ResetSpriteSys();
   
   
   // Splash 2
   //-----------------------------------------------------------------------------------------------
   PA_EasyBgLoad(1, 3, splash2Top);
   PA_EasyBgLoad(0, 3, splash2Bottom);
   
   fadeIn();
   
   for (i = 0; i < 60*3; i++)
   {
      if(Pad.Newpress.A || Stylus.Newpress) break;	
      PA_WaitForVBL();
   }   
   
   fadeOut();
   
   // Clear all loaded data
   //-----------------------------------------------------------------------------------------------
   PA_ResetBgSys();
   PA_ResetSpriteSys();
   
   // Note:
   // When you end the splash, make sure to
   // fade back in or set the brightness to
   // its normal level. This way you won't
   // end up with a black screen ;). You
   // should probably do this in your next
   // function, once it's loaded.
}   
 
 
//--------------------------------------------------------------------------------------------------
void fadeOut() {
//--------------------------------------------------------------------------------------------------   
   
   s8 i;
   
   for (i = 0; i >= -31; i--) {
			PA_SetBrightness(0, i); 
			PA_SetBrightness(1, i);		                 
			PA_WaitForVBL();
		}   
}
 
//--------------------------------------------------------------------------------------------------
void fadeIn() {
//--------------------------------------------------------------------------------------------------
   
   s8 i;
   
   for (i = -31; i <= 0; i++) {
			PA_SetBrightness(0, i);
			PA_SetBrightness(1, i);
			PA_WaitForVBL(); 
		}	
}

Version finale .nds

Version finale Code Source

Vous pouvez la réduire encore plus en ajoutant cette fonction

//--------------------------------------------------------------------------------------------------
void fadeSplash(int seconds) {
//--------------------------------------------------------------------------------------------------
   fadeIn();
   
   for (i = 0; i < 60*seconds; i++)
   {
      if(Pad.Newpress.A || Stylus.Newpress) break;	
      PA_WaitForVBL();
   }   
   
   fadeOut();
}

Si vous regardez le code c’est assez explicite. Il permet aussi de configurer l’attente (en secondes) de chaque Splash Screen. N’oubliez pas de les déclarer au début avec les autres fonctions, comme ceci:

void fadeSplash(int seconds);

Version finale code source avec la fonction

 
day22.txt · Dernière modification: 26/02/2010 19:00 par 79.82.244.68
 
Recent changes RSS feed Creative Commons License Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki