IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

XNA/Monogame Discussion :

Coordonnés de la fenêtre XNA


Sujet :

XNA/Monogame

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 11
    Points : 5
    Points
    5
    Par défaut Coordonnés de la fenêtre XNA
    Bonjour,

    J'ai un petit soucis, je m'explique.
    Je veux utiliser les coordonnés de ma souris lorsque je clic dans ma fenêtre, j'utilise alors :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    MouseState MState;
    MStat.X
    Mon problème est que le MStat prend pour repère mon écran ( 0,0 en haut à gauche) alors que je voudrais utiliser ma fenètre XNA.

    Y'a t-il un moyen de récupérer les coordonnés de la fenètre XNA ou de définir celle ci comme repère ?

    Merci d'avance, désolé si je ne suis pas assez clair.
    Cordialement

  2. #2
    Membre habitué
    Inscrit en
    Avril 2011
    Messages
    59
    Détails du profil
    Informations forums :
    Inscription : Avril 2011
    Messages : 59
    Points : 154
    Points
    154
    Par défaut
    Remplis tu le membre statique Microsoft.Xna.Framework.Input.Mouse.WindowHandle avec le Handle de ta GameWindow?

    Faut aussi bien sur utiliser Microsoft.Xna.Framework.Input.Mouse.GetState() pour récupérer l'état de la souris.

  3. #3
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 11
    Points : 5
    Points
    5
    Par défaut
    Merci pour ta réponse, je vais regarder de ce côté là.

    PS : J'utilise bien
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    MStat = Mouse.GetState();
    Mais je viens de me rendre compte que les coordonnés de ma souris à savoir,
    Renvoient des valeurs complètement différente à chaque lancement du jeu ...

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 11
    Points : 5
    Points
    5
    Par défaut
    Up

  5. #5
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2010
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 36
    Points : 20
    Points
    20
    Par défaut
    Dans la boucle Update met ton MStat = Mouse.GetState();
    après tu peux mettre une condition pour voir si ont clic sur la souris, genre

    if(MStat.LeftButton == ButtonState.Pressed)
    {
    Vector2 MaCoordonner = new Vector2(MStat.X, MStat.Y);
    }

    La coordonner 0,0 est en principe celle de ta fenêtre XNA.

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 11
    Points : 5
    Points
    5
    Par défaut
    Oui c'est bien ce que je fait. Mais les coordonnées que me renvoi MStat ne correspondes pas du tout à ma fenêtre.

  7. #7
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2010
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 36
    Points : 20
    Points
    20
    Par défaut
    J'arrive pas à comprendre pourquoi ça te donne ce résultat. Pourrais tu mettre ton code au complet, s'il n'est pas trop volumineux ou s'il ne contient pas du super code que tu voudrais garder top-secret. Avec un code complet, peut-être pourra t'ont voir s'il n'y aurais pas une petite erreur de frappe.

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 11
    Points : 5
    Points
    5
    Par défaut
    CogMR.cs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Media;
    using MSC_2010_BREIDENSTEIN;
     
    namespace CogMR
    {
        /// <summary>
        /// This is the main type for your game
        /// </summary>
        public class CogMR : Microsoft.Xna.Framework.Game
        {
            GraphicsDeviceManager graphics;
            SpriteBatch spriteBatch;
            Function Funct;
            SingleClick FunctClick;
            MouseState MStat;
     
            //-----------------------------------------------------Déclarations-----------------------------------------------//
            //Rectangle de sélection dans le fichier du sprite (où est l'image à afficher)
            Rectangle srcImg, srcImgLvl, srcSeparateur, srcFleche, srcSym, srcFond, srcChrono;
            // FR : Bouttons pour les transformations
            Button btnFlecheD, btnFlecheG, btnSymH, btnSymV;
            //Objet texture qui sera chargé
            Texture2D sprite, spriteModif, separateur, fond, chrono;
            SpriteFont ChronoTxt;
            //Rectangle de destination : où l'image sera affichée sur l'écran et sa taille
            Rectangle dstOrigine, dstSeparateur, dstModif, dstFond, dstChrono;
            //Si on veut faire tourner le sprite
            float rotation = 0;
            //Symétries
            SpriteEffects Transformation = SpriteEffects.None;
            //Résolution d'écran
            public static int SCREEN_WIDTH = 800;
            public static int SCREEN_HEIGHT = 600;
            //Etat du Jeu (switch, voir Update())
            int iEtat = 1, iText;
            //Etat du clavier
            KeyboardState KState;
            //Compteurs de transformations
            public int iRotatRight, iRotatLeft, iSymVer, iSymHor;
            //Déclaration du stream 
            Stream sImg; //sSave;
            Stream sImgLvl;
            msc_data ConfigMR, Level;
     
            //Extension des images
            string stExtension = ".png";
            //Nom de l'image à charger
            string stLoadImg = ".\\Images\\";
            string stLoadLevel = ".\\Images\\Level\\";
     
            float fTime = 0;
            public int iLvl = 1;
            //----------------------------------------------------------------------------------------------------------------//
     
     
     
            //-----------------------------------------------------Fonctions--------------------------------------------------//
     
     
     
            //----------------------------------------------------------------------------------------------------------------//
     
            public CogMR()
            {
                graphics = new GraphicsDeviceManager(this);
                Content.RootDirectory = "Content";
     
                //Résolutaion d'écran
                graphics.PreferredBackBufferWidth = SCREEN_WIDTH;
                graphics.PreferredBackBufferHeight = SCREEN_HEIGHT;
     
                //Afficher la souris
                IsMouseVisible = true;
     
                Window.Title = "Jeu des rotations";
     
                //CogMR_Login CogMR_Login = new CogMR_Login();
                //CogMR_Login.ShowDialog();
     
            }
     
            /// <summary>
            /// Allows the game to perform any initialization it needs to before starting to run.
            /// This is where it can query for any required services and load any non-graphic
            /// related content.  Calling base.Initialize will enumerate through any components
            /// and initialize them as well.
            /// </summary>
            protected override void Initialize()
            {
                // TODO: Add your initialization logic here
     
                //Ouverture fichier *.csv
                ConfigMR = new msc_data(@".\Fichiers CSV\", "ConfigMR.csv");
                Level = new msc_data(@".\Fichiers CSV\", "Level.csv");
     
                //Rectangle dans lequel sera l'image
                srcImg = new Rectangle(0, 0, 150, 150);                                         //Rectangle pour le cactus
                srcImgLvl = new Rectangle(0, 0, 50,50);
                srcSeparateur = new Rectangle(0, 0, 2, 600);                                //Rectangle pour le séparateur
                srcFleche = new Rectangle(0, 0, 50, 50);                                   //Rectangle pour les flêches
                srcSym = new Rectangle(0, 0, 50, 50);                                       //Rectangle pour les symétries
                srcFond = new Rectangle(0, 0, 800, 600);
                srcChrono = new Rectangle(0, 0, 90, 100);
     
                // FR : Placement de l'image à modifier
                Point MilieuR = new Point((SCREEN_WIDTH * 3 / 4), (SCREEN_HEIGHT / 2));
                Point CoinR = new Point(MilieuR.X - (srcImg.Width / 2), MilieuR.Y - (srcImg.Height / 2));
     
                // FR : Placement de l'image d'origine
                Point MilieuL = new Point((SCREEN_WIDTH * 3 / 8), (SCREEN_HEIGHT / 2));
                Point CoinL = new Point(MilieuL.X - (srcImg.Width / 2), MilieuL.Y - (srcImg.Height / 2));
     
                //Lieu d'aparition de l'image
                dstSeparateur = new Rectangle(399, 0, 2, 600);
                dstOrigine = new Rectangle(CoinL.X, CoinL.Y, srcImgLvl.Width, srcImgLvl.Height);
                dstModif = new Rectangle(CoinR.X, CoinR.Y, srcImg.Width, srcImg.Height);
                dstFond = new Rectangle(0, 0, srcFond.Width, srcFond.Height);
                dstChrono = new Rectangle(55, 10, srcChrono.Width, srcChrono.Height);
     
                btnFlecheD = new Button(new Vector2(40, 240));
                btnFlecheG = new Button(new Vector2(110, 240));
                btnSymH = new Button(new Vector2(40, 310));
                btnSymV = new Button(new Vector2(110, 310));
     
                Funct = new Function();
                FunctClick = new SingleClick();
                base.Initialize();
            }
     
            /// <summary>
            /// LoadContent will be called once per game and is the place to load
            /// all of your content.
            /// </summary>
            protected override void LoadContent()
            {
                // Create a new SpriteBatch, which can be used to draw textures.
                spriteBatch = new SpriteBatch(GraphicsDevice);
     
                // TODO: use this.Content to load your game content here
     
                //Chargement de l'image de jeu : Effectuer une recherche du nom de l'image dans un fichier *.csv pour la charger dynamiquement
                stLoadImg += String.Concat(Funct.LoadLvl(Level, iLvl), stExtension);
                sImg = File.OpenRead(@stLoadImg);
                spriteModif = Texture2D.FromStream(GraphicsDevice, sImg);
     
                stLoadLevel += String.Concat(Funct.LoadLvl(Level, iLvl), stExtension);
                sImgLvl = File.OpenRead(@stLoadLevel);
                sprite = Texture2D.FromStream(GraphicsDevice, sImgLvl);
     
                fond = Content.Load<Texture2D>("fond");
                separateur = Content.Load<Texture2D>("separateur");
     
                /*Stream sImg2;
                sImg2 = File.OpenRead(@".\Images\flecheD.png");
                flecheD.Texture = Texture2D.FromStream(GraphicsDevice, sImg2);*/
     
                btnFlecheD.Texture = Content.Load<Texture2D>("flecheD");
                btnFlecheG.Texture = Content.Load<Texture2D>("flecheG");
                btnSymH.Texture = Content.Load<Texture2D>("SymH");
                btnSymV.Texture = Content.Load<Texture2D>("SymV");
     
                ChronoTxt = Content.Load<SpriteFont>("SpriteFont");
                chrono = Content.Load<Texture2D>("chrono");
     
     
            }
     
            /// <summary>
            /// UnloadContent will be called once per game and is the place to unload
            /// all content.
            /// </summary>
            protected override void UnloadContent()
            {
                // TODO: Unload any non ContentManager content here
     
                if (File.Exists(@"Images\Temp\1.jpg") == true)
                {
                    File.Delete(@"Images\Temp\1.jpg");
                }
                Funct.SaveRLeft(ConfigMR, Convert.ToString(iRotatLeft));
                Funct.SaveRRight(ConfigMR, Convert.ToString(iRotatRight));
                Funct.SaveSHorizontally(ConfigMR, Convert.ToString(iSymHor));
                Funct.SaveSVertically(ConfigMR, Convert.ToString(iSymVer));
                Funct.SaveTime(ConfigMR, Convert.ToString(fTime));
     
            }
     
            /// <summary>
            /// Allows the game to run logic such as updating the world,
            /// checking for collisions, gathering input, and playing audio.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
            protected override void Update(GameTime gameTime)
            {
                // Allows the game to exit
                KState = Keyboard.GetState();
                MStat = Mouse.GetState();
     
                if (KState.IsKeyDown(Keys.Escape)) this.Exit();
                //Funct.SaveSprite(sprite, 0, SpriteEffects.None, spriteBatch, GraphicsDevice);
     
                int i;
                i = Funct.SolvRotaL(Level, iLvl);
     
                // TODO: Add your update logic here
                switch (iEtat)
                {
                    case 1:
                        if (FunctClick.Click(MStat, btnFlecheD))
                        {
                            iEtat = 2;
                        }
                        if (FunctClick.Click(MStat, btnFlecheG))
                        {
                            iEtat = 3;
                        }
                        if (FunctClick.Click(MStat, btnSymH))
                        {
                            iEtat = 4;
                        }
                        if (FunctClick.Click(MStat, btnSymV))
                        {
                            iEtat = 5;
                        }
                        break;
     
                    case 2:    //Rotation vers la droite
                        rotation += (float)((Math.PI) / 2);
                        iRotatRight++;
                        iEtat = 1;
                        break;
     
                    case 3:    //Rotation vers la gauche
                        rotation += (float)-((Math.PI) / 2);
                        iRotatLeft++;
                        iEtat = 1;
                        break;
     
                    case 4:     //Sym Horizontally
                        Transformation = SpriteEffects.FlipVertically;
                        iSymVer++;
                        //spriteModif = Funct.SaveSprite(spriteModif, 0, Transformation, spriteBatch, ConfigMR, GraphicsDevice);
                        iEtat = 1;
                        break;
     
                    case 5:     //Sym Vertically
                        Transformation = SpriteEffects.FlipHorizontally;
                        iSymHor++;
                        //spriteModif = Funct.SaveSprite(spriteModif, 0, Transformation, spriteBatch, ConfigMR, GraphicsDevice);
                        iEtat = 1;
                        break;
                }
                iText++;
                base.Update(gameTime);
            }
     
            /// <summary>
            /// This is called when the game should draw itself.
            /// </summary>
            /// <param name="gameTime">Provides a snapshot of timing values.</param>
            protected override void Draw(GameTime gameTime)
            {
                //GraphicsDevice.Clear(Color.CornflowerBlue);
                //fTime += gameTime.ElapsedGameTime.Seconds;
                fTime += gameTime.TotalGameTime.Seconds;
                // TODO: Add your drawing code here
     
                spriteBatch.Begin();
                spriteBatch.Draw(fond, dstFond, srcFond, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
                spriteBatch.Draw(chrono, dstChrono, srcChrono, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
                Funct.DrawChrono(ChronoTxt, Convert.ToString(iText), spriteBatch);
                spriteBatch.Draw(separateur, dstSeparateur, srcSeparateur, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
     
                btnFlecheD.Draw(spriteBatch);
                btnFlecheG.Draw(spriteBatch);
                btnSymH.Draw(spriteBatch);
                btnSymV.Draw(spriteBatch);
     
                spriteBatch.Draw(sprite, dstOrigine, srcImgLvl, Color.White, 0, Vector2.Zero, SpriteEffects.None, 1.0f);
                spriteBatch.Draw(spriteModif, dstModif, srcImg, Color.White, rotation, Vector2.Zero, Transformation, 1.0f);
     
     
     
                spriteBatch.End();
     
                base.Draw(gameTime);
            }
        }
    }
    SingleClick.cs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework.Input;
     
    namespace CogMR
    {
        class SingleClick
        {
            bool bGeneralClick = false;
     
     
            public bool Click(MouseState MStat, Button btn)
            {
                bool bRet = false;
                if (MStat.LeftButton == ButtonState.Pressed)
                {
                    bGeneralClick = true;
                    bRet = false;
                }
                if (MStat.LeftButton == ButtonState.Released && bGeneralClick == true)
                {
                    bGeneralClick = false;
                    if ((MStat.X > btn.Position.X) && (MStat.X < btn.Position.X + btn.Texture.Width) && (MStat.Y > btn.Position.Y) && (MStat.Y < btn.Position.Y + btn.Texture.Height))
                        bRet = true;
                    else
                        bRet = false;
                }
                return bRet;
            }
        }
    }
    Fonction.cs
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Media;
    using MSC_2010_BREIDENSTEIN;
     
    namespace CogMR
    {
        public class Function : Microsoft.Xna.Framework.Game
        {
            //-----------------------------------------------------Déclarations-----------------------------------------------//
     
     
     
            //----------------------------------------------------------------------------------------------------------------//
     
            //-----------------------------------------------------Fonctions--------------------------------------------------//
     
            // FR : Sauvegarde du temps de jeu (?)
            public void SaveTime(msc_data ConfigMR, string Time)
            {
                ConfigMR.WriteCell(1, 3, Time);
                ConfigMR.FinalizeFile();
            }
     
            // FR : Sauvegarde des manipultions effectuées
            public void SaveRLeft(msc_data ConfigMR, string stInfo)
            {
                ConfigMR.WriteCell(1, 4, stInfo);
                ConfigMR.FinalizeFile();
            }
            public void SaveRRight(msc_data ConfigMR, string stInfo)
            {
                ConfigMR.WriteCell(1, 5, stInfo);
                ConfigMR.FinalizeFile();
            }
            public void SaveSHorizontally(msc_data ConfigMR, string stInfo)
            {
                ConfigMR.WriteCell(1, 6, stInfo);
                ConfigMR.FinalizeFile();
            }
            public void SaveSVertically(msc_data ConfigMR, string stInfo)
            {
                ConfigMR.WriteCell(1, 7, stInfo);
                ConfigMR.FinalizeFile();
            }
     
            // FR : Affichage du sprite
            public void DrawSprite(Texture2D sprite, Rectangle dst, Rectangle src, float rotation, SpriteEffects Flip, SpriteBatch spriteBatch)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(sprite, dst, src, Color.White, rotation, Vector2.Zero, Flip, 1.0f);
                spriteBatch.End();
            }
     
            // FR : Redimentionnement du Rectangle Source (src...)
            public void Redimension(Rectangle srcImg, Texture2D spriteModif)
            {
                srcImg.Height = spriteModif.Height;
                srcImg.Width = spriteModif.Width;
            }
     
            // FR : Fonction permettant de charger le niveau
            public string LoadLvl(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToString((uint)iLvl, 0);
            }
     
            // FR : Fonction pour résoudre le niveau
            public int SolvRotaL(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToInt((uint)iLvl, 4);
            }
     
            public int SolvRotaR(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToInt((uint)iLvl, 5);
            }
     
            public int SolvSymH(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToInt((uint)iLvl, 6);
            }
     
            public int SolvSymV(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToInt((uint)iLvl, 7);
            }
     
            // FR : Fonction permettant d'obtenir les dimensions de l'image du niveau
            public int WidthLvl(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToInt((uint)iLvl, 2);
            }
     
            public int HeighLvl(msc_data CogMR, int iLvl)
            {
                return CogMR.ReadCellToInt((uint)iLvl, 3);
            }
     
            // FR : Permet la sauvegarde d'un sprite (Texture2D) en fichier *.png
            public Texture2D SaveSprite(Texture2D sprite, float rotation, SpriteEffects Flip, SpriteBatch spriteBatch, msc_data ConfigMR, int iLvl, GraphicsDevice GraphicsDevice)
            {
                //SpriteBatch spriteBatch = new SpriteBatch(GraphicsDevice);
     
                int width = sprite.Width;
                int height = sprite.Height;
                string ImgLvl;
                Stream sImg;
     
                RenderTarget2D renderTarget = new RenderTarget2D(GraphicsDevice, width, height, false, SurfaceFormat.Color, DepthFormat.None, 0, RenderTargetUsage.PreserveContents);
                GraphicsDevice.SetRenderTarget(renderTarget);
                Rectangle DestRect = new Rectangle(0, 0, width, height);
                spriteBatch.Begin();
                spriteBatch.Draw(sprite, DestRect, null, Color.White, rotation, Vector2.Zero, Flip, 0);
                spriteBatch.End();
                GraphicsDevice.SetRenderTarget(null);
     
                ImgLvl = "Images\\Temp\\" + LoadLvl(ConfigMR, iLvl) + ".jpg";
     
                using (Stream stream = File.Create(@ImgLvl))
                {
                    renderTarget.SaveAsPng(stream, width, height);
                }
     
                sImg = File.OpenRead(@ImgLvl);
                sprite = Texture2D.FromStream(GraphicsDevice, sImg);
     
                return sprite;
            }
     
            // FR : Afficher du texte
            public void DrawChrono(SpriteFont Chrono, String Texte, SpriteBatch spriteBatch)
            {
                spriteBatch.DrawString(Chrono, Texte, new Vector2(65, 55), Color.White);
            }
     
            // FR : Copie du sprite dans un sprite temporaire pour traitement des symétries
            public void TempSprite(SpriteBatch Sprite, SpriteBatch SpriteTemp)
            {
                if (SpriteTemp.Equals(Sprite) != true)
                {
                    Sprite = SpriteTemp;
                }
                else
                    SpriteTemp = Sprite;
            }
     
            //----------------------------------------------------------------------------------------------------------------//
     
        }
    }
    Normalement avec sa y'a tout ce qu'il faut.
    Désolé si sa fait beaucoup, au pire je peux fournir mon projet sous XNA 4

    Edit : Au niveau des noms des variables c'est du provisoire, je mettrais de l'ordre plus tard

  9. #9
    Membre à l'essai
    Profil pro
    Inscrit en
    Août 2010
    Messages
    36
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2010
    Messages : 36
    Points : 20
    Points
    20
    Par défaut
    Je ne suis pas un expert, mais j'arrive à me débrouiller un peu. J'ai regarder et après un bon bout de temps, j'arrive à saisir ton code sauf que je ne vois pas pourquoi tu as cette erreur. Si tu veux, envois moi ton projet et je testerais voir.

    frenchwolf88@gmail.com

  10. #10
    Futur Membre du Club
    Profil pro
    Inscrit en
    Mars 2011
    Messages
    11
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mars 2011
    Messages : 11
    Points : 5
    Points
    5
    Par défaut
    Voilà je t'ai envoyé sa


    Edit : Up

  11. #11
    Membre expert

    Homme Profil pro
    Développeur de jeux vidéo
    Inscrit en
    Février 2006
    Messages
    1 031
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Nord (Nord Pas de Calais)

    Informations professionnelles :
    Activité : Développeur de jeux vidéo
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Février 2006
    Messages : 1 031
    Points : 3 092
    Points
    3 092
    Par défaut
    Peux tu reproduire ton problème sur un projet vierge ?

    -Si oui : fais le nous parvenir
    -Si non : commentes ton code jusqu'à trouver ce qui pose problème
    Suivez le développement de Chibis Bomba
    twitter : https://twitter.com/MoD_DiB
    DevBlog : http://moddib.blogspot.fr/

  12. #12
    Membre averti Avatar de yodaime
    Profil pro
    Développeur informatique
    Inscrit en
    Avril 2006
    Messages
    282
    Détails du profil
    Informations personnelles :
    Âge : 38
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique

    Informations forums :
    Inscription : Avril 2006
    Messages : 282
    Points : 340
    Points
    340
    Par défaut
    Voila ce que j'ai trouver sur le site MSDN :

    MouseState.X Propriété :

    Si la souris est à gauche de la zone cliente (portion interne de la fenêtre de jeu, à l'exclusion des bordures), la coordonnée renvoyée est négative. Si la souris est à droite de la zone cliente, la coordonnée renvoyée est supérieure à la largeur de la zone cliente de la fenêtre.

    MouseState.Y Propriété :

    Si la souris est au-dessus de la zone cliente (portion interne de la fenêtre de jeu, à l'exclusion des bordures), la coordonnée renvoyée est négative. Si la souris est au-dessous de la zone cliente, la coordonnée renvoyée est supérieure à la hauteur de la zone cliente de la fenêtre.

Discussions similaires

  1. problème d'affichage fenêtre sur une fenêtre XNA
    Par dark poulpo dans le forum C#
    Réponses: 2
    Dernier message: 03/02/2012, 09h22
  2. [Débutant] Coordonnées de la fenêtre active
    Par bambou015 dans le forum MATLAB
    Réponses: 1
    Dernier message: 21/12/2010, 17h13
  3. Problème de composant WPF qui passe sous une fenêtre XNA
    Par Tod_sd dans le forum Windows Presentation Foundation
    Réponses: 2
    Dernier message: 20/05/2009, 10h46
  4. Coordonnées dans la fenêtre
    Par babyboy dans le forum WinDev
    Réponses: 1
    Dernier message: 29/01/2006, 10h01
  5. coordonnées d'une fenêtre avec window.open
    Par neecolas dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 25/05/2005, 09h08

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo