darcmagik

Members
  • Content count

    102
  • Joined

  • Last visited

  1. Tilemap rendering 2D RPG

    I see what you are talking about with the rendering I'm not sure how to fix this yet I'm going to do some research. The challenge is with using Direct X 11 + DirectXTK the way DirectXTK does rendering for 2D is using an implementation of a sprite batch which I currently have things setup so that every system in my engine that is currently active that needs to render does a render call between the SpriteBatch Begin call and the SpriteBatch End call. But I have been trying to make this DirectXTK stuff work for a while now maybe its time to consider another way of rendering.
  2. Tilemap rendering 2D RPG

    Hey so I figured this out it was my code for grabbing the tile actually lol so my source rectangle wasn't setup properly it was slowly grabbing different tiles from the array of tiles. Now to speed up the scrolling speed...
  3. Tilemap rendering 2D RPG

    Hey thanks for responding here is the code that I use to define the layerColumns, and layerRows: // calculate certain values for rendering screenRows = (RenderManager::GetInstance().GetGameHeight() / (int)(m_tileDimensions.y) + 1); screenColumns = (RenderManager::GetInstance().GetGameWidth() / (int)(m_tileDimensions.x) + 1); Yes I will look at what you mentioned.
  4. Tilemap rendering 2D RPG

    Hmm ok so I looked at what you both were talking about and I figured out how to fix the issue somewhat... so it is no longer going out of bounds and it does scroll all around the map like it is supposed to which is great but I do have one problem left to solve which is now when it is scrolling up down left and right I get some weird abnormality which I think has to do with my sourceRectangle and DestinationRectangle code. I have included a picture to show what it is doing: I realize again this is probably something simple that I'm missing and I am going to keep looking at my own code to see if I can find it but if anybody has any ideas as to what is causing this please help. I'm currently working off of very little sleep so any help is appreciated on this project. Also somebody asked me about how I am rendering things just an FYI that might help in understanding I am using DirectX 11 but I'm using the DirectXTK in order to make doing 2D rendering easier which from what I can see there is no translate option for 2D in DirectXTK so... And as a reminder this is how my look that render's the map to the screen looks right now. // traverse through the number of rows for (int row = 0; row < screenRows; row++) { // traverse through the number of columns for (int column = 0; column < screenColumns; column++) { // grab value from tilemap tileValue = m_tileMap[((tileY + row) * m_layerColumns + (tileX + column))]; //tileValue = m_tileMap[(column * m_layerColumns) + row]; // calculate the source rectangle //m_sourceRectangle.left = (long)((tileValue % textureColumns) * m_tileDimensions.x); m_sourceRectangle.left = (long)(m_currentDrawPosition.x + (long)((tileValue % textureColumns) * m_tileDimensions.x)); m_sourceRectangle.top = (long)(m_currentDrawPosition.y + (tileValue / textureColumns) * m_tileDimensions.y); m_sourceRectangle.right = (long)(m_sourceRectangle.left + m_tileDimensions.x); m_sourceRectangle.bottom = (long)(m_sourceRectangle.top + m_tileDimensions.y); // calculate the destination rectangle m_destinationRectangle.left = (long)(column * m_tileDimensions.x); m_destinationRectangle.top = (long)(row * m_tileDimensions.y); m_destinationRectangle.right = (long)(m_destinationRectangle.left + m_tileDimensions.x); m_destinationRectangle.bottom = (long)(m_destinationRectangle.top + m_tileDimensions.y); // draw the tile to the screen at the correct position RenderManager::GetInstance().RenderObject(m_textureName, m_sourceRectangle, m_destinationRectangle); } }
  5. Tilemap rendering 2D RPG

    Good evening all, so it has been a while since I've posted but I am back to working on some stuff now that I have time. I'm working out some issues with a game I'm working on which is an old school 2D top down style JRPG. I'm working out the code for rendering the map to the screen which I know is something that has been done a million times and believe me I have read through close to hundreds of articles and tried so many changes to my code to find out what is going on and what is causing the error I'm having and I still can't track down what I'm doing wrong so I have decided that it is time for a fresh set of eyes to look at my code. Let me set the stage for what I'm doing I have my map setup so that I can have multiple layers to the map, to give the world some depth, and I am using a Vector to hold my array of int values that are used to decide the tiles to render to the screen. The issue I am having is somewhere between my rendering and my update code if I try to move the map at all on the screen I immediately get a Vector index out of bounds error and I can't track down what I'm doing wrong. I know it is probably something simple but I can't see it. Here is my update method: void Layer::UpdateLayer(float deltaTime) { // update the draw position based on scroll speed, velocity and the change in time from frame to frame m_currentDrawPosition.x += (m_scrollSpeed.x * m_velocity.x) * deltaTime; m_currentDrawPosition.y += (m_scrollSpeed.y * m_velocity.y) * deltaTime; // check to see that the draw position isn't less than 0 if (m_currentDrawPosition.x < 0) { m_currentDrawPosition.x = 0; } // check to see that the draw position isn't greater than the size of the map if ( (m_mapDimensions.x >= RenderManager::GetInstance().GetGameWidth()) && m_currentDrawPosition.x > m_mapDimensions.x - RenderManager::GetInstance().GetGameWidth()) { m_currentDrawPosition.x = m_mapDimensions.x - RenderManager::GetInstance().GetGameWidth(); } // check to see that the draw position isn't less than 0 if (m_currentDrawPosition.y < 0) { m_currentDrawPosition.y = 0; } // check to see that the draw position isn't greater than the size of the map if ( (m_mapDimensions.y >= RenderManager::GetInstance().GetGameHeight()) && m_currentDrawPosition.y > m_mapDimensions.y - RenderManager::GetInstance().GetGameHeight()) { m_currentDrawPosition.y = m_mapDimensions.y - RenderManager::GetInstance().GetGameHeight(); } } Here is my Render Method: void Layer::RenderLayer() { int screenRows = 0; // int that represents the number of rows on the screen int screenColumns = 0; // int that represents the number of columns on the screen int tileX = 0; // int that represents x position on screen for a tile int tileY = 0; // int that represents y position on screen for a tile int tileValue = 0; // value of tile in tilemap at the position int textureColumns = 0; // how many columns in the texture // only calculate and do rendering if this is a graphical layer if (m_layerType == graphicLayer) { // calculate certain values for rendering screenRows = RenderManager::GetInstance().GetGameHeight() / (int)(m_tileDimensions.y); screenColumns = RenderManager::GetInstance().GetGameWidth() / (int)(m_tileDimensions.x); if (screenColumns > m_layerColumns) { screenColumns = m_layerColumns; } if (screenRows > m_layerRows) { screenRows = m_layerRows; } tileX = (int)(m_currentDrawPosition.x / m_tileDimensions.x); tileY = (int)(m_currentDrawPosition.y / m_tileDimensions.y); textureColumns = (int)(RenderManager::GetInstance().GetTextureDesc(m_textureName).Width / m_tileDimensions.x); // traverse through the number of rows for (int row = 0; row < m_layerRows; row++) { // traverse through the number of columns for (int column = 0; column < m_layerColumns; column++) { // grab value from tilemap tileValue = m_tileMap[((tileY + row) * m_layerColumns + (tileX + column))]; // calculate the source rectangle m_sourceRectangle.left = (long)((tileValue % textureColumns) * m_tileDimensions.x); m_sourceRectangle.top = (long)((tileValue / textureColumns) * m_tileDimensions.y); m_sourceRectangle.right = (long)(m_sourceRectangle.left + m_tileDimensions.x); m_sourceRectangle.bottom = (long)(m_sourceRectangle.top + m_tileDimensions.y); // calculate the destination rectangle m_destinationRectangle.left = (long)(column * m_tileDimensions.x); m_destinationRectangle.top = (long)(row * m_tileDimensions.y); m_destinationRectangle.right = (long)(m_destinationRectangle.left + m_tileDimensions.x); m_destinationRectangle.bottom = (long)(m_destinationRectangle.top + m_tileDimensions.y); // draw the tile to the screen at the correct position RenderManager::GetInstance().RenderObject(m_textureName, m_sourceRectangle, m_destinationRectangle); } } } } So although I'm not looking for somebody to write my code for me I'm looking for some help in figuring out what I'm doing wrong that is causing the error's I'm getting. Please help me with this if you can. Also let me know if you need any more info on how I'm doing things.
  6. Hey sorry for not clarifying some stuff OK this is a game engine that I'm making myself I am writing it in C++ and using DirectX 11.  I am using the DirectXTK library for the sprite batch features as well as the audio and input features as well.  As of right now I'm attempting to design it out myself but I know this is going to be a very daunting task so if there are any good libraries out there that I could implement into my engine I would love to hear about it.
  7. Hey everybody I'm back again with more fun stuff that I'm attempting to solve.  So at this point in the project I am trying to figure out GUI controls and just to clarify what I mean by this, I want to have a screen in the game where the player can turn the volume up or down, and possibly make it so they can select a resolution, also I will have a screen where they player can set key bindings and I want to display labels and Boxes they can click on and then press a new key to bind to that action in the game.  I'm trying to figure out the controls creating sliders, and labels, etc... I'm not opposed to using a library I just want to make sure that if I do use a library that it will work on other platforms like game consoles I'm also not opposed to attempting to program it myself even though I know something like this can be a very daunting programming task.   So I guess I'm looking for advice on this topic, any ideas for libraries that will not have any licensing issues in a product put out on the market for sale and or just some ideas for how to do this.  I'm doing research on the topic and I'm attempting to find the answers myself but not finding much out there which I'm guessing may be due to my google searches.   Any and all helpful information would be greatly appreciated.
  8. The funny thing is that today when I tried to step through it again I couldn't get the null value to re appear.  I think that something that I did last night in attempting to fix the problem fixed that part and as I posted earlier I forgot to load the textures into the engine when I moved code around.
  9. Ok So after I posted this I started following my code a little more and found where I screwed up.  This really was a simple mistake I forgot to move the stuff over to the state where the actual graphics are loaded into memory.  The Graphics Object is there the Input Object is there hell every bit of data is there accept I forgot to load the textures into memory for the map which I was doing originally in the Game class temporarily while I was working on the state system.   Ignore this post sorry about that.
  10. Hello again everybody on GameDev.net forums you guys are always so helpful in my quest to learn and complete the game that I'm working on.  So here is another problem I'm having that I'm hoping you guys can assist me with.   So let me give you a little run down on how my engine works, I have a class that builds the window and once its done doing that it passes control basically over to a game class that does most of the work or delegates the work to other systems.  This game class instantiates the Render Manager class object, and an input manager object and a game state manager object as well.  The render manager, and input manager objects are passed into the game state manager class so that the various states of the game can render and access input.   Now this system has worked just great since I started using it the first couple of states in the system work great I have the company logo's being displayed on a timed setting and they transition between each one easily and with no problems.  Then the system changes the state over to the Main Menu and that state works great it changes the input scope over to that system and accepts input specific for that state and everything is happy.  When that state accepts input to move on to the New Game it changes the current state over to the New Game and things seem to be fine.  Now the New Game state is not complete I'm using it to test out various other systems like dialog boxes as well as my map system for displaying the main game play of the game on screen.   Hope your still with me on this so far... Now I should point out that before I started using the game state system I had created a temporary variable inside of the main Game class for the Map system and had tested out how it works made sure that everything gets loaded properly and that it accepted input and was drawing things to the screen just fine.  So when I created the New Game State I simply copied over how I was creating the map to the New Game State I used the same variable, copied the lines that I used for setting it up and everything.   The Update call is called inside of the states update method which is called by the State Manager which is called by the game class, the draw call is setup the same way as well.  Now when I build everything and start running the game the engine switches between the states just fine and when it gets to the switch over to the New Game state it does so just fine but by the time it reaches the point of doing an update and doing a draw call the map class's rendering object has become NULL again as if it was never received and before I'm asked I have verified that it is getting passed in and verified that it was received correctly in fact I stepped through every line of the Initialize process of the map system and up until the point where the initialize map method returns back to the state all objects that the map contains are in great shape and everything is happy.   But by the time it reaches the first update and the first draw call it loses the graphics object as well as a few other object variables now I realize this has something to do with how I'm holding onto the pointers for these variables what I'm trying to figure out is what would be the best course of action for this system should I be holding onto a smart_pointer or shared_pointer or what is your suggestion.  I've been looking at this code now for a couple of days and honestly I'm just not seeing the answer right now.  I know its going to be something simple that I'm missing here but that is why I'm here hoping that a fresh brain can point out what I'm missing.   So as always thank you in advance for any and all assistance you guys can provide.
  11. Hello everybody I'm back again with some more interesting problems that I need help solving.  So I have moved forward with my engine and I'm working on the Input system for it I had Input from a keyboard working before and decided that it was time to add support for a game controller.  When I started working on this I also decided to change my input system so that it would be easier for me to change controls and to allow for Change in Key bindings in an options menu.   I'm running into a very interesting bug the reason why it is interesting to me is that the code kinda works, it receives the input commands it processes them for me.  Keyboard Commands get handled perfectly with no issues.  But when it comes to the game pad controls I'm getting some abnormalities.  So if I setup my code for checking for Directional pad presses like this: if (tracker.dpadUp == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Up)) (*commandIterator)->execute(true); else if (tracker.dpadUp == GamePad::ButtonStateTracker::RELEASED && ((*commandIterator)->getGamePadDpadBinding() == Up)) (*commandIterator)->execute(false); if (tracker.dpadDown == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Down)) (*commandIterator)->execute(true); else if (tracker.dpadDown == GamePad::ButtonStateTracker::RELEASED && ((*commandIterator)->getGamePadDpadBinding() == Down)) (*commandIterator)->execute(false); if (tracker.dpadLeft == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Left)) (*commandIterator)->execute(true); else if (tracker.dpadLeft == GamePad::ButtonStateTracker::RELEASED && ((*commandIterator)->getGamePadDpadBinding() == Left)) (*commandIterator)->execute(false); if (tracker.dpadRight == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Right)) (*commandIterator)->execute(true); else if (tracker.dpadRight == GamePad::ButtonStateTracker::RELEASED && ((*commandIterator)->getGamePadDpadBinding() == Right)) (*commandIterator)->execute(false); It will process DPad PRESSED lines correctly but will ignore the RELEASED lines but all directions will work.  Now if I change it to this: if (tracker.dpadUp == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Up)) (*commandIterator)->execute(true); else if (tracker.dpadUp == GamePad::ButtonStateTracker::UP && ((*commandIterator)->getGamePadDpadBinding() == Up)) (*commandIterator)->execute(false); if (tracker.dpadDown == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Down)) (*commandIterator)->execute(true); else if (tracker.dpadDown == GamePad::ButtonStateTracker::UP && ((*commandIterator)->getGamePadDpadBinding() == Down)) (*commandIterator)->execute(false); if (tracker.dpadLeft == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Left)) (*commandIterator)->execute(true); else if (tracker.dpadLeft == GamePad::ButtonStateTracker::UP && ((*commandIterator)->getGamePadDpadBinding() == Left)) (*commandIterator)->execute(false); if (tracker.dpadRight == GamePad::ButtonStateTracker::PRESSED && ((*commandIterator)->getGamePadDpadBinding() == Right)) (*commandIterator)->execute(true); else if (tracker.dpadRight == GamePad::ButtonStateTracker::UP && ((*commandIterator)->getGamePadDpadBinding() == Right)) (*commandIterator)->execute(false); It recognizes both states PRESSED and UP and if I put a break point I can see that it catches on both cases PRESSED and UP but it ignores whatever the first action is like for example I have it setup so that if Left is Pressed it will scroll the map Left and if Right is pressed it scrolls Right.   If I step through the code it triggers on the LEFT it calls the execute method which calls the callback function that handles moving the map correctly but it will not move it.  I'm stumped on this one I've spent probably close to 5 hours trying to solve this issue and I know it is probably something simple that I'm just missing which is why I'm hoping that a fresh set of eyes will spot the bug.  So please help.   If you need more code related to the issue to understand it please ask.
  12. OK me again ignore my rants and my dumb questions I figure it out I had to move the actual declarations from the game header file to the game cpp file and the error went away and everything works again so this was a simple dumb error on my part.  But you live and you learn and I have learned quite a bit today so kudos to everybody that gave me their thoughts on this and thanks to everybody on this website because I have learned so much from these forums and the various articles on here as well.
  13. OK so I am attempting to use an external variable for the graphics system because with the way I'm doing things it seems like the best idea.  So I have an issue with a link error now.  I am defining the extern g_graphicSystem variable inside the Graphics System's Header file at the bottom after the class.  Then in the game class header file I have it defined like I am supposed to from what I am reading in reference material, and in the Game class I call the constructor of the Graphics class to make sure that the new g_graphicSystem variable is defined.   The error I'm now getting is if I have the variable declaration inside of the game class I get an unresolved external symbol link error but if I have the declaration line in the game header but outside of the game class I then get a link error related to the g_graphicSystem already being defined.   One thing I should point out that may give somebody an aha moment for somebody is that the way my class structure is setup is that the actual game entry point the WinMain is part of a class called Win32_Window this class instantiates a Game variable sets up the loop and then passes control over to the game class so the Win32_Window class basically doesn't get touched again until the window closes.   I'm very sorry if what I'm saying sounds like it doesn't make sense but I have been looking at my code for many hours as I attempt to fix all of these crazy issues and try to move the project forward towards completion.
  14. OK I understand where you are going with that, I'm going back to my project now and see if I can implement things correctly related to what people have suggested.  I will hopefully not be back with more problems related to this but you never know...
  15. So here is what I have I have a class for graphics that creates the DirectX 11 object, and the device context and everything else it needs to get graphics displaying on the screen.  This class also contains a Map that contains all textures in the game they are tied to a name in the map.  This class also contains certain methods for drawing graphics to the screen I have methods like Draw Object which you can pass in the name of the texture and the position you want it at.  I have other methods like that in the class.   The other sub systems I'm referring to are like I have a class for the Console window that handles everything related to displaying a console on the screen and accepting commands.   I have a system that I'm working on that will be a level editor for the game this level editor right now is only going to be used by the internal team for developing the content for the game but that may change when the game gets closer to release.  This system will be heavily tied in with the Console class.   Then I have my map and game world classes the game world class contains all the maps for the game I haven't gotten very far with this class yet as I'm working on just getting a single map displaying on the screen and updating properly with animations and when user input is present.   Right now I am passing the graphics pointer from the Game class to Map, and its various classes and what not, and I'm also passing this pointer to the Console and Level Editor classes.   I'm a little embarrassed to say that I didn't think of the idea of using an interface to the Graphics system of my game to be honest I have never implemented one before in a class I guess I will need to go do some research on how to properly do this because I do remember reading about using interfaces in game development just never implemented one myself.