Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Lkcynric

Pages: [1] 2
1
General / Re: 4 newbie questions (tilemap, textures & animating a sprite)
« on: February 09, 2018, 02:46:54 pm »
Ok, thank you both! Short and easy to understand.


2
General / 4 newbie questions (tilemap, textures & animating a sprite)
« on: February 08, 2018, 06:02:01 pm »
Hi! I made a small sample game based on tilesets without really looking how its done besides the "Example: tile map" tutorial to see if I could figure it how and learn on the way. I will now be looking into how others have done it to learn more and figure out which way might be better, but until then:

Its a 2d platformer and there are 4 things I'm not sure of and would like to ask more experienced users.

1 - When I create my vertex array, if my tile value is 0, its supposed to not have a tile. So during the creation, when this happens I skip to the next cycle. As far as I understand this means the QUADs will get the default values of (0,0) in all 4 positions and all  4 texture coordinates. That is also what I use when I want to remove a block from the game, i set its QUAD position and texture coords to (0,0).

Is this the way you should do things or there's a better way? Since the example has no such cases i figure it out on my own and might be doing something wrong.

2 - on my map.load (where I create my vertex array) I should be getting the "map" (vector<vector<int>>) NOT by value but as either a pointer or as a reference, right? I honestly need to go read more about pointers & references.

3 - I have N amount of enemy's that walk left and right like SMB Gumba's, to animate them independently of each other, I have 2 choices:
A - Use a vector of clocks, one for each enemy.
B - use 1 clock and vector of SF::time one for each enemy so I can calculate time passed.
Which of the 2 would be optimal? There's a 3rd choice of 1 clock and animate all the enemy's at the same time, but that might not work in all cases, I'm not sure.

4 - To animate a sprite would it be better to use several textures and use the ".setTexture" to change the animation frame or to use 1 texture and use the ".setTextureRact"?
I'm asking performance wise. Probably doesn't make a difference, but I'm curious.

In case you want to look at the tilemap code:
(click to show/hide)


3
General / Re: When should I update my tilemap
« on: January 31, 2018, 09:49:33 pm »
I see, that makes a lot of sense.
Thank you so much! :)

4
General / Re: When should I update my tilemap
« on: January 31, 2018, 07:51:07 pm »
Thank you, I understand how it works much better now. You are correct, was a bad approach on my part.
I decided to do and finish things even if in a bad way to see if I could do it and learn along the way, only in the end read more about it and check how to properly do it. Now I was trying to solve a problem that doesn't even exist from something I don't fully understand... not a good idea.

It didn't even occur to me that loading a bigger tileset might even have a better performance than a badly implemented "solution".

Let me ask you one last question to make sure I fully understood what you meant.

If there's a performance hit and I need to fix it, a good way is to instead of having a vertex array with, lets say  10 000 tiles, devide that in smaller chunks. like the tiles that fit on the screen +a buffer.
The buffer might be just 1, but should probably be a little higher so I don't have to update the vertex array so often (but again, the "problem" is the transfer not remaking the vertex array, so +1 buffer would work)

Is that what you meant?



5
General / Re: When should I update my tilemap
« on: January 31, 2018, 01:26:29 am »
I'm kinda embarrassed about it but I need help.
Since my last post I have been reading a ton on how to draw only the tiles that are visible, but I only got confused about if thats even possible.

This is my "tile manager", is the one from the tutorial with 2 changes.
(click to show/hide)

Changed from receiving "const int" to "std::vector<std::vector<int>>"
I added the m_vertices.clear() so when I change maps the old don't stay on screen.
and added
if (tileNumber == 0) // so 0 = no texture.
        continue; //skips giving texture to this quad vertice.
else
        tileNumber--;
 
So when the tile is 0 it doesn't show anything. (I'm not sure if I should be doing this, but thats a question for another day)

This is how I load the level:
map.load("Assets/tileSet2.png", sf::Vector2u(32, 32), _currentLevel, 30, 20);
This is how I draw the tilemap:
window.draw(map);

