• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
PuReInSaNe

Bug: Sprite is not drawn correctly

7 posts in this topic

[attachment=13273:bug.png]

 


Bug that happens: the tiles are drawn 49x50 or 48x50 instead of 48x48. On the right side it's the actual texture which I attached, the left side is the bug I got from the code below.

 

Posted about this some time before, happend to me again somehow.
This time I made a new project and made an easy main loop so I don't have to post my whole game.

 

Please help me to fix it!

 

#ifndef _WINMAIN_H
#define _WINMAIN_H 1	

#include <windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <dinput.h>

using namespace std;

// include the Direct3D Library file
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#pragma comment (lib, "dinput8.lib")
#pragma comment (lib, "dxguid.lib")

#endif


HINSTANCE g_hInstance;
HWND g_hWnd;
HICON hMyIcon;
int width = 1056;
int height = 768;

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

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
	g_hInstance = hInstance;

	WNDCLASSEX wc;
	wc.cbSize = sizeof(WNDCLASSEX); 

	//fill the struct with info
	wc.style		 = CS_HREDRAW | CS_VREDRAW;
	wc.lpfnWndProc   = (WNDPROC)WinProc;
	wc.cbClsExtra	 = 0;
	wc.cbWndExtra	 = 0;
	wc.hInstance	 = hInstance;
	wc.hbrBackground = NULL;
	wc.lpszMenuName  = NULL;
	wc.lpszClassName = "winmain";
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	hMyIcon = LoadIcon(NULL, MAKEINTRESOURCE(IDI_WINLOGO));
	wc.hIconSm = hMyIcon;
	wc.hIcon = hMyIcon;

	RegisterClassEx(&wc); // calculate the size of the client area 
	HWND window;	
	RECT wr = {0, 0, width, height}; // set the size, but not the position 
	AdjustWindowRect(&wr, WS_OVERLAPPEDWINDOW, TRUE); // adjust the size
	window = CreateWindowEx( 0,
	   "winmain",								 //window class
	   "test",								 //title bar
      WS_EX_TOPMOST|WS_POPUP|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS|WS_VISIBLE, 
	   100, 100,											 //x,y coordinate 
	   wr.right - wr.left, // width of the window 
	   wr.bottom - wr.top, // height of the window
	   0,											 //parent window
	   0,											 //menu
	   g_hInstance,									  //application instance
	   0);	
	//display the window


	ShowWindow(g_hWnd, SW_SHOW);
	UpdateWindow(g_hWnd);
	LPDIRECT3D9 p_d3d;
	LPDIRECT3DDEVICE9 p_device;
	p_d3d = NULL;
	p_device = NULL;
	p_d3d = Direct3DCreate9(D3D_SDK_VERSION);
	if (p_d3d == NULL) {
		return 0;
	}
	//get system desktop color depth
	D3DDISPLAYMODE dm;
	p_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &dm);

	D3DPRESENT_PARAMETERS PresentParams;

	ZeroMemory( &PresentParams, sizeof(PresentParams) );
	PresentParams.Windowed = TRUE;
	PresentParams.SwapEffect = D3DSWAPEFFECT_DISCARD; //effizienteste methode
	PresentParams.hDeviceWindow = window;    // set the window to be used by Direct3D
	PresentParams.BackBufferFormat = D3DFMT_X8R8G8B8;    // set the back buffer format to 32-bit
	PresentParams.BackBufferWidth = width;    // set the width of the buffer
	PresentParams.BackBufferHeight = height;    // set the height of the buffer
	PresentParams.BackBufferCount = 1;

		//create Direct3D device
		p_d3d->CreateDevice(
			D3DADAPTER_DEFAULT,
			D3DDEVTYPE_HAL,
			window,
			D3DCREATE_HARDWARE_VERTEXPROCESSING,
			&PresentParams,
			&p_device);
		p_device->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,0), 1.0f, 0);

