• What do you need help with? Version 5
    5,752 replies, posted
Code::Blocks just has a stupid parser [editline]24th January 2013[/editline] Also that font hurts.
[QUOTE=Dr Magnusson;39341283]Wait, is this actually causing a problem? Is it calling ios::clear instead of the SFML one?[/QUOTE] I don't know for sure. That's what it seems like from the build-log to me, but I'm pretty inexperienced with this stuff so I can't say for sure. [QUOTE=WeltEnSTurm;39341336]Also that font hurts.[/QUOTE] Yes, it does. I just re-installed it so I haven't customized too much yet. [editline]Edit[/editline] Okay, after fumbling around for a bit I managed to get it to compile and run properly, but I had to remove anything referring to move or rotate. It might not be doing what I think it is but there's still something wrong that I can't figure out so any sort of help would be great.
[QUOTE=Kabscure;39341494]I don't know for sure. That's what it seems like from the build-log to me, but I'm pretty inexperienced with this stuff so I can't say for sure. Yes, it does. I just re-installed it so I haven't customized too much yet. [editline]Edit[/editline] Okay, after fumbling around for a bit I managed to get it to compile and run properly, but I had to remove anything referring to move or rotate. It might not be doing what I think it is but there's still something wrong that I can't figure out so any sort of help would be great.[/QUOTE] If your program isn't acting wacky, and it compiles fine, then it's probably just the highlighter that's fucking up. If you're importing the std namespace (ie using namespace std;), then perhaps you can solve it by removing that line and referring to the function by their full name. It's much more likely that the highlighter is just having a bad day, and this is all an aesthetic issue you can ignore.
[QUOTE=Dr Magnusson;39341653]If your program isn't acting wacky, and it compiles fine, then it's probably just the highlighter that's fucking up. If you're importing the std namespace (ie using namespace std;), then perhaps you can solve it by removing that line and referring to the function by their full name. It's much more likely that the highlighter is just having a bad day, and this is all an aesthetic issue you can ignore.[/QUOTE] Clear works fine so it's probably just the highlighter on that one, but move and rotate still refuse to compile for some reason. I'm not using namespace std, it was the first thing I checked for. I'm pretty sure now that the issue is not what I thought it was, but I still need some help finding out what it is then. [editline]Edit[/editline] OH. Apparently I screwed up recoding my template to work with the new SFML beta and tried to use sf::Time as a regular int inside the move & rotate functions, causing that weird error. Whoops. [editline]Edit 2[/editline] Yup, just added .asSeconds() on the end of ElapsedTime and it works fine. I should learn to read the manual.
how do you guys handle colisions on 2d games? draw a black/white map, checking for the next color is a good way?
[QUOTE=Mete;39342138]how do you guys handle colisions on 2d games? draw a black/white map, checking for the next color is a good way?[/QUOTE] I use various algorithms depending on the needs. For rectangles I use AABB's. For circles I just check the distance between the centers. For anything more complicated I usually take advantage of [URL=http://en.wikipedia.org/wiki/Hyperplane_separation_theorem]separating axis theorem[/URL].
[QUOTE=robmaister12;39338140]In what language?[/QUOTE] C++/OpenGL
[QUOTE=Topgamer7;39339045]Read the second response from [URL="http://stackoverflow.com/questions/5919143/is-it-safe-not-to-close-a-java-scanner-provided-i-close-the-underlying-readable"]this[/URL] stack overflow page. It states that if you close the scanner, it will close your underlying stream. I would imagine because you're creating the Scanner in a method, once the scope is finished, Java will dispose of it. Don't quote me on that.[/QUOTE] i get a warning from eclipse about resource leaks because i'm not calling close() on the Scanner. is there any method less headache inducing for simply reading in a line of user input from the console?
I've used C+ for a long time, but I never thought about this until using java for a while. Say you have a class, which contains another class instance inside of it that has initializes. Now, what I used to do was declare the instance, then in the initializer assign it some value. However, I feel like this does double the work (creates a normal instance, then creates a new one with the assigned values and changes the value of the normal instance to that). Should I still use this or use an initalizer list?
[QUOTE=twoski;39343221]i get a warning from eclipse about resource leaks because i'm not calling close() on the Scanner. is there any method less headache inducing for simply reading in a line of user input from the console?[/QUOTE] Just close it when you no longer need it then? The last time I used a scanner was more than a year ago, I don't remember closing the scanner back then. I used Netbeans at the time, perhaps netbeans complains less than eclipse. In any case, it's just a warning, you could always ignore it and not close the scanner.
Does anyone here have much experience with DirectX 11 and a bit of time to help me out on Steam? I would just ask my question(s) here but I don't particularly want to make my code public just yet since it's for a university assignment.
can anybody help a beginner out with a simple arraylist problem in java? I'm just trying to learn some major differences between arrays and arraylists. Anyway I've figured out how to sort an array from smallest to largest, but I can't figure out how to do this for an arraylist? (the arraylist is full of ints, that is).
Is there a way in C++ to create a function pointer with default values? That is, say I have a function move(int) and the integer would represent the direction, however my function pointer would have no inputs. Could I create a pointer to function move(5) or something like that, so that it would still count as a pointer with no parameters? If not, then can I create a function inside scope of a code, so like void func(){move(5)} and then just point to that?
Where can I find a good dictionary for a word game? Technically it only needs to be a word list, but it would be really awesome if each (or some?) words also had a short definition. I've tried some Scrabble and Linux dictionaries but kept running into blatantly invalid/missing words.
Alright, I'm having some more troubles with SFML now. I'm running this code: [cpp]tileToLoad << "tileTexture_" << testLevel.levelTileData[row][col]; tileSprite.setTexture(tileToLoad.str().c_str()); tileSprite.setPosition(row * 32, col * 32); App.draw(tileSprite);[/cpp] To try and draw my level onscreen, and the way it's supposed to work is if in the 2D array that position has a 1 in it, it's supposed to do tileSprite.setTexture(tileTexture_1) - if it has a 2, it's supposed to do tileSprite.setTexture(tileTexture_2) and so on. For this I tried using a StringStream to take the number in that location in the 2D array and slap it at the end of "tileTexture_" and then put that stringStream into tileSprite.setTexture, however my compiler complains saying that that function needs a sf::Texture, not a std::StringStream or char. Is there another way of doing this, then?
[QUOTE=Kabscure;39346855]Alright, I'm having some more troubles with SFML now. I'm running this code: [cpp] tileToLoad << "tileTexture_" << testLevel.levelTileData[row][col]; tileSprite.setTexture(tileToLoad.str().c_str()); tileSprite.setPosition(row * 32, col * 32); App.draw(tileSprite);[/cpp] To try and draw my level onscreen, and the way it's supposed to work is if in the 2D array that position has a 1 in it, it's supposed to do tileSprite.setTexture(tileTexture_1) - if it has a 2, it's supposed to do tileSprite.setTexture(tileTexture_2) and so on. For this I tried using a StringStream to take the number in that location in the 2D array and slap it at the end of "tileTexture_" and then put that stringStream into tileSprite.setTexture, however my compiler complains saying that that function needs a sf::Texture, not a std::StringStream or char. Is there another way of doing this, then?[/QUOTE] You could load the textures into a vector and set them from there. Something like this: [cpp] std::vector<sf::Texture> textures; // Load textures into the vector. ie: sf::Texture mytex; mytex.loadFromFile("mytexture.jpg"); textures.push_back(mytex); ... tileSprite.setTexture(textures[testLevel.levelTileData[row][col]]); ... [/cpp]
[QUOTE=WTF Nuke;39346827]Is there a way in C++ to create a function pointer with default values? That is, say I have a function move(int) and the integer would represent the direction, however my function pointer would have no inputs. Could I create a pointer to function move(5) or something like that, so that it would still count as a pointer with no parameters? If not, then can I create a function inside scope of a code, so like void func(){move(5)} and then just point to that?[/QUOTE] The former is almost definitely impossible. Adding default arguments to a function doesn't actually change its signature, it just changes how the compiler looks for the right function call. The latter would definitely work, though I have to question your use case. I would try to avoid such code myself.
[QUOTE=WTF Nuke;39346827]Is there a way in C++ to create a function pointer with default values? That is, say I have a function move(int) and the integer would represent the direction, however my function pointer would have no inputs. Could I create a pointer to function move(5) or something like that, so that it would still count as a pointer with no parameters? If not, then can I create a function inside scope of a code, so like void func(){move(5)} and then just point to that?[/QUOTE] auto fn = [](){ move(5); }; If move is a member function you'll have to put = or & inside the [] [url]http://en.wikipedia.org/wiki/Anonymous_function#C.2B.2B[/url]
[QUOTE=Dr Magnusson;39346926]You could load the textures into a vector and set them from there. Something like this: [cpp] std::vector<sf::Texture> textures; // Load textures into the vector. ie: sf::Texture mytex; mytex.loadFromFile("mytexture.jpg"); textures.push_back(mytex); ... tileSprite.setTexture(textures[testLevel.levelTileData[row][col]]); ... [/cpp][/QUOTE] That's the way to do it, but it might be more efficient to take it a step further: load a vector of sprites and draw them at different positions. Working with textures is generally quite slow.
[QUOTE=Larikang;39346852]Where can I find a good dictionary for a word game? Technically it only needs to be a word list, but it would be really awesome if each (or some?) words also had a short definition. I've tried some Scrabble and Linux dictionaries but kept running into blatantly invalid/missing words.[/QUOTE] [url]http://www.morewords.com/[/url] Really, really thorough. Their dictionary is available [URL=http://www.morewords.com/enable2k.txt]here[/URL]. [QUOTE=True_colors;39346698]can anybody help a beginner out with a simple arraylist problem in java? I'm just trying to learn some major differences between arrays and arraylists. Anyway I've figured out how to sort an array from smallest to largest, but I can't figure out how to do this for an arraylist? (the arraylist is full of ints, that is).[/QUOTE] [url]http://stackoverflow.com/questions/890254/how-can-i-sort-this-arraylist-the-way-that-i-want[/url]
[QUOTE=Dr Magnusson;39346926]You could load the textures into a vector and set them from there. Something like this: [cpp] std::vector<sf::Texture> textures; // Load textures into the vector. ie: sf::Texture mytex; mytex.loadFromFile("mytexture.jpg"); textures.push_back(mytex); ... tileSprite.setTexture(textures[testLevel.levelTileData[row][col]]); ... [/cpp][/QUOTE] I'd still run into the same problem, no? I'd want to automate loading all my textures ( mytex.loadFromFile("mytexture.jpg"); ) in order so it would load tex1.png, tex2.png, tex3.png and so on. And if I tried to do that it would just complain at me about trying to feed a stringStream into a function which needs something else again. Is there not a way around this? Cause the main problem here is that I'm feeding the name of a sf::Texture from a stringStream, causing it to thing it's not referring to a sf::Texture. [editline]Edit[/editline] I just found out I can just load tileset into the game and use setTextureRect() but still, is there not a way to feed a stringStream into a function like that? What if I have to load like, a hundred different files sequentially named? Would I just have to input the code, one by one?
[QUOTE=Larikang;39346928]The former is almost definitely impossible. Adding default arguments to a function doesn't actually change its signature, it just changes how the compiler looks for the right function call. The latter would definitely work, though I have to question your use case. I would try to avoid such code myself.[/QUOTE] I want to create an input class, but have the whole input getting encapsulated, and just make it so that if a button is pressed, a function will be executed. Such a function could be to move, however I don't want to create functions like moveLeft, moveRight.
[QUOTE=Kabscure;39347040]I'd still run into the same problem, no? I'd want to automate loading all my textures ( mytex.loadFromFile("mytexture.jpg"); ) in order so it would load tex1.png, tex2.png, tex3.png and so on. And if I tried to do that it would just complain at me about trying to feed a stringStream into a function which needs something else again. Is there not a way around this? Cause the main problem here is that I'm feeding the name of a sf::Texture from a stringStream, causing it to thing it's not referring to a sf::Texture. [editline]Edit[/editline] I just found out I can just load tileset into the game and use setTextureRect() but still, is there not a way to feed a stringStream into a function like that? What if I have to load like, a hundred different files sequentially named? Would I just have to input the code, one by one?[/QUOTE] You need to create a Texture object and tell it to load a file [cpp] sf::Texture texture; texture.loadFromFile(tileToLoad.str()); [/cpp]
Is it bad that, on Project Euler, I write really long pieces of code that I figure out got solved with just about 5 in the same language? I mean, I tried problem 2, and got the right answer by adding the numbers generated via calculator (but for some reason when I do it in code it's 8 off??), and then I go to the forum to see why that was. Suddenly all of this [cpp]int main() { int numbers[500]; numbers[0] = 1; numbers[1] = 2; int i = 2; int x = 1; int sum[20]; int y = 0; do { x = numbers[i-2] + numbers[i-1]; numbers[i] = x; if(x % 2 == 0) { cout << x << "\n"; sum[y] = x; y++; } i++; } while( x < 4000000); y = 0; for(i = 0; i < 20; ++i) y += sum[i]; cout << "sum: " << y + 2 << "\n"; system("pause"); return 0; }[/cpp] can just be written as [cpp]total = 0; x = y = 1; do { if (x%2 == 0) total += x; z=x;x+=y;y=z; } while x > 1000000;[/cpp] It's kind of discouraging. Is this just the learning process?
[QUOTE=Meatpuppet;39348913]Is it bad that, on Project Euler, I write really long pieces of code that I figure out got solved with just about 5 in the same language? I mean, I tried problem 2, and got the right answer by adding the numbers generated via calculator (but for some reason when I do it in code it's 8 off??), and then I go to the forum to see why that was. Suddenly all of this [cpp]int main() { int numbers[500]; numbers[0] = 1; numbers[1] = 2; int i = 2; int x = 1; int sum[20]; int y = 0; do { x = numbers[i-2] + numbers[i-1]; numbers[i] = x; if(x % 2 == 0) { cout << x << "\n"; sum[y] = x; y++; } i++; } while( x < 4000000); y = 0; for(i = 0; i < 20; ++i) y += sum[i]; cout << "sum: " << y + 2 << "\n"; system("pause"); return 0; }[/cpp] can just be written as [cpp]total = 0; x = y = 1; do { if (x%2 == 0) total += x; z=x;x+=y;y=z; } while x > 1000000;[/cpp] It's kind of discouraging. Is this just the learning process?[/QUOTE] That's the point of the tasks, to see the way you implanted it and then seeing another 'better' or 'worse' way of implanting it. All part of the learning process, for example I was making an a* algorithm that took 3 times longer to code and work, after looking at other examples I rewrote the entire thing to make a faster better version.
[QUOTE=Meatpuppet;39348913]Is it bad that, on Project Euler, I write really long pieces of code that I figure out got solved with just about 5 in the same language? I mean, I tried problem 2, and got the right answer by adding the numbers generated via calculator (but for some reason when I do it in code it's 8 off??), and then I go to the forum to see why that was. Suddenly all of this It's kind of discouraging. Is this just the learning process?[/QUOTE] It's just kind of seeing what's necessary and what isn't and you will usually figure it out if you give it some more thought, as well as with time.
What exactly is happening here? I understand class inheritance, but why instead of a class name, there is a complete function? _window is [cpp]sf::RenderWindow _window;[/cpp] And the confusing code is [cpp]Application::Application : _window( sf::VideoMode( 800, 600 ), "SFML", sf::Style::Resize | sf::Style::Close ) { // stuff }[/cpp]
That is an initialization list; [url]http://stackoverflow.com/questions/4589237/c-initialization-lists[/url]
[QUOTE=Meatpuppet;39348913]Is it bad that, on Project Euler, I write really long pieces of code that I figure out got solved with just about 5 in the same language?[/QUOTE] You should also check out [url]http://z-trening.com[/url].
I could use some assistance encoding Lua numbers into binary floats/doubles. My previous attempts are rather pathetic and I could use someone who is more experienced in bitwise operation trickery: [code] readFloat = function(self) local a, b, c, d = readBytes(self.handle, 4) local sign = bit.band(d, -128) d = bit.band(d, 127) --local exponent = 1 error("Not implemented", 2) local fraction = bit.bor(a, bit.lshift(b, 8), bit.lshift(bit.band(c, 0x7F), 16)) + 1 return (-1)^sign*fraction*2^(exponent-127) end [/code]
Sorry, you need to Log In to post a reply to this thread.