• What do you need help with? V. 3.0
    4,884 replies, posted
Using java, is it a good idea to have a class called 'Values' that contains all my globally-used constants and variables like gamestate, gametime, physics constants etc?
I fixed my crash when the game window wasn't in focus a lot faster than i expected. The frame rate was going ballistic while out of focus which caused the error. [csharp] spriteBatch.DrawString(hitfont, "FPS "+ Convert.ToInt32(frameRate), new Vector2(9, 380), Color.FromNonPremultiplied(10, 10, 10, 40)); [/csharp] That is the line of code that caused the exception, is there a way of getting the frame rate or converting this Float to an Integer that doesn't end in an exception? How I got the frame rate [csharp] float frameRate = 1 / (float)gameTime.ElapsedGameTime.TotalSeconds; [/csharp] You cant use an underline tag in a code tag? That's unfortunate.
I'm trying to add Farseer in my XNA game. I added an existing project and brought it in. When I put this: [code] using FarseerPhysics; [/code] It says can't find the namespace Any ideas why?
[QUOTE=Nigey Nige;31842053]Using java, is it a good idea to have a class called 'Values' that contains all my globally-used constants and variables like gamestate, gametime, physics constants etc?[/QUOTE] For a small one-man project where you just want to get stuff done without worrying about a sustainable and scalable design, you can pretty much do whatever you want. However, if it's not a small project, not a one-man project, or done with the intention of learning, then you should definitively strive to write idiomatic Java, so the answer is generally a big "no". Globals are really bad for the [url=http://en.wikipedia.org/wiki/Coupling_(computer_programming)]coupling[/url] in your program. The Java thing to do is expose only the functionality strictly required for a particular class. For example, if your game state object is responsible for handling the physics simulation, have it either receive and keep the physics handling object on creation or have it create it on its own, or some other strategy for transferring ownership. By keeping each class' responsibility clear and cohesion high, the code is easier to read and reason with, reducing bugs in your program as well as not hampering scalability. The above advice can sometimes be hard to follow if your classes don't have clear responsibilities. Remember, a class should usually do just one thing, and do it well. For example, if you suddenly find that your physics simulation class depends on your rendering class, you have a bad dependency implying that either of the two classes are doing too much and that functionality should be factored out into a different, perhaps new, class. I tried to keep it short even though it's a big subject, I hope it wasn't all just confusing. (The above advice works for pretty much every programming environment except replace "class" with something more general like "module")
[QUOTE=jA_cOp;31842616]For a small one-man project where you just want to get stuff done without worrying about a sustainable and scalable design, you can pretty much do whatever you want. However, if it's not a small project, not a one-man project, or done with the intention of learning, then you should definitively strive to write idiomatic Java, so the answer is generally a big "no". Globals are really bad for the [url=http://en.wikipedia.org/wiki/Coupling_(computer_programming)]coupling[/url] in your program. The Java thing to do is expose only the functionality strictly required for a particular class. For example, if your game state object is responsible for handling the physics simulation, have it either receive and keep the physics handling object on creation or have it create it on its own, or some other strategy for transferring ownership. By keeping each class' responsibility clear and cohesion high, the code is easier to read and reason with, reducing bugs in your program as well as not hampering scalability. The above advice can sometimes be hard to follow if your classes don't have clear responsibilities. Remember, a class should usually do just one thing, and do it well. For example, if you suddenly find that your physics simulation class depends on your rendering class, you have a bad dependency implying that either of the two classes are doing too much and that functionality should be factored out into a different, perhaps new, class. I tried to keep it short even though it's a big subject, I hope it wasn't all just confusing. (The above advice works for pretty much every programming environment except replace "class" with something more general like "module")[/QUOTE] That's a terrifying post, but I'll remember it for when I get a bit more experience under my belt. Thanks, dude.
[QUOTE=ThePuska;31838229]you call SetUpVertices() before LoadHeightData(), which causes the former to use heightData before it's initialized, i.e. it's still a null reference.[/QUOTE] Oh god, thank you so much. It works perfectly now, I can't believe I missed that. [img]http://i.imgur.com/wkthH.png[/img]
Ok this will probs be piss easy for all you guys but I'm having some serious trouble with this. It's an exam question for a past exam paper I have to resit. Heres the question: [quote] Using the method from part (b), write a method called consonantsonly( ) which takes a string parameter and returns the string with all the vowels removed[/quote] I keep getting errors on the if statement saying things are not defined and all and I have no idea what I am doing to be honest, would appreciate any help. And here is my code for the rest of it: [code]public class Q2 { public static String lettersOnly(String s){ String letters = ""; for(int i = 0; i < s.length(); i++){ if(Character.isLetter(s.charAt(i))== true){ letters = letters + s.charAt(i); } } return letters; } public static boolean isVowel(char c){ boolean vowel = false; if(c == 'a' || c == 'e'|| c == 'i'|| c == 'o'|| c == 'u') return true; else return false; } public static String consonantsOnly(String a){ String letters = ""; for(int i = 0; i < a.length(); i++){ if(a.charAt(i)== a.isVowel(false)) letters=letters + a.charAt(i); } return letters; } public static void main (String [] args){ System.out.println("Enter a line of text:"); String str = Console.readString(); System.out.println(consonantsOnly(str)); //System.out.println(lettersOnly(str)); //System.out.println("Enter a letter or letters"); //char c = Console.readChar(); //System.out.println(isVowel(c)); } }[/code]
[QUOTE=Over-Run;31849255]Ok this will probs be piss easy for all you guys but I'm having some serious trouble with this. It's an exam question for a past exam paper I have to resit. Heres the question: I keep getting errors on the if statement saying things are not defined and all and I have no idea what I am doing to be honest, would appreciate any help. And here is my code for the rest of it: [code]public class Q2 { public static String lettersOnly(String s){ String letters = ""; for(int i = 0; i < s.length(); i++){ if(Character.isLetter(s.charAt(i))== true){ letters = letters + s.charAt(i); } } return letters; } public static boolean isVowel(char c){ boolean vowel = false; if(c == 'a' || c == 'e'|| c == 'i'|| c == 'o'|| c == 'u') return true; else return false; } public static String consonantsOnly(String a){ String letters = ""; for(int i = 0; i < a.length(); i++){ if(a.charAt(i)== a.isVowel(false)) letters=letters + a.charAt(i); } return letters; } public static void main (String [] args){ System.out.println("Enter a line of text:"); String str = Console.readString(); System.out.println(consonantsOnly(str)); //System.out.println(lettersOnly(str)); //System.out.println("Enter a letter or letters"); //char c = Console.readChar(); //System.out.println(isVowel(c)); } }[/code][/QUOTE] It should be if ( isVowel( a.charAt(i) ) == false )
[QUOTE=Darwin226;31850173]It should be if ( isVowel( a.charAt(i) ) == false )[/QUOTE] You don't need ==true or ==false, just remove the ==true and use !<statement> for ==false
What's the formula for determining the position of a single point in 3D space to be rendered on a 2D surface, with camera location and rotation are relevant? I'm not using OpenGL or DirectX or any other API, just plain old C/C#/C++
[QUOTE=Hypershadsy;31852908]What's the formula for determining the position of a single point in 3D space to be rendered on a 2D surface, with camera location and rotation are relevant? I'm not using OpenGL or DirectX or any other API, just plain old C/C#/C++[/QUOTE] Some sines and cosines with numbers in them, of some sort. Kirupa had a thing on it [editline]20th August 2011[/editline] [url]http://en.wikipedia.org/wiki/3D_projection#Perspective_projection[/url]
[QUOTE=Map in a box;31854744]Some sines and cosines with numbers in them, of some sort. Kirupa had a thing on it [editline]20th August 2011[/editline] [url]http://en.wikipedia.org/wiki/3D_projection#Perspective_projection[/url][/QUOTE] Dear lord that looks complicated. Well, I'll get this working eventually.
Just a pedantic question... if I'm making some random Windows Forms application, is there a time when I should use C++ for it, and a time when I should use C#...? Or should I use C# pretty much most the time? (I'm aware C++ is more cross-platform than C#, but I'm not worried about that the moment. :smile:)
I want an elasticated rope to run between two 3D points...Where should I start with the maths? [QUOTE=Chrispy_645;31856925]Just a pedantic question... if I'm making some random Windows Forms application, is there a time when I should use C++ for it, and a time when I should use C#...? Or should I use C# pretty much most the time? (I'm aware C++ is more cross-platform than C#, but I'm not worried about that the moment. :smile:)[/QUOTE] Well winforms isn't cross platform anyway so, just use C#
[QUOTE=CarlBooth;31858448]I want an elasticated rope to run between two 3D points...Where should I start with the maths? Well winforms isn't cross platform anyway so, just use C#[/QUOTE] I think he will even get further with cross platformness if he uses C# and winforms since Mono.
My entry for Ludum Dare seems to have sprouted thousands of stupid crashes, ranging from variables not be initalised properly, sf::RenderTarget::Clear crashing, heap corruptions and everything. I've wasted too much time looking for the error, does anyone know what I can do to try and fix this? If I can't then I'm out of the competition for good because there's no way I can fix this on my own, I have no idea where to start.
Another easy one I just can't get my head around. What I have to do is read a String in from the user, and return it when any duplicate sequence of characters removed. For example, Hello, would be Helo, and Rrrraaawr would be rawr. Here is the code I got so far. [code] public static String removeDupes(String b){ String letters = ""; for(int i = 0; i < b.length(); i++){ if(b.charAt(i)== b.charAt(i + 1)) letters = letters + ""; else letters = letters + b.charAt(i); } return letters; }[/code] Its probably laughable that I can't get my head around this ha, I'm hoping its only a simple mistake I made.
[QUOTE=Chris220;31858570]My entry for Ludum Dare seems to have sprouted thousands of stupid crashes, ranging from variables not be initalised properly, sf::RenderTarget::Clear crashing, heap corruptions and everything. I've wasted too much time looking for the error, does anyone know what I can do to try and fix this? If I can't then I'm out of the competition for good because there's no way I can fix this on my own, I have no idea where to start.[/QUOTE]Try Valgrind, maybe? I'm not sure if it does what you need, but I've used it to find memory leaks and stuff in the past.
[QUOTE=ROBO_DONUT;31858600]Try Valgrind, maybe? I'm not sure if it does what you need, but I've used it to find memory leaks and stuff in the past.[/QUOTE] Is there anything like that for Windows? Or am I gonna have to setup a Linux distro in a virtual box and run my program through WINE or something? :suicide:
Thought it was cross-platform :v: Sorry.
[QUOTE=Over-Run;31858592]Another easy one I just can't get my head around. What I have to do is read a String in from the user, and return it when any duplicate sequence of characters removed. For example, Hello, would be Helo, and Rrrraaawr would be rawr. Here is the code I got so far. [code] public static String removeDupes(String b){ String letters = ""; for(int i = 0; i < b.length(); i++){ if(b.charAt(i)== b.charAt(i + 1)) letters = letters + ""; else letters = letters + b.charAt(i); } return letters; }[/code] Its probably laughable that I can't get my head around this ha, I'm hoping its only a simple mistake I made.[/QUOTE] I personally would use the first occurence of the character and then ignore the following ones, but it probably makes no difference :v: [code] public static String removeDupes(String b){ String letters = ""; for(int i = 0; i < b.length(); i++){ if(i == 0 || b.charAt(i) != b.charAt(i - i)) letters = letters + b.charAt(i); } return letters; }[/code]
[QUOTE=thf;31858715]I personally would use the first occurence of the character and then ignore the following ones, but it probably makes no difference :v:[/QUOTE] You see I have no idea how to do that I keep trying different things and it just isn't working. I don't know what I would let letters equal to if it was a duplicate. Any help?
[QUOTE=Over-Run;31858739]You see I have no idea how to do that I keep trying different things and it just isn't working. I don't know what I would let letters equal to if it was a duplicate. Any help?[/QUOTE] If it's a duplicate, nothing should happen to letters, because you don't need to append anything.
[QUOTE=thf;31858770]If it's a duplicate, nothing should happen to letters, because you don't need to append anything.[/QUOTE] I sort of understand, I just tested that code you gave me and when I wrote in rrraaaawwrrr it gave me raaaaww, so it sort of works but not for all of it
[QUOTE=Over-Run;31858812]I sort of understand, I just tested that code you gave me and when I wrote in rrraaaawwrrr it gave me raaaaww, so it sort of works but not for all of it[/QUOTE] Actually that's very strange. I'll look closely at the code to see what's wrong with it. [editline]1:11[/editline] Just saw my fault, it was a small typo :v: Try this: [code] public static String removeDupes(String b){ String letters = ""; for(int i = 0; i < b.length(); i++){ if(i == 0 || b.charAt(i) != b.charAt(i - 1)) letters = letters + b.charAt(i); } return letters; }[/code] The typo was that i wrote i - i instead of i - 1 :v: Small mistake on my part which made it act completely wrong.
[QUOTE=thf;31858831]Actually that's very strange. I'll look closely at the code to see what's wrong with it.[/QUOTE] Cool man cheers really appreciate it The only thing I was wondering is, see where you said if(i == 0 || b.char blah blah blah), is that because the code wouldn't work otherwise since it would start at 0 and then take 1 from it? Therefore going out of bounds? Just trying to understand the logic in it because I'm pretty bad at programming.
[QUOTE=Over-Run;31858837]Cool man cheers really appreciate it The only thing I was wondering is, see where you said if(i == 0 || b.char blah blah blah), is that because the code wouldn't work otherwise since it would start at 0 and then take 1 from it? Therefore going out of bounds? Just trying to understand the logic in it because I'm pretty bad at programming.[/QUOTE] You are completely right. If it's at index 0 there can't be anything before it anyway, so it can't be a duplicate. And because of lazy evaluation it's also a protection against going out of bounds.
[QUOTE=ROBO_DONUT;31858652]Thought it was cross-platform :v: Sorry.[/QUOTE] No problem :P I've been poking around a bit, the error itself is: [code]Windows has triggered a breakpoint in ld21.exe. This may be due to a corruption of the heap, which indicates a bug in ld21.exe or any of the DLLs it has loaded. This may also be due to the user pressing F12 while ld21.exe has focus. The output window may have more diagnostic information.[/code] The output window says: [code]HEAP[ld21.exe]: HEAP: Free Heap block 612e228 modified at 612e260 after it was freed[/code] How can I go about finding what modified that block after it was freed?
Heres another one [code] Write a method called middlePosition( ) which takes an array of integers and returns a boolean value, true if the middle element in the array is correctly positioned and false otherwise. For example, if the array was { 2 , 7 , 4 , 8, 1 } , then the method would return true , because 4 would be in the same place if the array was sorted. Hint: it may be useful to count the number of elements which are less than the middle element[/code] We always have to assume the number of elements in the array will be different and also odd. The way I would presume you would do it would be to have the array unsorted equal to one array, and then make a second array where it is sorted, and just compare to two!? Would that be correct?
[QUOTE=Over-Run;31859627]Heres another one [code] Write a method called middlePosition( ) which takes an array of integers and returns a boolean value, true if the middle element in the array is correctly positioned and false otherwise. For example, if the array was { 2 , 7 , 4 , 8, 1 } , then the method would return true , because 4 would be in the same place if the array was sorted. Hint: it may be useful to count the number of elements which are less than the middle element[/code] We always have to assume the number of elements in the array will be different and also odd. The way I would presume you would do it would be to have the array unsorted equal to one array, and then make a second array where it is sorted, and just compare to two!? Would that be correct?[/QUOTE] I'd read their hint. You should first get the middle value. Then loop through the array and counts the numbers which are less than or equal to it. Then check if that equals the index of the middle element.
Sorry, you need to Log In to post a reply to this thread.