Bonjour,
J'ai en effet un souci avec un programme que je n'arrive plus à faire marcher
SDL_Texture *load_texture(const signed char *filepath)
{
SDL_Texture *texture = NULL;
texture = IMG_LoadTexture(app.renderer, filepath);
if (texture==NULL)
SDL_ExitWithError("impossible de charger l'image");
return texture;
}
void blit_texture(SDL_Texture *texture, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;
if (SDL_QueryTexture(texture, NULL, NULL, &dest.w, &dest.h)!=0)
SDL_ExitWithError("impossible de d'allouer la texture dans la memoire vive");
if (SDL_RenderCopy(app.renderer, texture, NULL, &dest)!=0)
SDL_ExitWithError("impossible de copier le rendu SDL2");
return;
}
void blit_player(void)
{
blit_texture(player.texture, player.x, player.y);
return;
}
void blit_bullet(void)
{
blit_texture(bullet.texture, bullet.x, bullet.y);
return;
}
void SDL_InitPlayer(void)
{
player.x = SDL_PLAYER_SPAWNPOINT_X;
player.y = SDL_PLAYER_SPAWNPOINT_Y;
player.texture = load_texture("player.png");
return;
}
void SDL_InitBullet(void)
{
bullet.texture = load_texture("bullet.png");
return;
}
void SDL_DoPlayer(void)
{
if(app.up==1)
player.y-=SDL_PLAYER_SPEED;
if(app.down)
player.y+=SDL_PLAYER_SPEED;
if(app.left==1)
player.x-=SDL_PLAYER_SPEED;
if(app.right==1)
player.x+=SDL_PLAYER_SPEED;
if(app.fire==1&&bullet.health==0)
{
bullet.health=1;
bullet.x=player.x;
bullet.y=player.y;
printf("Fire");
}
return;
}
void SDL_DoBullet(void)
{
if(bullet.health==1)
{
bullet.y-=SDL_PLAYER_BULLET_SPEED;
if(bullet.y<0)
{
printf("Destroy Bullet");
bullet.health=0;
}
blit_texture(bullet.texture, bullet.x, bullet.y);
}
}
Ce code marche en principe pour la création et la gestion du bullet mais la texture refuse de s'afficher