Jump to content
  • Advertisement
Sign in to follow this  
steven31dd

Directx 9 sprite class help

This topic is 3454 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I went through everything in my sprite.cpp, sprite.h (there is no reference to the main file yet) I keep getting these errors I know I'm missing something (I looked in my game coding complete book, and look up source references in cplusplus.com) I just can't place my finger on it, which I find sad since I'm good at classes.
------ Rebuild All started: Project: DirectX9 Window, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'DirectX9 Window', configuration 'Debug|Win32'
Compiling...
WinMain.cpp
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C2653: 'std' : is not a class or namespace name
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C2146: syntax error : missing ';' before identifier 'TextureFileName'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(39) : error C2653: 'std' : is not a class or namespace name
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(39) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(39) : error C2146: syntax error : missing ',' before identifier 'TextureFileName'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C2146: syntax error : missing ';' before identifier 'd3d'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C2377: 'LPDIRECT3D9' : redefinition; typedef cannot be overloaded with any other symbol
        c:\program files\microsoft directx sdk (november 2008)\include\d3d9.h(331) : see declaration of 'LPDIRECT3D9'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C2512: 'Sprite' : no appropriate default constructor available
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(109) : error C2440: '=' : cannot convert from 'IDirect3D9 *' to 'int'
        There is no context in which this conversion is possible
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(120) : error C2227: left of '->CreateDevice' must point to class/struct/union/generic type
        type is 'int'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(153) : error C2227: left of '->Release' must point to class/struct/union/generic type
        type is 'int'
Sprite.cpp
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C2653: 'std' : is not a class or namespace name
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C2146: syntax error : missing ';' before identifier 'TextureFileName'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(31) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(39) : error C2653: 'std' : is not a class or namespace name
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(39) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(39) : error C2146: syntax error : missing ',' before identifier 'TextureFileName'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(3) : error C2628: 'Sprite' followed by 'void' is illegal (did you forget a ';'?)
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(4) : error C2556: 'Sprite Sprite::Set_Size(int,int)' : overloaded function differs only by return type from 'void Sprite::Set_Size(int,int)'
        c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(35) : see declaration of 'Sprite::Set_Size'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(4) : error C2371: 'Sprite::Set_Size' : redefinition; different basic types
        c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(35) : see declaration of 'Sprite::Set_Size'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(5) : error C2065: 'Scale' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(5) : error C2228: left of '.x' must have class/struct/union
        type is ''unknown-type''
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(6) : error C2065: 'Scale' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(6) : error C2228: left of '.y' must have class/struct/union
        type is ''unknown-type''
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(29) : error C2146: syntax error : missing ',' before identifier 'TextureFileName'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(32) : error C2065: 'd3ddev' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(32) : error C2065: 'm_Sprite' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(34) : error C2065: 'd3ddev' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(35) : error C2065: 'TextureFileName' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(41) : error C2143: syntax error : missing ')' before ';'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(47) : error C2065: 'm_Sprite' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(47) : error C2059: syntax error : ')'
Generating Code...
Build log was saved at "file://c:\Documents and Settings\Steven\My Documents\Visual Studio 2008\Projects\DirectX9 Window\DirectX9 Window\Debug\BuildLog.htm"
DirectX9 Window - 43 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========

I'll keep checking for mistake(s). but I ask those willing to help take a look see for yourself. here is sprite.h
#ifndef _SPRITE_H
#define _SPRITE_H

#include <d3d9.h>
#include <d3dx9.h>
#include <string.h>


struct Vector2D
{
	int x;
	int y;
};

struct Box
{
	int x1;
	int y1;
	int x2;
	int y2;
};

class Sprite
{
public:
ID3DXSPRITE *m_Sprite;
Vector2D Size;
Vector2D Position;
Vector2D Velocity;
Box Bound;
const std::string TextureFileName;
int RedColorKey, GreenColorKey, BlueColorKey;


void Set_Size(int x, int y);
void Set_Position(int x, int y);
void Set_Velocity(int x, int y);
void Set_Bound(int x1, int y1, int x2, int y2);
void LoadSprite(const std::string TextureFileName, int RedColorKey, int GreenColorKey, int BlueColorKey);
}

