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

 

 


Tema destacado: Tutorial básico de Quickjs


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación C/C++ (Moderadores: Eternal Idol, Littlehorse, K-YreX)
| | |-+  ayuda con SDL c++
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: ayuda con SDL c++  (Leído 1,320 veces)
kabutom

Desconectado Desconectado

Mensajes: 14



Ver Perfil
ayuda con SDL c++
« en: 8 Enero 2018, 17:09 pm »

el problema es que al mover el personaje se quedan las imágenes atrás  , aunque si aparecen desde su posición y avanza Asia donde se presiona ,pero se queda como un rastro ,abajo esta el código y aquí el link de las imágenes:https://mega.nz/#!RNswjIJB!d9FvXkTBby_cs8zkyXI0nDrsKPaCdGQbCaUi66J9S5E   y  https://mega.nz/#!cB9kkQTI!GvtijkRzZXRhXRKLAhZK1pytnN8gsCKYDz8aYH0DPRY #include<stdio.h>
#include<SDL.h>
#include<SDL_image.h>
#include<iostream>
#include <stdlib.h>
using namespace std;

int main(int argc, char *argv[]) {   
   cout << "inicializacion....... " << endl;
   cout << "creando ventana....." << endl;
   cout << "cargando imagenes....." << endl;
   cout << "comprobando errores...." << endl;
   SDL_Init(SDL_INIT_EVERYTHING);
   SDL_Window*window = SDL_CreateWindow("juego", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 700, 480, SDL_WINDOW_SHOWN);
   SDL_Surface*windowSurface = nullptr;
   SDL_Surface*imageSurface = nullptr;
   SDL_Surface*bola = nullptr;

   SDL_Rect posicion;
   SDL_Event tecla;
   windowSurface = SDL_GetWindowSurface(window);
   imageSurface = SDL_LoadBMP("h.BMP");
   bola = SDL_LoadBMP("normal.BMP");
   
   posicion.x = 200;
   posicion.y = 300;
   posicion.h = bola->h;
   posicion.w = bola->w;
   SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
   while (true) {
   
      SDL_BlitSurface(imageSurface, NULL, windowSurface, NULL);
   SDL_BlitSurface(bola, NULL, imageSurface, &posicion);
   SDL_UpdateWindowSurface(window);
   while (SDL_PollEvent(&tecla)) {
      if (tecla.type == SDL_QUIT) {
         exit(0);
      }
      if (tecla.type == SDL_KEYDOWN) {

         if (tecla.key.keysym.sym == SDLK_RIGHT){
            posicion.x++;
            posicion.x++;
            posicion.x++;
            posicion.x++;
            posicion.x++;
            posicion.x++;
            
         }
         if (tecla.key.keysym.sym == SDLK_LEFT) {
            posicion.x--;
            posicion.x--;
            posicion.x--;
            posicion.x--;
            posicion.x--;
            posicion.x--;
         }
         if (tecla.key.keysym.sym == SDLK_UP) {
            posicion.y--;
            posicion.y--;
            posicion.y--;
            posicion.y--;
            posicion.y--;
            posicion.y--;
         }
         if (tecla.key.keysym.sym == SDLK_DOWN) {
            posicion.y++;
            posicion.y++;
            posicion.y++;
            posicion.y++;
            posicion.y++;
            posicion.y++;


         }
}
   }
   }
   SDL_Delay(4000); 
   SDL_DestroyWindow(window);
   SDL_Quit();
   return 0;
}



En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines