• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

258 Neutral

About Nausea

  • Rank
  1. Hey!   So, I've worked on creating a little application with bitmap fonts. I can add color on top of the text without any issue. However, I would like to know how I would go about being able to change the color for different parts of the text.   For example: "Testing ^4this ^2thing", where ^4 would tell the application that the font after it should be red, and the ^2 being say yellow.   I thought about it and it feels like I would need to split the string up at those points and then create a new sprite for the following text. Does this sound like a good idea? Because I felt like this would be very bad if the original string was very large.   Any advice would be great. Thanks     edit: So I tried going about it in another way and I'm getting a strange behavior. I'm checking if the current letter is a '^' and if so, is the next letter a '1'.  If it is, set the color to blue. It does this but somehow the letter before '^' also gets the blue color, I'm at a loss here. Can't figure out why. else if(Text[show] == '^') { if(Text[show+1] == '1') { sf::Color BlueColor(0,0,255); FontSprite.setColor(BlueColor); show = (show + 1); } }
  2. A quick way to test if your framework has the problem is to write a simple stress test. I'm not sure about it, but it sounds like you are filling the screen with small tiles. In my mind, that means you have perhaps 30x20 background tiles + 50 or so foreground tiles + 50 or so UI sprites, totaling about 700 or so sprites. So load up and draw 1,000 sprites in a frame for one test and perhaps 2,000 or even 5,000 sprites in a frame in a second test, doing the same thing you do to normally draw them. Those can even be copies of the same image, if that is how you intend to run it. Run it and look at performance. It is not uncommon that drawing a tile-based world in the way you described -- drawing the tiles individually -- has difficulty in running at a high frame rate. Many times (but certainly not always) the simple implementations will run into problems because they are copying the sprites to video memory every frame. Using SDL objects correctly probably won't have the problem. The test is to just make sure you are using them correctly and your solution will work. Running a quick stress test can easily verify that your intended method can or cannot handle that many individual draw calls.     From what I can tell my program takes up 0% in the task manager with a 1000 tiles drawn inside and outside the screen region. I go through my tilelist, blit the tiles and then when all are blit I send it from the buffer to the screen in one go.   I might go for splitting the map up in sections just because of speed anyway, might not be needed but might be a good thing anyway.
  3. How many do you have? Be realistic.   Rectangular collision tests are cheap. Performing even 1000 rectangular collision tests on your objects probably isn't going to be a noticeable blip on the profiler.   If you are running with multiple thousands of rectangular tests every frame, or hundreds of non-rectangular tests every frame, then it will make sense to use a spatial tree.     If your numbers are small then don't bother with the added complexity.     Ok. Well I won't be having over 1000 I guess I don't have to be worried, good to hear some thoughts on the subject tho.   Thanks   EDIT:     Hmm.. I have a render function in my map class that goes over the tile slots, if the current tile slot is inside the camera range, go through the list of tiles and check which ID it corresponds to and render the tileslot at x/y with the tiles sprite x/y. This render function is run inside the applications render function, when all the things in the program has been through the render function it blits it on to the screen.   Maybe my wording is poor. What i mean to say is that the maps rendering function blits the stuff on to the screen surface, later in the applications render function when everything in the program is blitted on to the screen surface i "flip" it.
  4. The tiles are all the same size.    However I mostly wonder if this will be a real bad solution?   I've tried to fill up the screen with tiles without feeling any real performance problems and I wonder if that will change when I have a full map even tho I will only draw the tiles inside the camera and the collision boxes will be fewer to check for.
  5. Hi!   I've tried to get animated tiles to work on my tile map and I've run into what may be a problem going forward. I'll try to explain how I have it constructed in my code.   First: My map class stores two vectors, one with tiles (one of each kind) and one vector stores "tile slots". It also holds a tile sheet.   Second: My tile class handles updating the sprite animation, only changes coordinates for the target sprite.  Handles frame rate etc.   It also holds an ID to connect this with a tile slot ID.   Third: My tile slot class holds ID, type, and x/y for where to draw them on the map. ID is used to link it to a tile during rendering.   .... I did it like this because it was the only way I could think of, this way I could make it so that I only need to update the animation once per tile. However, when I need to draw the tile slots for where the animated tile will be drawn I run into the problem of having to go through all tile slots and then go through all tiles to draw the correct tile at the correct place. I can cut down on some of it by checking if the tile slot is inside of the camera, but this still leads to going through the entire tile slot vector.   My worry is that this will be very taxing on the computer when I get to the point of making a full fledged map. Not to mention when I will have to in some way check for collisions with the tile slots.   I wish that someone could maybe give some input on this.   Thank you!
  6. How on earth do I start a game?!

    If you already know some basic c++ and feel somewhat comfortable in it you could go to sdltutorials.com for pretty in depth tutorials and it will get you started with SDL. 
  7.   I'm a noob but I guess I could tell you how I did this.   I used a Animation class to handle the animation itself. Then it had a list of Frameset class instances and a pointer to the current Frameset which it used to loop over it. The Frameset class had a list of Frames and ability to add Frames etc. The Frame class had x/y cords for the image and offsets and some more stuff.   I hope you get the idea, some time ago since I coded it.   Maybe someone with actual skill can tell you how much my version sucks. :)
  8. UI: move-able windows (z-order)

    Thank you so much for your answer :) I will try to make this work. And thanks for your critique on my code blocks. edit: I got it working thanks to you :) Happy times!
  9. UI: move-able windows (z-order)

    Thank you for your answer. Could you go into more detail on the "list of indices" thing? Sorry my first language is not English so I don't fully understand what you mean by it. Especially the "indices" part :P
  10. Hey!   I've run into a problem with my noobish UI setup. I have a Vector that stores all my windows. When the mouse is clicked I go through the windows vector and check if the mouse is inside any of the windows. If it is i move that window relative to the mouse position.   Now my problem is: How do I order the window selected to be in front? and since the mouse can be inside 2 windows during my check the last window it's inside will always be the one selected.    I know I should probably be using a z-order of some kind, but I just can't work out where to set it for a window and how to adjust the other accordingly.   I'll just post some code of the way I check if the mouse is inside a window. void CGame::OnLButtonDown(int _mousex, int _mousey) { for(unsigned int i=0; i < WindowList.size(); i++) { if(!WindowList[i]->GetShow()) //dont do any checks if the window is hidden. { continue; } if(_mousex >= WindowList[i]->GetX() && _mousex <= (WindowList[i]->GetX() + WindowList[i]->GetW() )) { if(_mousey >= WindowList[i]->GetY() && _mousey <= (WindowList[i]->GetY() + WindowList[i]->GetH())) { CurrentWindow = i; WindowList[i]->SetMouseDown(true); WindowList[i]->SetDifference(_mousex - WindowList[i]->GetX(), _mousey - WindowList[i]->GetY()); for(unsigned int itemnum = 0; itemnum < WindowList[i]->WindowItemList.size(); itemnum++) { if(_mousex >= WindowList[i]->WindowItemList[itemnum]->GetX() && _mousex <= (WindowList[i]->WindowItemList[itemnum]->GetX() + WindowList[i]->WindowItemList[itemnum]->GetW())) { if(_mousey >= WindowList[i]->WindowItemList[itemnum]->GetY() && _mousey <= (WindowList[i]->WindowItemList[itemnum]->GetY() + WindowList[i]->WindowItemList[itemnum]->GetH())) { if(!WindowList[i]->WindowItemList[itemnum]->GetActive()) //if the item is not an active item (such as a divider), don't do any checks for it. { continue; } else { OverActiveItem = true; if(WindowList[i]->WindowItemList[itemnum]->GetType() == ITEM_TYPE_CHECKBOX) { WindowList[i]->WindowItemList[itemnum]->Toggle(); } } } } } } } } }    
  11. Art skill learning?

    How to learn art is a pretty big question. If you want to learn by "teaching yourself" then I suggest getting books on the basics. And when you feel a bit more comfortable with your drawing skills maybe you could check out the gnomon workshop.  They have very good dvds, pretty expensive but very good. Tho you should probably not jump right into them if you lack the basics.   But most importantly: practice, practice and more practice like with most skills in life.   Hope this helps in some way.   Oh, and a school is good because it forces you to practice, you can't slack because then you wont pass the tests.
  12. Game: Health regeneration?

    I did change my health and regen to float instead of int. :) 
  13. Game: Health regeneration?

    Thank you all for your input. I finally with your help got it working. :)
  14. Game: Health regeneration?

    Hey! So I've been working on a health bar which shrinks and grows according to how much health your character has. The problem is I don't know how to add a smooth increment to health regen.  Say if I want to gain 600 life over 4 seconds, how would I go about achieving this? Will I have to use float numbers, and in what way? The health bar checks how many pixels the bar should shrink and grow depending on the health value.   This is my code right now. CHealthBart.cpp void CHealthBar::OnRender(SDL_Surface* _destination) { SDL_FillRect(_destination, &BarBackground, SDL_MapRGB(_destination->format, 0, 0, 0)); if( (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth() > 0.6f ) { SDL_FillRect(_destination, &Bar, SDL_MapRGB(_destination->format, HighHealth.r, HighHealth.g, HighHealth.b)); } if ( (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth() <= 0.6f && Owner->GetCurrentHealth() / Owner->GetMaxHealth() < 0.25f ) { SDL_FillRect(_destination, &Bar, SDL_MapRGB(_destination->format, AverageHealth.r, AverageHealth.g, AverageHealth.b)); } if( (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth() <= 0.25f) { SDL_FillRect(_destination, &Bar, SDL_MapRGB(_destination->format, LowHealth.r, LowHealth.g, LowHealth.b)); } } void CHealthBar::OnLoop() { BarBackground.x = Owner->GetX(); BarBackground.y = ( Owner->GetY() - 5 ); Bar.x = ( Owner->GetX() + 1 ); Bar.y = ( Owner->GetY() - 4 ); float tempw = (float)Owner->GetCurrentHealth() / Owner->GetMaxHealth(); Bar.w = MaxBarLength * tempw; }   Would be great if someone could give a good answer on this.
  15. Classes that need to know each other..

    Ok, thank you. Will try to get that up and running then. Yep got it working, thank you :)
  • Advertisement