#endif

here is sprite.cpp
#include "Sprite.h"

void Sprite::Set_Size(int x, int y)
{
Scale.x = x;
Scale.y = y;
}

void Sprite::Set_Position(int x, int y)
{
Position.x = x;
Position.y = y;
}

void Sprite::Set_Velocity(int x, int y)
{
Velocity.x = x;
Velocity.y = y;
}

void Sprite::Set_Bound(int x1, int y1, int x2, int y2)
{
Bound.x1 = x1;
Bound.y1 = y1;
Bound.x2 = x2;
Bound.y2 = y2;
}

void Sprite::LoadSprite(const string TextureFileName, int RedColorKey, int BlueColorKey, int GreenColorKey)
{

D3DXCreateSprite(d3ddev, &m_Sprite);

D3DXCreateTextureFromFileEx(d3ddev,
				  TextureFileName,
				  Size.x,
				  Size.y,
				  D3DX_DEFAULT,
				  NULL,
				  D3DFMT_A8R8G8B8,
				  D3DPOOL_MANAGED;
				  D3DX_DEFAULT,
				  D3DX_DEFAULT,
				  D3DCOLOR_XRGB(RedColorKey, GreenColorKey, BlueColorKey),
				  NULL,
				  NULL,
				  &m_Sprite);
}

I will be very appreciated to those who are willing to help

Share this post


Link to post
Share on other sites
Advertisement
Basically it looks like it's not finding they types that you declared. For example ID3DXSPRITE is not found. The std is not found because you have not delcared which namespace youre using, after #include <string> write
using namespace std;

P.S Is you code large? Maybe you can post it, I can try compiling it.

Share this post


Link to post
Share on other sites
yea... i tried that but I end up with 79 errors, so i left out
using namespace std;

I'm thinking of removing the string and just using heap memory with old char[].

ID3DXSPRITE, I don't understand how that not declared, it's right there in Sprite.h.

that's kinda why I'm confused.

Share this post


Link to post
Share on other sites
phew ok, now I'm down to 23 errors, yea i forgot to remove .h I was experiment with what mistakes i had made.

thx vanilla on that.


------ Rebuild All started: Project: DirectX9 Window, Configuration: Debug Win32 ------
Deleting intermediate and output files for project 'DirectX9 Window', configuration 'Debug|Win32'
Compiling...
WinMain.cpp
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C2146: syntax error : missing ';' before identifier 'd3d'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C2377: 'LPDIRECT3D9' : redefinition; typedef cannot be overloaded with any other symbol
c:\program files\microsoft directx sdk (november 2008)\include\d3d9.h(331) : see declaration of 'LPDIRECT3D9'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C2512: 'Sprite' : no appropriate default constructor available
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(109) : error C2440: '=' : cannot convert from 'IDirect3D9 *' to 'int'
There is no context in which this conversion is possible
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(120) : error C2227: left of '->CreateDevice' must point to class/struct/union/generic type
type is 'int'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\winmain.cpp(153) : error C2227: left of '->Release' must point to class/struct/union/generic type
type is 'int'
Sprite.cpp
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C2143: syntax error : missing ';' before '*'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(26) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(3) : error C2628: 'Sprite' followed by 'void' is illegal (did you forget a ';'?)
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(4) : error C2556: 'Sprite Sprite::Set_Size(int,int)' : overloaded function differs only by return type from 'void Sprite::Set_Size(int,int)'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(35) : see declaration of 'Sprite::Set_Size'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(4) : error C2371: 'Sprite::Set_Size' : redefinition; different basic types
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(35) : see declaration of 'Sprite::Set_Size'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(5) : error C2065: 'Scale' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(5) : error C2228: left of '.x' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(6) : error C2065: 'Scale' : undeclared identifier
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(6) : error C2228: left of '.y' must have class/struct/union
type is ''unknown-type''
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(29) : error C2146: syntax error : missing ',' before identifier 'TextureFileName'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.cpp(30) : error C2511: 'void Sprite::LoadSprite(const int)' : overloaded member function not found in 'Sprite'
c:\documents and settings\steven\my documents\visual studio 2008\projects\directx9 window\directx9 window\sprite.h(24) : see declaration of 'Sprite'
Generating Code...
Build log was saved at "file://c:\Documents and Settings\Steven\My Documents\Visual Studio 2008\Projects\DirectX9 Window\DirectX9 Window\Debug\BuildLog.htm"
DirectX9 Window - 23 error(s), 0 warning(s)
========== Rebuild All: 0 succeeded, 1 failed, 0 skipped ==========




