Précédent   Forum du club des développeurs et IT Pro > Applications > Développement 2D, 3D et Jeux > API graphiques > SDL
SDL Forum d'entraide sur l'API SDL. Avant de poster -> FAQ SDL
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 30/05/2012, 21h51   #1
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Par défaut Rotation Image / Positionnement / SDL_gfx

Bonjour,
Je cherche à faire développer un tower defense. Pour cela, j'aurais besoin de developper une fonctionalité qui permet aux tourelles de tourner.
J'ai donc ecrit ce code mais le positionnement ne marche pas et il y a une bande noire dont je n'arrive pas à me débarasser.

Voici le code :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
 
void RotationSdl(SdlJeu *sj, SDL_Surface * ecran, int xtank, int ytank, int xtourelle, int ytourelle, int type)
{
	SDL_Surface * rotation = NULL;
	double angle=45;
	SDL_Rect pos;
	pos.x=xtourelle;
	pos.y=ytourelle;
	{
		if(type==2)
		{
			/*angle=tan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank));*/
			rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
                        SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
			SDL_SetAlpha(rotation, SDL_RLEACCEL, 0);
			AffichageImageSdlJeu (rotation, ecran, xtourelle, ytourelle);
        		pos.x =  xtourelle - rotation->w / 2; //Test du positionnement de l'image en fonction de la taille
        		pos.y =  ytourelle - rotation->h / 2;
			angle++;
		}
 
		if(type==3)
		{
			/*angle=tan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank));*/
			rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
                        SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
			SDL_SetAlpha(rotation, SDL_RLEACCEL, 0);
			AffichageImageSdlJeu (rotation, ecran, xtourelle,  ytourelle);
			pos.x =  xtourelle - rotation->w * 2; //ReTest du positionnement
        		pos.y =  ytourelle - rotation->h * 2;
			angle++;
		}
	SDL_FreeSurface(rotation);
	}
}
Et voici ce que cela me donne :

http://imageshack.us/photo/my-images...eenshotxvi.png

Merci de bien vouloir m'aider
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/05/2012, 18h30   #2
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Sinon personne aurait un bon tuto sur sdl_gfx parce que celui du site du zéro est vraiment très lapidaire.
Merci
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/05/2012, 19h48   #3
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Bonjour,

