Programming 2D Games

The official forum for "Programming 2D Games" the book by: Charles Kelly

It is currently Fri Feb 28, 2020 8:55 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Mar 23, 2016 10:48 pm 
Offline

Joined: Wed Nov 25, 2015 4:56 pm
Posts: 24
So far my game runs fine in debug version but when I run a release version it plays sound but does not display any graphics.

I have created audio and graphic folders within my game folder just as in your engine and I move the .exe from the release folder to the game folder. I've even tried writing the full path to my graphics folder in the code and rebuilding but still the same.

What am I doing wrong:(

Thanks


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 24, 2016 5:34 pm 
Offline

Joined: Wed Nov 25, 2015 4:56 pm
Posts: 24
Here's an update to my problem to try and help clarify.

I thought that maybe I hadn't setup my release confiration correctly so I created a new project and loaded your space game in and set everything up as in my game (note: I'm using VS2008 so I have to use the #pragma comment (lib,"d3d9.lib"), #pragma comment (lib,"d3dx9.lib"), #pragma comment (lib,"winmm.lib"), #pragma comment (lib,"xinput.lib") in the graphics header).

I ran a debug version and it was fine. I then ran a release version, moved the file to the parent folder and that ran ok to.


So that means I've must have a problem with my code, even though everything runs fine in debug version. I even thought maybe there is something wrong with my images so I used one of yours but still the same result. Please see below:

This is from the debug version:

Attachment:
Debug.jpg



And this is from the Release version:

Attachment:
Release.jpg



Here are all the sniplets of code from my project relating to drawing the images:

Code:
// From Graphics header class
=====================================================================

#include <d3d9.h>
#include <d3dx9.h>
#include <D3dx9core.h>
#include "GameConstants.h"
#include "GameError.h"

#pragma comment (lib,"d3d9.lib")
#pragma comment (lib,"d3dx9.lib")
#pragma comment (lib,"winmm.lib")
#pragma comment (lib,"xinput.lib")

~

struct SpriteInformation
{
   LPDIRECT3DTEXTURE9      Texture;
   RECT                    Frame;
       float                    SpritePositionX;
   float                    SpritePositionY;
   float                    SpriteWidth;
   float                    SpriteHeight;
   bool                    FlipHorizontal;
       bool                    FlipVertical;
       float                    Scale;
   float                    Angle;
   COLOUR_ARGB         Filter;
};

~

LPDIRECT3DTEXTURE9             LogoTexture,
                               IntroTexture,
                               MenuTexture,
            LevelMenuTexture,
            BottomMapTilesTexture,
            SpritesTexture,
            EffectsTexture,
            TopMapTilesTexture,
            UITexture,
            LevelDesignTexture;

LPCSTR                         LogoTextureFilename,
                                IntroTextureFilename,
                                MenuTextureFilename,
                                LevelMenuTextureFilename,
                                BottomMapTilesTextureFilename,
                                SpritesTextureFilename,
                                EffectsTextureFilename,
                                TopMapTilesTextureFilename,
                                UITextureFilename,
                                LevelDesignTextureFilename;

RECT                           GameArea;

int                            NumberOfLogoItems,
            NumberOfIntroItems,
                                NumberOfMenuItems,
                                NumberOfLevelMenuItems,
                                NumberOfBottomMapTiles,
                                NumberOfSprites,
                                NumberOfEffects,
                                NumberOfTopMapItems,
                                NumberOfUI,
                                NumberOfLevelDesignItems;

// From Sprite header class
=====================================================================


protected:
   int         TotalRows;
   int         TotalColumns;
   int         CurrentRow;
   int         CurrentColumn;
       bool         FlipHorizontal;
       bool         FlipVertical;
       float         Scale;
   float         Angle;
       float                   OpacityValue;
   bool         SpriteInitialised;
       int                     FrameBorderWidth;
       bool                    GameWindowSprite;
   Sequence      CurrentSequence;

       D3DXVECTOR2      SpriteWidthAndHeight;
       D3DXVECTOR3             SpriteHandle;
       D3DXVECTOR3      SpritePosition;
       LPDIRECT3DTEXTURE9   Texture;
       RECT                 Frame;
   bool                           ReadyForNextSequence;   
       COLOUR_ARGB      Filter;


// From Game Engine class(Initialise member function)
=====================================================================


Graphics = new GameGraphics();
   Graphics->Initialise(hwnd);



// From my game class file

   Graphics->NumberOfLogoItems = 1;
        Graphics->LogoTextureFilename = "Images\\Logo.jpg";
        Graphics->NumberOfIntroItems = 1;                           
        Graphics->IntroTextureFilename = "Images\\Intro.png";
       
        if (!Graphics->LoadTexture(STATE_INTRO))
            PostQuitMessage(0);
       
        LogoItem = new LogoItems[Graphics->NumberOfLogoItems];
        IntroItem = new IntroItems[Graphics->NumberOfIntroItems];
      
        LogoItem[0].Initialise(Graphics->LogoTexture, Graphics->LogoTextureFilename, 0, 0, 0);


// From Sprite Class
=====================================================================

void Sprite::Initialise(LPDIRECT3DTEXTURE9 Tex, LPCSTR Filename, int FrameSizeX, int FrameSizeY, int Border)
{
   D3DXIMAGE_INFO FileInfo;

   Texture = Tex;

   D3DXGetImageInfoFromFile(Filename, &FileInfo);

    if (FrameSizeX == 0)
        SpriteWidthAndHeight.x = (float)FileInfo.Width;
    else
        SpriteWidthAndHeight.x =  (float)FrameSizeX;
   
    if (FrameSizeY == 0)
        SpriteWidthAndHeight.y = (float)FileInfo.Height;
    else
        SpriteWidthAndHeight.y =  (float)FrameSizeY;
   

   if (FrameSizeX == 0)
      TotalColumns = 1;
   else
      TotalColumns = (int)FileInfo.Width / FrameSizeX;

   if (FrameSizeY == 0)
      TotalRows = 1;
   else
      TotalRows = (int)FileInfo.Height / FrameSizeY;
   
    FrameBorderWidth = Border;

   SpriteHandle.x = 0;
   SpriteHandle.y = 0;


   SpritePosition.x = 0;
   SpritePosition.y = 0;
   SpritePosition.z = 0;

   Frame.left = 0;
   Frame.top = 0;
   if (FrameSizeX == 0)
      Frame.right = FileInfo.Width;
   else
      Frame.right = FrameSizeX;
   if (FrameSizeY == 0)
      Frame.bottom = FileInfo.Height;
   else
      Frame.bottom = FrameSizeY;

   Scale = 1.0;
   Angle = 0;     // ROTATE_90_DEGREES
   Filter = D3DCOLOR_ARGB(255, 255, 255, 255);

   FlipHorizontal = false;
   FlipVertical = false;

    ReadyForNextSequence = true;
   SpriteInitialised = true;

}


// From my game Class
=====================================================================


for (i = 0 ; i < Graphics->NumberOfLogoItems ; i++)
{
   Graphics->DrawSprite(LogoItem[i].GetSpriteInfo());
        LogoItem[i].UpdateFrame();
}


// From Graphics Class
=====================================================================


bool GameGraphics::DrawSprite(SpriteInformation SI)
{
   D3DXMATRIX   Matrix;
   D3DXVECTOR2 SpriteCenter;
   D3DXVECTOR2 Translate;
   D3DXVECTOR2 Scaling(SI.Scale, SI.Scale);
   
   SpriteCenter.x = (SI.SpriteWidth * SI.Scale) / 2;
   SpriteCenter.y = (SI.SpriteHeight * SI.Scale) / 2;

    //Translate.x = SI.SpritePositionX + ((SI.SpriteWidth - (SI.SpriteWidth * SI.Scale)) / 2);
   //Translate.y = SI.SpritePositionY + ((SI.SpriteHeight - (SI.SpriteHeight * SI.Scale)) / 2);
   Translate.x = SI.SpritePositionX;
   Translate.y = SI.SpritePositionY;

   if (SI.FlipHorizontal) 
    {
        Scaling.x *= -1;           
        SpriteCenter.x -= (SI.SpriteWidth * SI.Scale);
        Translate.x += (SI.SpriteHeight * SI.Scale);
    }
   if (SI.FlipVertical)   
    {
        Scaling.y *= -1;           
      SpriteCenter.y -= (SI.SpriteWidth * SI.Scale);
        Translate.y += (SI.SpriteHeight * SI.Scale);
    }
   
    D3DXMatrixTransformation2D(&Matrix, NULL, 0.0f, &Scaling, &SpriteCenter, SI.Angle,   &Translate);           

    Sprite->SetTransform(&Matrix);

   Sprite->Draw(SI.Texture, &SI.Frame, NULL, NULL, SI.Filter);
   

   return true;
}


You do not have the required permissions to view the files attached to this post.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 24, 2016 8:38 pm 
Offline

Joined: Wed Nov 25, 2015 4:56 pm
Posts: 24
OK I've have an answer to this problem now and this may be useful to anyone else who gets it.

I simply just created a new project and copied the files in and re-built it. All works perfect. Seems my project just got corrupted somewhere :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group