edit: changed 29 errors to 23, and shown the errors.

Share this post


Link to post
Share on other sites
can you post the remaining errors? If they're about std, you can try moving
<string> and using namespace std; to be the forst things included (defore DX headers)

EDIT: Ok, can you post your winmain?

Share this post


Link to post
Share on other sites
here you go but, to give you a heads up, Sprite.h is declared but there is no reference to it object yet. <-- that may be most of my problems.



#include <windows.h>
#include <d3d9.h>
#include "Sprite.h"

// global declarations
LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3ddev;

// function prototypes
void initD3D(HWND hWnd);
void render_frame(void);
void cleanD3D(void);


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);


int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
HWND hWnd;
WNDCLASSEX wc;

ZeroMemory(&wc, sizeof(WNDCLASSEX));

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WindowProc;
wc.hInstance = hInstance;
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)COLOR_WINDOW;
wc.lpszClassName = "WindowClass";

RegisterClassEx(&wc);

hWnd = CreateWindowEx(NULL,
"WindowClass",
"Our First Direct3D Program",
WS_OVERLAPPEDWINDOW,
300, 300,
640, 480,
NULL,
NULL,
hInstance,
NULL);

ShowWindow(hWnd, nCmdShow);


initD3D(hWnd);


MSG msg;

while(TRUE)
{
DWORD starting_point = GetTickCount();

if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;

TranslateMessage(&msg);
DispatchMessage(&msg);
}

render_frame();

while ((GetTickCount() - starting_point) < 25);
}


cleanD3D();

return msg.wParam;
}


LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch(message)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
}

return DefWindowProc (hWnd, message, wParam, lParam);
}



void initD3D(HWND hWnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS d3dpp;

ZeroMemory(&d3dpp, sizeof(d3dpp));
d3dpp.Windowed = TRUE;
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow = hWnd;



d3d->CreateDevice(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp,
&d3ddev);

return;
}


void render_frame(void)
{

d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(80, 80, 255), 1.0f, 0);

d3ddev->BeginScene();


d3ddev->EndScene();

d3ddev->Present(NULL, NULL, NULL, NULL);

return;
}



void cleanD3D(void)
{
d3ddev->Release();
d3d->Release();

return;
}



Share this post


Link to post
Share on other sites
Quote:
Original post by steven31dd
here you go but, to give you a heads up, Sprite.h is declared but there is no reference to it object yet. <-- that may be most of my problems.

*** Source Snippet Removed ***


Step 1: change < > around d3d9 to "", lets ee if that does anything. <> are used mostly for system headers.

Share this post


Link to post
Share on other sites
no change in errors when using "", so eh.

wait, show me a basic sprite.h and sprite.cpp that you would make, maybe I can catch a mistake. I know judging by the errors it doesn't seem to like Direct3D sprite and my use of class functions.

Share this post


Link to post
Share on other sites
Ok, I'm basically compiling your code right now. Another mistake (quiet major) is that you forgot a semicolon after you Sprite class

class Sprite
{
...
};

I'll look for others

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!