Je me demande quels sont les fichiers utilisés à la base. Je veux dire par là, que je pense que vous aurez moins de soucis, si vous utilisez un sprite qui ne contient que la terre (le sol) et un sprite qui ne contient que la tourelle (et ce uniquement celui ci que l'on tourne).
Si tel est déjà le cas, alors il y a un problème avec la gestion de l'alpha. Peut être faudra t-il refaire la commande pour indiquer la couleur de transparence à la SDL.
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 31/05/2012, 20h15   #4
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Bonjour,
déjà merci pour votre réponse, ensuite j'utilise bien un sprite pour le terrain, un autre pour la base de la tourelle et un troisième pour le canon.
Donc, dans ma fonctionnalité je veux juste faire tourner l'image du canon.

Dans mon code (que j'ai un peu retouché), j'essaye déjà de m'occuper de la transparence du noir avec
Code :
1
2
 
SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
voici le code complet

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
 
void RotationSdl(SdlJeu *sj, SDL_Surface * ecran, int xtank, int ytank, int xtourelle, int ytourelle, int type)
{
	SDL_Surface * rotation = NULL;
	double angle;
	SDL_Rect pos;
	pos.x=xtourelle;
	pos.y=ytourelle;
 
	if(ytourelle<ytank && xtourelle>xtank)
	{
		angle=90+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	else if (ytourelle>ytank && xtourelle>xtank)
	{
		angle=90-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	else if (ytourelle>ytank && xtourelle<xtank)
	{
		angle=270+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	else if (ytourelle<ytank && xtourelle<xtank)
	{
		angle=270-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	if(type==2)
	{
		rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
	}
	if(type==3)
	{
		rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
	}
 
	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
	SDL_SetAlpha(rotation, SDL_RLEACCEL, 0);
	AffichageImageSdlJeu (rotation, ecran, xtourelle,  ytourelle);
	pos.x =  xtourelle - rotation->w / 2; /*ReTest du positionnement*/
        pos.y =  ytourelle - rotation->h / 2;
	SDL_FreeSurface(rotation);
}
Merci beaucoup pour l'aide !
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/06/2012, 16h16   #5
Djakisback
Membre Expert
 
Avatar de Djakisback
 
Inscription : février 2005
Messages : 1 911
Détails du profil
Informations forums :
Inscription : février 2005
Messages : 1 911
Points : 1 839
Points : 1 839
Salut,
peut-être une réponse ici : http://www.developpez.net/forums/d70...tozoomsurface/
__________________
Vive les roues en pierre
Djakisback est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/06/2012, 17h15   #6
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Oui, je comprends pourquoi ça marche pas maintenant mais comment je définis la transparance pixel par pixel alors ?
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 10h51   #7
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Je pense qu'il faut virer le SetAlpha ( http://www.gamedev.net/topic/501621-...-transparency/ )
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 12h38   #8
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Ok, je l'ai enlevé donc il n'y a plus de noir mais la transparence avec l'image du canon ne se fait plus

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
 
void RotationSdl(SdlJeu *sj, SDL_Surface * ecran, int xtank, int ytank, int xtourelle, int ytourelle, int type)
{
	SDL_Surface * rotation = NULL;
	double angle;
	SDL_Rect pos;
	pos.x=xtourelle;
	pos.y=ytourelle;
 
	if(ytourelle<=ytank && xtourelle>=xtank)
	{
		angle=90+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	else if (ytourelle>ytank && xtourelle>xtank)
	{
		angle=90-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	else if (ytourelle>=ytank && xtourelle<=xtank)
	{
		angle=270+(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	else if (ytourelle<ytank && xtourelle<xtank)
	{
		angle=270-(180/PI)*(atan(fabs(ytourelle-ytank)/fabs(xtourelle-xtank)));
	}
	if(type==2)
	{
		rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
	}
	if(type==3)
	{
		rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
	}
	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
	pos.x =  pos.x - rotation->w/20 ; 
        pos.y =  pos.y - rotation->h/20 ;
	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL|SDL_SRCALPHA), SDL_MapRGB(rotation->format, 255, 0, 255));
	SDL_BlitSurface(rotation, NULL, ecran, &pos);
        SDL_FreeSurface(rotation); //On efface rotation car on va la redéfinir dans la prochaine boucle. Si on ne le fait pas, cela crée une fuite de mémoire. 
}
voici l'image que j'ai :

http://www.noelshack.com/2012-22-133...reenshot-1.png

Merci de l'aide
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 14h19   #9
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Au final, pourquoi n'utilisez vous pas des fichiers en PNG ayant un canal alpha ?
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h18   #10
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
En fait j'ai déjà essayé mais je ne sais pas comment ça s'utilise donc j'ai des problemes de segmentation.
Y a pas un moyen facile de faire avec des bmp vu qu'il ne manque plus que la transparence du canon à faire ?
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h22   #11
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
On peut faire un BMP en 32bits, qui aura donc une couche d'alpha, mais le PNG restait une meilleure solution.
Vous chargez vos images avec SDL_image ?
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h28   #12
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Je charge mes images comme ça :
Code :
1
2
3
4
5
6
 
	SDL_Rect pos;
	pos.x = (int) x;
	pos.y = (int) y;
	SDL_SetColorKey (img, SDL_SRCCOLORKEY, SDL_MapRGB (img->format,255 ,0,255));
	SDL_BlitSurface(img, NULL, ecran, &pos);
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h35   #13
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Non ça c'est pour l'affichage. En SDL le chargement se fait avec SDL_LoadBMP() et avec SDL_image en utilisant IMG_Load()
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h38   #14
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
ah oui pardon, j'utilise SDL_LoadBMP()
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h41   #15
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Je vous conseille d'utiliser SDL_image afin de charger des PNG, qui auront un canal de transparence.
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h45   #16
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Juste pour les canons ou pour toutes les images ?
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 16h49   #17
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Autant toutes les faire
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 17h03   #18
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Voilà c'est fait mais en gardant le code :

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
 
if(type==2)
	{
		rotation=rotozoomSurface(sj->image->imgtourelle[6], angle, 1.0, 1);
	}
	if(type==3)
	{
		rotation=rotozoomSurface(sj->image->imgtourelle[8], angle, 1.0, 1);
	}
	SDL_SetAlpha(rotation, SDL_RLEACCEL, 1);
	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(rotation->format, 0, 0, 0));
 
	pos.x =  pos.x - rotation->w/20 ; 
        pos.y =  pos.y - rotation->h/20 ;
 
	SDL_SetColorKey(rotation,(SDL_SRCCOLORKEY|SDL_RLEACCEL|SDL_SRCALPHA), SDL_MapRGB(rotation->format, 255, 0, 255));
	SDL_BlitSurface(rotation, NULL, ecran, &pos);
        SDL_FreeSurface(rotation);
la bande noire est toujours là !
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 17h15   #19
LittleWhite
Responsable 2D/3D/Jeux


 
Avatar de LittleWhite
 
Homme Alexandre Laurent
Ingénieur développement logiciels
Inscription : mai 2008
Messages : 10 437
Détails du profil
Informations personnelles :
Nom : Homme Alexandre Laurent
Localisation : France

Informations professionnelles :
Activité : Ingénieur développement logiciels

Informations forums :
Inscription : mai 2008
Messages : 10 437
Points : 40 059
Points : 40 059
Enlevez les lignes de SDL_SetColorKey()
__________________
Vous souhaitez participer à la rubrique 2D / 3D / Jeux ? Contactez-moi
La rubrique a aussi un blog !

Ma page sur DVP
Mon Portfolio

Qui connaît l'erreur, connaît la solution.
LittleWhite est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/06/2012, 18h16   #20
hazaki
Futur Membre du Club
 
mouloud jean
Inscription : septembre 2010
Messages : 84
Détails du profil
Informations personnelles :
Nom : mouloud jean

Informations forums :
Inscription : septembre 2010
Messages : 84
Points : 16
Points : 16
Voilà c'est fait et maintenant il n'y pas de transparance avec le noir et le rose !
hazaki est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 04h04.


 
 
 
 
Partenaires

Hébergement Web