Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!

Dave Hunt

Member Since 30 Dec 2002
Offline Last Active Yesterday, 09:19 AM

#5081989 Help with 2d texture array for maps in XNA

Posted by Dave Hunt on 31 July 2013 - 12:57 PM



Assuming brick width is 10 for this example:


0 * greenBrick.Width + xOffset == 0 + 100 == 100;

1 * greenBrick.Width + xOffset == 10 + 100 == 110;

2 * greenBrick.Width + xOffset == 20 + 100 == 120;


#5081980 Help with 2d texture array for maps in XNA

Posted by Dave Hunt on 31 July 2013 - 12:20 PM

Something like:

int xOffset = 100; // or whatever you come up with for the left edge
int yOffset = 20; // or whatever you come up with for the top edge


spriteBatch.Draw(greenBrick, new Vector2(x * greenBrick.Width + xOffset, y * greenBrick.Height + yOffset), Color.White);

#5081954 Help with 2d texture array for maps in XNA

Posted by Dave Hunt on 31 July 2013 - 10:40 AM

To get your map 10 wide and 7 tall, you need to reverse your x and y index usage. bound0 is the number of rows (y) and bound1 is the number of columns (x), not the other way around as you are using them.


To draw a blank space when you encounter a zero, just don't draw anything:

switch (map[y,x])
    case 1:
    case 2:
    case 3:

#5077873 Strange Sprite Behaviour

Posted by Dave Hunt on 15 July 2013 - 09:40 AM

However it seems to be scaling the sprite up a bit. Is this because of the texture size? Does it need to be a factor of 2?

It likely needs to be a power of 2. Try resizing the texture to 512x64 (you can leave the actual sprite image in the upper 458x50 of the texture) and specifying a 458x50 source rectangle in the Draw call.

#5076462 Batch files question, namely assigning values correctly

Posted by Dave Hunt on 09 July 2013 - 05:34 PM

Make sure you don't have extra spaces in this line:


    set /a endloop = endloop1 + endloop2


It should be:


    set /a endloop=endloop1+endloop2


Also, numeric values starting with a leading '0' will be treated as octal, so it's possible that some of your lines contain values with leading '0's and digits greater than 7, which would result in an error. I noticed your "map" line has a LoopStart value with leading '0's...


Other than that, I don't see anything wrong with your script.

#5075049 D3DX8 and D3DX9 in one project

Posted by Dave Hunt on 03 July 2013 - 09:43 AM

I'm confused as to how an outright hack is preferable to a clean and simple solution, but if you're happy, then carry on.

#5074795 What is ID3D11Blob ?

Posted by Dave Hunt on 02 July 2013 - 11:48 AM

It's a generic wrapper containing a buffer (blob) of data specific to whatever call you are making. The buffer is accessible through the ID3D11Blob::GetBufferPointer function. You can then cast that pointer to whatever type is specified for whichever function you are calling.


For example, when calling D3DX11CompileFromFile, the blob gives you a pointer to a string that contains any error message generated by the call. See http://msdn.microsoft.com/en-us/library/windows/desktop/ff476139(v=vs.85).aspx for an example.


When calling D3DX11SaveTextureToMemory, the blob gives you a pointer to the memory where the texture was saved. See https://code.google.com/p/slimdx/source/browse/branches/dx11/source/direct3d11/Texture.cpp?r=813 for an example.


The contents of the blob are always specific to the function being called and should be documented on the MSDN page for that function.

#5073757 obj doesn't draw

Posted by Dave Hunt on 28 June 2013 - 09:02 PM

Probably because sizeof(cub.getVertexBuffer()) and sizeof(cub.getIndexBuffer()) don't do what you think they do. Since cub.getVertexBuffer() and cub.getIndexBuffer() return pointers, the sizeof() is giving you the size of a pointer, not the size of the buffer. You need to pass in the actual size of the buffers.

#5073009 Right way to start Game programming.

Posted by Dave Hunt on 26 June 2013 - 11:48 AM

I would suggest searching/browsing these forums for topics similar to yours. This question, in one form or another, is asked on a daily basis here. Also, there's a sticky post at the top of this forum titled "New to the forums? Start here!". I would suggest doing just that. There are some good links in there that should help get you started on the right track.

#5070551 [MASM] where to start - good books for beginner.

Posted by Dave Hunt on 17 June 2013 - 02:03 PM

Modern compilers are much better at optimizing code than they used to be. Without a deep understanding of processor architecture, you're much better off writing clean C++ code, and leaving the assembly-level optimization to the compiler.

#5070455 DirectX or OpenGL

Posted by Dave Hunt on 17 June 2013 - 10:35 AM

I would suggest you search the forums and internet. This question has been asked here many times. The trouble with a question like this is it often degenerates into a holy war between two factions.


Just read the information that's available already and make a decision based on what seems best for you.

#5069240 Bullets won't shoot up or down

Posted by Dave Hunt on 12 June 2013 - 03:49 PM

Seriously, your debugger will tell you what is going wrong.

#5069197 Bullets won't shoot up or down

Posted by Dave Hunt on 12 June 2013 - 01:12 PM

The debugger is your best friend here. Step through your shoot and update code and check that they are actually being called and the variables have the expected values and are getting updated as expected. That should tell you where things are going wrong.

#5065856 Problem with texture mapping

Posted by Dave Hunt on 29 May 2013 - 10:49 AM

As an aside, you do NOT want to be generating a new texture and loading an image every time you draw. You should load the image and generate the texture once, during initialization (or level change), and then just set it on the device (with glBindTexuture) when you draw.

#5063881 SDL_Surface to OpenGL texture problem.

Posted by Dave Hunt on 22 May 2013 - 10:44 AM

The last thing you want to do is glGenTextures/glDeleteTextures every frame.


1. Move the code that does the glGenTextures/glTexImage2D/glTexParameteri closer to where your textures get loaded. Once you generate a texture, you can release the associated SDL surface.


2. When "applying" a surface, cal glBindTexture with the appropriate texture id. That's all you need (other than the glTexCoord2f's).


3. Move the code that does the glDeleteTextures somewhere in your shutdown code, or, if you are loading/unloading resources per level, move it to your unload code.


edit - in step 1, you'll also need a glBindTexture there as well. That tells OpenGL what texture the following glTex* code applies to.