//Create sprite
		
		IDirect3DTexture9* texture;
		ID3DXSprite*		sprite;				// The sprite instance
		D3DXIMAGE_INFO info;
		//standard Windows return value
		HRESULT result;
		//create the new texture by loading a bitmap image file
		result = D3DXGetImageInfoFromFile("textures.png",&info);
		if (result != D3D_OK) 	{
		MessageBox(0, "Texture file not found", "Error!", 0);
			texture = NULL;
		}
		result = D3DXCreateTextureFromFileEx( 
			p_device, //Direct3D device object
			"textures.png",
			info.Width,            //bitmap image width
			info.Height,           //bitmap image height
			1,                     //mip-map levels (1 for no chain)
			D3DPOOL_DEFAULT,       //the type of surface (standard)
			D3DFMT_UNKNOWN,        //surface format (default)
			D3DPOOL_DEFAULT,       //memory class for the texture
			D3DX_DEFAULT,          //image filter
			D3DX_DEFAULT,          //mip filter
			D3DCOLOR_RGBA(255,255,255, 0),            //color key for transparency
			&info,                 //bitmap file info (from loaded file)
			NULL,                  //color palette
			&texture );            //destination texture

		//make sure the bitmap textre was loaded correctly
		if (result != D3D_OK) 	{
		MessageBox(0, "Texture not loaded correctly.", "Error!", 0);
			texture = NULL;
		}
		D3DXCreateSprite(p_device,&sprite);

	MSG msg;
    ZeroMemory( &msg, sizeof(msg) );
    while( msg.message!=WM_QUIT )
    {
		while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) 
		{
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
		// ------ MAP------
		p_device->BeginScene();
		sprite->Begin(D3DXSPRITE_ALPHABLEND);
		RECT rectangleg;
		rectangleg.right = 48;
		rectangleg.left = 0;
		rectangleg.bottom = 48;
		rectangleg.top = 0;
		RECT rectanglew;
		rectanglew.right = 96;
		rectanglew.left = 48;
		rectanglew.bottom = 48;
		rectanglew.top = 0;
		RECT rectangles;
		rectangles.right = 48;
		rectangles.left = 0;
		rectangles.bottom = 96;
		rectangles.top = 48;
		int y = 0;
		int x = 0;
		for(int i=0;i<16;i++){
			x = 0;
		for(int j=0;j<22;j++){
			if(j == 10||j == 11&&i != 3)
			{
				sprite->Draw(texture,&rectanglew,NULL,&D3DXVECTOR3( (float)x*48, (float)y*48, 0 ),D3DCOLOR_RGBA(255,255,255, 255)); }
			else if(j == 9&&i == 3||j == 11&&i == 3)
			{
				sprite->Draw(texture,&rectangles,NULL,&D3DXVECTOR3( (float)x*48, (float)y*48, 0 ),D3DCOLOR_RGBA(255,255,255, 255)); }
			else
			{
				sprite->Draw(texture,&rectangleg,NULL,&D3DXVECTOR3( (float)x*48, (float)y*48, 0 ),D3DCOLOR_RGBA(255,255,255, 255)); }
		x++;
		 }
		y++;
		}
		sprite->End();
		p_device->EndScene();
		p_device->Present(NULL, NULL, NULL, NULL);
		// ------ MAP Ende------
	}

   return 1;
}
LRESULT WINAPI WinProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam )
{
	switch( msg )
		{                
		 case WM_QUIT:
		 case WM_CLOSE:
		 case WM_DESTROY:
			PostQuitMessage(0);
			break; 

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

 

0

Share this post


Link to post
Share on other sites

Adding
 

				sprite->Draw(texture,&rectanglew,NULL,&D3DXVECTOR3( (float)(x*48)-0.5f, (float)(y*48)-0.5f, 0 ),D3DCOLOR_RGBA(255,255,255, 255)); }
			else if(j == 9&&i == 3||j == 11&&i == 3)
			{
				sprite->Draw(texture,&rectangles,NULL,&D3DXVECTOR3( (float)(x*48)-0.5f, (float)(y*48)-0.5f, 0 ),D3DCOLOR_RGBA(255,255,255, 255)); }
			else
			{
				sprite->Draw(texture,&rectangleg,NULL,&D3DXVECTOR3( (float)(x*48)-0.5f, (float)(y*48)-0.5f, 0 ),D3DCOLOR_RGBA(255,255,255, 255)); }

results in

ag4tjf3nl6y.png

 

now they have a small blurr too. blink.png

0

Share this post


Link to post
Share on other sites

make sure about the mapping, probably you are mapping it wrong

 

// ------ MAP------
p_device->BeginScene();
sprite->Begin(D3DXSPRITE_ALPHABLEND);
RECT rectangleg;
rectangleg.right = 48;
rectangleg.left = 0;
rectangleg.bottom = 48;
rectangleg.top = 0;
RECT rectanglew;
rectanglew.right = 96;
rectanglew.left = 48;
rectanglew.bottom = 48;
rectanglew.top = 0;
RECT rectangles;
rectangles.right = 48;
rectangles.left = 0;
rectangles.bottom = 96;
rectangles.top = 48;
0

Share this post


Link to post
Share on other sites

In the image you posted in original post, are you sure backbuffer was the right size? If it's smaller it could stretch everything when actually everything's fine.

0

Share this post


Link to post
Share on other sites
Right, the backbuffer had some problems.

I removed this:
PresentParams.BackBufferWidth = width; // set the width of the buffer
PresentParams.BackBufferHeight = height; // set the height of the buffer

Because of PresentParams.windowed = true; the BackBufferWidth and Height is set automatical.

Also I changed the width and height here:
window = CreateWindowEx( 0,"winmain",	//window class"test",	//title bar
WS_EX_TOPMOST|WS_POPUP|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_CLIPSIBLINGS|WS_VISIBLE,100, 100,	//x,y coordinate
wr.right - wr.left, // width of the window
wr.bottom - wr.top, // height of the window
0,	//parent window
0,	//menu
g_hInstance,	//application instance
0);	//display the window

to the variables width, and height. Dunno why I made a rectangle there. Edited by PuReInSaNe
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0