As you can see my map is 30x20.
My view is 15x10.
I want to draw only 16x11.
is that possible the way I have things set up?

What I was doing was, instead of loading the full map (30x20), i was loading only the 16x11, and update it it when i need the next tile. Since that is wrong, I don't know how to do it.
I read when you draw a vertex array it always fully draws, there is no way to draw only part of it. then read SFML doesn't render whats outside the view anyway. But I also saw in so many topics that rendering only the visible tiles its the correct way, so I'm just confused now.

I'm probably mixing concepts again. If anyone can help, i would appreciate it.

6
General / Re: When should I update my tilemap
« on: January 30, 2018, 09:58:43 pm »
Yes, I had to use pen and paper to help me with some things since I fall to the habit of not thinking how something work and just testing it, and then take forever to fix something because of it.

This time I just mixed loading the whole map with displaying the whole map. Its the 2nd one I don't want to do.
Thank you for the help!

7
General / Re: When should I update my tilemap
« on: January 30, 2018, 07:11:41 pm »
Things don't have to be any way. I'm trying to learn and figure things out on my own, since I don't fully understand everything I make simple mistakes (That I usually correct later).

I load the map in chunks because I understood it wrong.
For whatever reason, I was thinking if I wanted to show the tilemap on screen with the windows.draw() I would have to load the map I want every time, or else it would always show the full map. but that doesn't make much sense I realize now.

What I should do is, load the full map ONCE and then, show ONLY the part i need. Is that the correct way?
Of course, I will update the map when it needs to, like when I destroy an object.

EDIT: Lately I have been trying to solve problems the wrong way. The problem was I was drawing the full map, instead of changing how I draw it, I changed it to load a smaller map.

8
General / When should I update my tilemap
« on: January 30, 2018, 02:59:20 pm »
Short version:

I have a map of 30 x 20 tiles (32x32px).
the view shows 15x10 tiles at a time (will show partial tile if the view moves only a few px).
I load only 16x11 map, so its "view + 1".

When should I update my 16x11 map? (call the "load" from the tilemap class in the tutorial)
 - 1 - every time before I draw the map to screen (every frame).
 - 2 - After I move the view.
 - 3 - When the view passes a certain point (like ½ the next tile), so it loads only 15 times when going from side to side.

I'm using 2, but think 3 should be better. but may have problems I don't know about.

Detailed Version:

I'm learning how to use tilemaps (used the tutorial in "learn" section), I'm trying to do things on my own so I learn and when it all works, look into the proper way of doing things. But this question keeps poping in my mind, so let me ask it. I did a search, but didn't find an answer.

I have a map of 30 x 20 tiles (32x32px).
the view shows 15x10 tiles at a time (will show partial tile if the view moves only a few px).
I load only 16x11 map, so its "view + 1".

When should I update my 16x11 map? (call the "load" from the tilemap class in the tutorial)
 - 1 - every time before I draw the map to screen (every frame).
 - 2 - After I move the view.
 - 3 - When the view passes a certain point (like ½ the next tile).

Right now I'm using - 2 -. But since the camera can move only a few px at a time, when going from left to right or right to left the full map length it updates around 115 times... even though there are only 15 "new tiles" (The view cant go outside the 30x20 map) .
It updates 79 times from bot to top and 33 from top to bot (the movement is different, thats why the values are different)

Should I try to implement way - 3 - so It only updates 15 times going from side to side and 10 times when going from bot to top? Is that the proper way of doing it?

Thank you for your time.

9
EDIT: Can someone please delete the old topic since I can't do it myself? Thank you. sorry for the trouble. This one.

Hi there, I have 2 bugs in my game. I tried to explain it before, but was a long and dumb explanation.

In the "simple" (couldn't make it smaller) code bellow there are 2 issues:

1. - if you click the options text, the new window open, if you click that window it closes. But then it doesn't recognize any mouse clicks until I move the mouse. Its a strange behavior I cant solve on my own.
PS: You can make it work the other way around, so its window 2 that wont recognize clicks until you move the mouse.


2. - If you start the program and press controller button 1, the 2nd window will open and instantly close. After that it works as intended, press & hold the button, the new window will only open. release, press again and it will close.
But if you open & close the 2nd window using the ENTER key the bug happens again. You press the controller button and the window will open and insta close.

Hope someone can help me with this silly problem.
Thank you for your time!

Full test code that replicates both problems:
(click to show/hide)

10
General / Re: Some newbie questions
« on: July 26, 2017, 02:35:09 pm »
Thank you so much! That helps a lot.

I have to handle input differently it seams. That actually makes sense, and will help with what I plan to do next. I wasn't sure how to do what I will need yet, but now I know.

I do have a state machine, but its simple and I am not using it correctly. I don't fully understand them yet (I will be adding more functionality as I understand it and get more experience working with them).
ATM my states are basically different game screens. Like, menu, highscore and game. The states have "initialization" "handle input" "update" and "draw". They are not really "game states" like.. is jumping or has a power up.

For some reason I didn't think of "paused game" as a different state, but it does make sense.

I also didn't implement "pause" "resume" for a state, since I don't understand it too well, and doesn't make sense (to me), the way I use my machine atm. My states are a stack and only the one on TOP runs, when I remove the top, if there is one bellow it will resume automatically.

Again, thank you so much! You helped me understand some things a little better :)
I still have a lot to learn, but I'm having so much fun.
Oh and your "Small game engine" also helped, I didn't fully understand it, but helped me create my simple one.


11
General / Some newbie questions
« on: July 25, 2017, 05:52:09 pm »
I finally looked into state machines and made one, then ported my previous game (first SFML project) to it. Everything is working fine, but while porting it I got some questions that maybe I can get an answer to here.

Please note I don't need help, the game works, these are for future reference, to be honest don't know where to ask, so I will try it here.
I don't want to waste anyone's time, these are dumb questions, they came from my lack of programing and game creation knowledge.
Thank you if you decide to read it anyway.

SFML Relate Q:

1. - Should I always draw the screen every frame? Even for screens that never changes, like a High Score list screen. If I only display it once, the only "problem" is if I minimize the window, and it comes back it won't show anything but thats fixable with a "on minimize draw again".
Or drawing it uses so little resources anyway that its pointless to stop it (using a if(bool) in the drawing method.

1.5 - If I draw several lines of text on screen, like on a High Score screen, should I have a SF::text for every line, or use only one, have a string[] to save the strings and a for loop to display them in place.

2. - In my game I earn points every second, except when the game is paused. Since I can't pause a clock, every second I add 1 to a counter Var and restart the clock. So when I pause, it still only counts a sec. Is this a good way to do it? Or there's a smart way I couldn't think of.

3. - The only problem in my game is controls.  Here's some of it
sf::Event evt;
while (window.pollEvent(evt)) {
if (evt.type == sf::Event::KeyPressed)
     switch (evt.key.code) {
          case sf::Keyboard::P:
                if(paused)
                     unpause
                else
                     pause
          case sf::keyboad::W:
                blablabla...

If I press and hold P it pauses/unpauses the game every frame. I can solve this with a bool. (I don't like the "on key release", I like the responsiveness of "do it on keydown", because sometimes you hold the key just a little longer). I only pause/unpause if the bool is true. As soon as "keypressed" I set it to false, when key is release, I set it to true.

The real problem is... My game is a snake clone, so when I go right, I can't turn left before going up or down.
But, if I while going right, I press up then quickly left, I can move from left to right. I don't know how to solve this.
If I use the bool method, the game doesn't feel very responsive. And I think it still sometimes happens, its just harder to do.
If I use a clock and only process input every X ms... again, the controls don't feel responsive. Maybe I haven't found the right ms timing for it.
How could I solve this? I cant thin of a good solution.

NON SFML Q:
As I said, these are dumb questions from my lack of knowledge, feel free to laugh and ignore them.

4. - I use PRAGMA ONCE on my .hpp files. a.hpp includes b.hpp and c.hpp. But then d.hpp includes a.hpp but also b.hpp, that was included in a.hpp... its a mess.
It works, but should I leave it as a mess? (maybe thats how its supposed to be) or should I use a "hppList.hpp" put all of them inside, and include this list only one in the main?

5. - In my game I have to sometimes wait for 1 second in that place before proceding with the code.
I use while (timer.getElapsedTime().asMilliseconds() < 1250) {}.
Is there a better way to pause the code? Ive done it before, but not on c++ and can't remember how.

6. - I don't check for errors, all the textures/soundbuffers/fonts work and load correctly.
The game will work, unless you move/delete the assets. But if you do, its not my fault. Reinstall it.
Still, is it the wrong thing to do? IS there a point of showing a error saying the game crashed because it can't load a texture/whatever when it was the users fault?

7. - I have a lot of warnings (around 15), most of them from "int to float conversion".
Should I try fix those or ignore them since the game works and actually no useful info is lost in the conversion.

If you read this far, thank you for your time, sorry for the wall of text boss.


12
General / Re: can't save game on install dir
« on: June 29, 2017, 07:10:50 pm »
Mind taking a look at how I created the folder to see if there's anything really wrong with it?

Its working (at least on my computer, didn't have a chance to test it on another) but its my first time using these and to be honest I don't fully understand it. It was kinda of a nightmare to get it to work, since there is so many variations out there. I had no idea which one to use nor WHY use it.
- getfolderpath | getknownfolderpath | getspecialfolderpath | GetEnvironmentVariable

Anyway as long as its not really wrong, I will leave it as it is and add this to the list of thing I really need to learn about in the future.

        TCHAR szPath[MAX_PATH];
        if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA, NULL, 0, szPath)))
        {
                // Append product-specific path
                PathAppend(szPath, _T("\\Lkc\\"));
                CreateDirectory(szPath, NULL);
        }
        PathAppend(szPath, _T("saveData.dat"));
        std::string hhh;
        hhh.clear();
        for (int i = 0; i < MAX_PATH; i++) {
                hhh += szPath[i];
        }
        vEcras[5]->fichPath = hhh;
        vEcras[3]->fichPath = hhh;
        vEcras[1]->fichPath = hhh;
 

13
General / Re: can't save game on install dir
« on: June 28, 2017, 04:47:49 pm »
I see, so thats indeed why.
I will try writing it there, since learning how to do so is useful.

Thank you!

14
General / can't save game on install dir
« on: June 28, 2017, 03:17:42 pm »
I'm not sure if its ok to ask a non SFML question here (the "read before posting" didn't say), if it isn't please tell me (so I learn) and I will delete it myself.

I finished my SFML test game (a snake clone), it was a fun and enjoyable experience. But I have a small problem I would like help with.

After installing the game, I can only save my game score if I run the game as admin mode. It reads it fine, but doesn't write.
- I created the install files using installshield on visual studio 2015.
- I create the file using ofstream
- the file is created in the install folder (install folder: C:\Program Files (x86)\Lkc)
- I'm using windows 10.
- Can't write to file even if the file already exists.
- Its a .dat file.
- it works fine on the visual studio, not sure if because it runs in admin mode, or because its saved at my docs.

Whats the best way to solve this problem?
Should I try grant the file permission to write? (To be honest after googling it for hours, I have no clue how to do that).
Should I save the file in some other place? Where would it be best/usual? (After googling it, no success using "CreateDirectory", can't give it a path and no example online worked for me, they're too old I think)

If anyone cal help I would really appreciate it.

Thank you for the time you took to read this.

15
Window / Re: whats the best/correct way to use multiple screens
« on: June 06, 2017, 03:36:32 pm »
Oh I see. It seams I misunderstood the "state machine" meaning. I didn't have time to look at the examples he provided yet. But your explanations made it simple to understand.

Thank you! I thought that might be the "correct" way to do things, I guess it truly is.
Thank you both! :)

Pages: [1] 2
anything