• 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
blueshogun96

2D sprite problems

3 posts in this topic

At the moment, I'm trying to write a replacement for the ID3DXSprite interface. The reason is because Xbox360 doesn't support this interface and I'm attempting to port existing code that currently uses it.

I've made some progress getting D3DXMatrixOrthoLH to work (finally) and I've managed to successfully blit a full screen 2D image. However, when blitting smaller images and sprite sheets, things don't work properly anymore. I've put quite a bit of work into getting this working so far, here's my code:

[CODE]
void bltSprite( LPDIRECT3DTEXTURE9 tex, RECT* src, D3DXVECTOR3* dst )
{
D3DXMATRIX mtxProj, mtxWorld, mtxView;
struct BLTVERTEX v[4];
float w = src->top - src->right;
float h = src->left - src->bottom;
float fx, fy;
ZeroMemory( v, sizeof( struct BLTVERTEX ) * 4 );
fx = src->right - (ScreenX/2.0f);
fy = src->bottom - ((ScreenY/2.0f)-h);
v[0].v.x = dst->x - 0.5f;
v[0].v.y = -dst->y - 0.5f;
v[1].v.x = dst->x+w - 0.5f;
v[1].v.y = -dst->y - 0.5f;
v[2].v.x = dst->x+w - 0.5f;
v[2].v.y = -dst->y+h - 0.5f;
v[3].v.x = dst->x - 0.5f;
v[3].v.y = -dst->y+h - 0.5f;
v[0].t.x = src->top / w;
v[0].t.y = 1.0f - src->left / h;
v[1].t.x = src->right / w;
v[1].t.y = 1.0f - src->left / h;
v[2].t.x = src->right / w;
v[2].t.y = 1.0f - src->bottom / h;
v[3].t.x = src->top / w;
v[3].t.y = 1.0f - src->bottom / h;
D3DXMatrixTranslation( &mtxWorld, fx, -fy, 0.0f );
D3DXMatrixIdentity( &mtxView );
IDirect3DDevice9_SetTransform( lpD3DDevice, D3DTS_WORLD, &mtxWorld );
IDirect3DDevice9_SetTransform( lpD3DDevice, D3DTS_VIEW, &mtxView );
IDirect3DDevice9_SetFVF( lpD3DDevice, D3DFVF_XYZ | D3DFVF_TEX1 );
IDirect3DDevice9_SetTexture( lpD3DDevice, 0, (IDirect3DBaseTexture9*) tex );
IDirect3DDevice9_DrawPrimitiveUP( lpD3DDevice, D3DPT_TRIANGLEFAN, 2, v, sizeof( struct BLTVERTEX ) );
}
[/CODE]


I apologize for the usage of C (for the C haters), but the project was originally written in C. I can't quite figure out what's going on here.

Examples of what works and what doesn't:

This works:
[CODE]
RECT src = { 0, 0, 640, 480 };
D3DXVECTOR3 dst = { 0, 0, 0 };
bltSprite( lpSplash, &src, &dst );
[/CODE]
[img]http://i48.tinypic.com/2jg4gp2.png[/img]

This doesn't:
[CODE]
RECT src = { 50, 50, 600, 440 };
D3DXVECTOR3 dst = { 0, 0, 0 };
bltSprite( lpSplash, &src, &dst );
[/CODE]
[img]http://i49.tinypic.com/2en8085.png[/img]

Moving the sprites about doesn't seem to work either in some instances. Not sure what's going on here. This sucks, so any help is appreciated. Thanks.

Shogun Edited by blueshogun96
0

Share this post


Link to post
Share on other sites
[source lang="cpp"]float w = src->top - src->right;
float h = src->left - src->bottom;
[/source]
Shouldn't this be w=right-left and h=top-bottom ?
0

Share this post


Link to post
Share on other sites
Just in case anyone cares, I fixed it the other day. This works perfectly.

[CODE]
void bltSprite( LPDIRECT3DTEXTURE9 tex, RECT* src, D3DXVECTOR3* dst )
{
D3DXMATRIX mtxWorld, mtxView, mtxWVP;
D3DSURFACE_DESC sd;
struct BLTVERTEX v[4];
float w = -(src->left - src->right);
float h = -(src->top - src->bottom);
float tw, th;
float fx, fy;
float u1, u2, v1, v2;
ZeroMemory( v, sizeof( struct BLTVERTEX ) * 4 );
fx = dst->x - (ScreenX/2.0f);
fy = dst->y - ((ScreenY/2.0f)-h);
IDirect3DTexture9_GetLevelDesc( tex, 0, &sd );
tw = sd.Width;
th = sd.Height;
u1 = src->left / tw;
u2 = src->right / tw;
v1 = src->top / th;
v2 = src->bottom / th;
v[0].v.x = 0.5f;
v[0].v.y = 0.5f;
v[1].v.x = w + 0.5f;
v[1].v.y = 0.5f;
v[2].v.x = w + 0.5f;
v[2].v.y = h + 0.5f;
v[3].v.x = 0.5f;
v[3].v.y = h + 0.5f;
v[0].t.x = u1;
v[0].t.y = v2;
v[1].t.x = u2;
v[1].t.y = v2;
v[2].t.x = u2;
v[2].t.y = v1;
v[3].t.x = u1;
v[3].t.y = v1;
D3DXMatrixTranslation( &mtxWorld, fx, -fy, 0.0f );
D3DXMatrixIdentity( &mtxView );
#if 0
IDirect3DDevice9_SetTransform( lpD3DDevice, D3DTS_WORLD, &mtxWorld );
IDirect3DDevice9_SetTransform( lpD3DDevice, D3DTS_VIEW, &mtxView );
IDirect3DDevice9_SetFVF( lpD3DDevice, D3DFVF_XYZ | D3DFVF_TEX1 );
#else
D3DXMatrixMultiply( &mtxWVP, &mtxWorld, &mtxView );
D3DXMatrixMultiply( &mtxWVP, &mtxWVP, &mtxProj );
IDirect3DDevice9_SetVertexShaderConstantF( lpD3DDevice, 0, (float*)&mtxWVP, 4 );
IDirect3DDevice9_SetVertexDeclaration( lpD3DDevice, lpVDecl );
IDirect3DDevice9_SetVertexShader( lpD3DDevice, lpVS );
IDirect3DDevice9_SetPixelShader( lpD3DDevice, lpPS );
#endif
IDirect3DDevice9_SetTexture( lpD3DDevice, 0, (IDirect3DBaseTexture9*) tex );
IDirect3DDevice9_DrawPrimitiveUP( lpD3DDevice, D3DPT_TRIANGLEFAN, 2, v, sizeof( struct BLTVERTEX ) );
}
[/CODE]
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