elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: (TUTORIAL) Aprende a emular Sentinel Dongle By Yapis


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  SDL mixer + SDL ttf; No se ejecutan
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: SDL mixer + SDL ttf; No se ejecutan  (Leído 1,457 veces)
Puntoinfinito


Desconectado Desconectado

Mensajes: 919


#! /win/archlinux


Ver Perfil WWW
SDL mixer + SDL ttf; No se ejecutan
« en: 20 Enero 2013, 13:47 pm »

Hola!

Mirad estoy programando un juego en SDL, y a la hora añadir sonidos no se ejecutan... Y teoricamente todo esta bien definido... Tampoco me va a la hora de escribir textos, con la extensión TTF.

Aquí os dejo el código para que veáis un poco;

Código
  1. #include "functions.h"
  2. #include <iostream>
  3. #include <SDL/SDL.h>
  4. #include <SDL/SDL_mixer.h>
  5. #include <SDL/SDL_ttf.h>
  6.  
  7. using namespace std;
  8.  
  9. int main() {
  10.  
  11. //Iniciamos
  12. if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  13. cout << "Error inesperado";
  14. cin.sync();
  15. cin.get();
  16. return 0;
  17. }
  18.  
  19. if( Mix_OpenAudio( 22050, MIX_DEFAULT_FORMAT, 2, 4096 ) < 0 ) {
  20. cout << "Error inesperado";
  21. return 0;
  22. }
  23.  
  24. //Variables
  25. SDL_Surface *nave;
  26. SDL_Surface *fondo;
  27. SDL_Surface *screen;
  28. SDL_Surface *texto;
  29. SDL_Rect destino;
  30. Uint8 * teclas = SDL_GetKeyState ( NULL );
  31. SDL_Event suceso;
  32. int yNave = 230/2, xNave = 240/2;
  33. int yFondo = 0, xFondo = 0;
  34. int terminado = 0;
  35. int tecla;
  36. TTF_Font* font = TTF_OpenFont("air.ttf",36);
  37. SDL_Color color = {250,250,250};
  38.  
  39. // The music that will be played
  40. Mix_Music *musica = NULL;
  41. //The sound effects that will be used  
  42. Mix_Chunk *disparos = NULL;
  43. Mix_Chunk *motor = NULL;
  44. Mix_Chunk *explosion = NULL;
  45. Mix_VolumeMusic(50);
  46. musica = Mix_LoadMUS("pixeluniverse.wav");
  47. if (!Mix_PlayMusic(musica, -1)) {
  48. cout << "Error inesperado";
  49. }
  50.  
  51. //Definir variables
  52. nave = SDL_LoadBMP("nave.bmp");
  53. fondo = SDL_LoadBMP("fondo.bmp");
  54. texto = TTF_RenderText_Solid(font,"Score : 0",color);
  55.  
  56. //Poner transparencia a la nave
  57. quit_color(nave, 0, 255, 0);
  58.  
  59. //Creamos ventana
  60. screen = SDL_SetVideoMode(320, 240, 32, SDL_HWSURFACE | SDL_DOUBLEBUF);
  61. if (screen == NULL) {
  62. cout << "Error inesperado";
  63. cin.sync();
  64. cin.get();
  65. SDL_Quit();
  66. return 0;
  67. }
  68.  
  69. // El getch cada 20 segundos
  70.   SDL_EnableKeyRepeat(5, 5);
  71.  
  72. //Nombre de ventana
  73. SDL_WM_SetCaption( "Naves", NULL );
  74.  
  75. while (terminado == 0) {
  76.  
  77. //Dibujamos fondo
  78. SDL_Rect posFondo;
  79.  
  80. posFondo.y = yFondo;
  81. posFondo.x = xFondo;
  82. SDL_BlitSurface(fondo, NULL, screen, &posFondo);
  83. apply_surface( 0, yFondo + fondo->h, fondo, screen );
  84.  
  85. //Texto blit
  86. SDL_BlitSurface(texto,NULL,screen,NULL);
  87.  
  88. //Dibujamos nave
  89. destino.y = yNave;
  90. destino.x = xNave;
  91. SDL_BlitSurface(nave, NULL , screen, &destino);
  92.  
  93. SDL_Flip(screen);
  94.  
  95. while (SDL_PollEvent(&suceso)) {
  96. if (suceso.type == SDL_QUIT)    terminado = 1;
  97. if (suceso.type == SDL_KEYDOWN)
  98. if (suceso.key.keysym.sym == SDLK_ESCAPE)  terminado = 1;
  99. }
  100. if (teclas[SDLK_ESCAPE]) { terminado = 1; }
  101. if (teclas[SDLK_UP]) { yNave -= 2; }
  102. if (teclas[SDLK_DOWN]) { yNave += 2; }
  103. if (teclas[SDLK_LEFT]) { xNave -= 3; }
  104. if (teclas[SDLK_RIGHT]) { xNave += 3; }
  105.  
  106. if( yFondo <= -posFondo.w )
  107. { //Reset the offset
  108. yFondo = 0; }
  109.  
  110. yFondo -= -1;
  111.  
  112. SDL_Delay( 5 );
  113.  
  114. }
  115. Mix_FreeMusic(musica);
  116. SDL_Quit();
  117. cout << "EXIT";
  118. return 0;;
  119. }

Para ver donde están los argumentos de mixer y ttf, buscad por los que comienzan por Mix y TTF.

Saludos!


En línea

AHORA EN SOFTONIC || CLICK HERE!!
Base64: QWNhYmFzIGRlIHBlcmRlciAxIG1pbnV0byBkZSB0dSB2aWRhLiBPbOkh



HACK AND 1337 : http://hackandleet.blogspot.com
WEBSITE: http://www.infiniterware.
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
error al editar con imagen mixer
Diseño Gráfico
eduardo fuks 0 1,725 Último mensaje 18 Marzo 2005, 14:00 pm
por eduardo fuks
Errores con Wilma: 631:mixerGetLineInfo:Mixer:Invalid parameter ....
Multimedia
maccacus09 4 2,182 Último mensaje 29 Marzo 2005, 05:09 am
por mikkelele
No aparece el Stereo Mixer en el volumen de WXP
Multimedia
brunomenarvino 5 2,765 Último mensaje 29 Junio 2007, 21:38 pm
por Songoku
No se me ejecutan los alias
GNU/Linux
danny920825 7 3,031 Último mensaje 4 Junio 2015, 00:55 am
por MinusFour
[C][?] No se ejecutan printf
Programación C/C++
JoseluCross 5 3,122 Último mensaje 25 Marzo 2016, 15:07 pm
por JoseluCross
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines