Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

viper110110

Member Since 11 Nov 2008
Offline Last Active May 14 2013 08:31 PM
-----

Topics I've Started

Target pointers for off-screen objects

26 April 2013 - 11:22 AM

I have a top down game where things sometimes go off the screen and you want to know where they are to go get them. I want markers on the edge of the screen to show where the target item is. I have tried a couple different strategies and none of them seem to be working. Here is my current one in case that helps.

 

Vector2 screenRatio = new Vector2(camera.Width, camera.Height);
                        screenRatio.Normalize();
                        Vector2 distance = snakePellets[i].worldPosition - snake.Head.worldPosition;
                        distance.Normalize();
                        if (distance.X / distance.Y > (float)camera.Width / (float)camera.Height)
                        {
                            snakePellets[i].worldPosition.X = distance.X < 0 ? camera.position.X + 20 : camera.position.X + camera.Width - 20;
                            snakePellets[i].worldPosition.Y = MathHelper.Lerp(camera.Height / 2, camera.position.Y + camera.Height - 20, distance.Y / screenRatio.Y);
                        }
                        else
                        {

                            snakePellets[i].worldPosition.X = MathHelper.Lerp(camera.Width / 2, camera.position.X + camera.Width - 20, distance.X / screenRatio.X);
                            snakePellets[i].worldPosition.Y = distance.Y < 0 ? camera.position.Y + 20 : camera.position.Y + camera.Height - 20;
                        }

                        camera.draw(spriteBatch, snakePellets[i]);
                        snakePellets[i].worldPosition = oldPos;

Using c#/xna. The snakePellets[i] is the item I want to make a pointer to. I am currently just moving it to where I want the pointer to be, drawing it, then moving it back. This is all assuming the snake pellet is off the screen.


Can't create texture from raw data

22 March 2013 - 12:45 PM

I am getting raw data from stb_image.c for an image I want to load. I am then trying to turn it into a  drawable texture. I haven't been able to find any tutorials on how to load an image from raw data. I have assembled some code from what I could gather from the documentation. The image drawing code works because I use different code to set the same resource view with a dds texture and it works. All the results are S_OK.

 

int x, y, n;
	unsigned char *data = stbi_load(charFilename, &x, &y, &n, 0);

	D3D11_TEXTURE2D_DESC desc;
	desc.Width = x;
	desc.Height = y;
	desc.MipLevels = 1;
	desc.ArraySize = 1;
	desc.Format = DXGI_FORMAT_R8G8B8A8_UINT;
	desc.SampleDesc.Count = 1;
	desc.SampleDesc.Quality = 0;
	desc.Usage = D3D11_USAGE_DEFAULT;
	desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;
	desc.CPUAccessFlags = 0;
	desc.MiscFlags = 0;

	/*D3D11_SUBRESOURCE_DATA subres;
	subres.pSysMem = data;
	subres.SysMemPitch = x * n;
	subres.SysMemSlicePitch = 0;*/

	ID3D11Texture2D *texture2D = 0;

	HRESULT result = device->CreateTexture2D(&desc, NULL, &texture2D);
	if (FAILED(result))
	{
		DebugConsole::writeLine("Failed to create Texture2D");
	}

	D3D11_SHADER_RESOURCE_VIEW_DESC resourceViewDesc;
	resourceViewDesc.Format = desc.Format;
	resourceViewDesc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
	resourceViewDesc.Texture2D.MostDetailedMip = 0;
	resourceViewDesc.Texture2D.MipLevels = 1;

	result = device->CreateShaderResourceView(texture2D, &resourceViewDesc, &m_texture);
	if (FAILED(result))
	{
		DebugConsole::writeLine("Failed to create resource view");
	}

 


There has to be a better way... (to get text)

14 March 2013 - 07:46 PM

Is there a better way to do the following?

 

I tried importing Microsoft.VisualBasic and then using Interaction.InputBox() but it sometimes crashed and otherwise froze the game.

 

string text = string.Empty;

            if (IsNewKeyPress(Keys.A))
            {
                if (CurrentKeyboardState.IsKeyDown(Keys.LeftShift) || CurrentKeyboardState.IsKeyDown(Keys.RightShift))
                {
                    text += "A";
                }
                else
                {
                    text += "a";
                }
            }
            if (IsNewKeyPress(Keys.B))
            {
                if (CurrentKeyboardState.IsKeyDown(Keys.LeftShift) || CurrentKeyboardState.IsKeyDown(Keys.RightShift))
                {
                    text += "B";
                }
                else
                {
                    text += "b";
                }
            }
           //Through z, plus numbers

 


Including a c file

04 March 2013 - 09:10 PM

From my other thread about loading PNGs, I ended up choosing a library that was distributed as a single C file (stb_image.c). What is the proper way to include this into my project and make it compile? I brought it in with an #include, but it gave duplicate definition errors because it was also compiling the file on its own. Is there a flag I can set on the file to not compile it? Or is there a better way to do it?


Loading PNG files

02 March 2013 - 10:48 PM

I have searched google and I can't seem to find anything relevant. I am trying to load simple PNG images into my directx program. I have DDS images working and they become ID3D11ShaderResourceView when loaded. How can I load PNGs?

 

I am targeting the windows app store and D3D 11.1, but I would also prefer something more backwards compatible with windows 7.


PARTNERS