• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=djjkxbox360;44573185]Can't really say I know a "good" way, but you could manually do it with a loop, moving the coordinates of the button and use something like sleep to decide the speed of it[/QUOTE] sleep is active waiting... don't do that !
[QUOTE=Chizbang;44572342]Im trying to make a Minecraft Server with a functioning status ping in C#. Everything has been going fine-ish so far except I cant figure out how to send the IP of the server in the packets byte array and I have absolutely no idea how VarInts work and what their purpose is (I have read on the protocol wiki and its something to do with the length of the byte? Something to do with it being a prefix? If so, where would I put the VarInts?) and so far have only come across 2 examples of how a VarInt is generated which, because im clinically stupid, I still struggling to get the concept of. First of all though, Im still very confused about the whole thing (im very stupid so bare with me). So far, for the packet structure I have this: [code]byte[] sayThis = new byte[8054]; // Not the correct length, was unsure what to set it to, so I just set it really high just to be safe for now sayThis[0] = (byte)0x00; // Packet ID, is that right? sayThis[1] = (int) 4; // Protocol Version, is this correct? sayThis[2] = myIP; // I still havent figured out how to convert an IP address into a byte. I know your supposed to have an array of bytes with segments of an IP but Im still stuck with that one some how sayThis[3] = (ushort) 25565; // The port, this doesnt work though but I think I know how I can fix that, so this one isnt a problem sayThis[4] = (int) 1; // Next state, for the status JSON on the next packet iirc [/code] Is that the correct structure for a status request packet? I put that together by reading this: [URL]http://wiki.vg/Server_List_Ping[/URL] Where would the VarInt go? Whats the point in VarInt? I really have no clue where they would go. Isnt their purpose to output the length of a byte? If so, where would the VarInt go? Thanks![/QUOTE] According to the article, it seems that VarInts are like regular integers, except they reserve the most significant bit in each byte as a flag to indicate that another byte follows it. This basically means that the smaller the number, the less bytes its VarInt equivalent will take up. This way, VarInts can represent infinitely large numbers, and only use the space they absolutely require. As for serializing IP addresses, each number in the address ranges from 0-255; the same range as a single byte. This means that you can represent an IP address as four bytes. It's quite simple, really.
[QUOTE=Pappschachtel;44573252]sleep is active waiting... don't do that ![/QUOTE] I did say it wasn't a good way v:v:v
Can somebody please help me? I've spent days stuck on this. Basically I'm making something that when you click on the map, it will show you the latitude and longitude of where you've clicked, as well as make a mark (stamp) of where you've clicked. Then the second time you click, it will make another mark and tell you the latitude and longitude, as well as the distance between both points. I'm also trying to make it loop so that after the second click, you can click again and start all over again. So far I have two problems. 1. It doesn't loop. I don't know why. I made 'count' variables to try and make it loop but they're not working. 2. When I click a second time, it only tells me the latitude and longitude. It doesn't tell me the distance between the two. [img_thumb]http://oi59.tinypic.com/zlvyhy.jpg[/img_thumb] Any help would be SO GREATLY APPRECIATED.
Do you have a flowchart of your porgram's ideal structure?
Nah I don't. I can't really do a proper flowchart either, because I thought the way I did it would work, but it doesn't. And I don't know why. My flowchart would only reflect what I've already done.
[QUOTE=Just2Rusty;44585331]Nah I don't. I can't really do a proper flowchart either, because I thought the way I did it would work, but it doesn't. And I don't know why. My flowchart would only reflect what I've already done.[/QUOTE] The way I see your code is that you're not really looping, just doing it twice using a count variable.
It should work like this... When space is clicked, it is assumed variable 'count' = 0. (it doesn't matter if you put a 'set_count=0' block in or not, so i've chosen not to'. Then if you click, it will say lat and long, and stamp, as well as change 'count' to 1. Then you're onto the second set of blocks. Starting with the 'if count>1'.. This is for the second mouse click. After you click again (this is the second click) and it tells you the lat long and distance between the two, it should set count back to 0... Resulting in it looping back to the first if and so on... It doesn't work, so I'm wrong. But I don't understand why it doesn't work because how I've explained it sounds logical to me and sounds like it should work.
as far as i can tell you want the entire thing in a repeat block, as of right now only the first block is being repeated and only when count < 1 which is broken out of on the first click when it sets it to 1
That helps. Putting it all into a forever block helps. I can now click as many times as I like. However, it doesn't display the lat, long and distance on the second click. It displays it on the third click. Why does it do this? It should display the lat and long on the first click, then on the second click, the lat and long and the distance between the two. Then the third time should be treated as the first time. [editline]19th April 2014[/editline] What it looks like now: [img_thumb]http://oi62.tinypic.com/29ddyci.jpg[/img_thumb]
you want it to go 1 2 - distance between 1 & 2 3 - distance between 2 & 3 (3 replaces 1) 4 - distance between 3 & 4 (4 replaced 2) or 1 2 - distance between 1 & 2 3 (clears points except this one) 4 - distance between 3 & 4
How do you mean? The application should work so that I click once. When I click the first time, it will display the latitude and longitude of where I've clicked. Then when I click a second time it should display the latitude and longitude of where I've just clicked, as well as the distance between both first and second click. Then it should repeat, so that if I click a third time, it is treated as though it is the first time I've clicked, looping it all. [editline]19th April 2014[/editline] Right now when I click the first time, it displays the latitude and longitude. When I click the second time, it only displays the latitude and longitude. When I click the third time, (which it should have looped, and the third time should be the new first time)... it displays the latitude and longitude of where I have just clicked (for the third time), as well as the distances between where I have just clicked and where I clicked the second time.
is count being initialized at 1? it would explain the first block being repeat until count > 1, then adding 1 would make it 2 for the next block, which then sets it to 0 so the first block runs twice. try having the second block set it to 1
I got it working! It works! After like four days of working on it. This is how it looks now, in it's working state: [img_thumb]http://oi57.tinypic.com/2ccpfsm.jpg[/img_thumb] Now the first time I click it, it displays lat and long, as it should The second time I click, it displays lat and long of where I've just clicked as well as the distance between. As it should. The third time I click it loops and acts as though it's the first time again. Perfect! All I don't understand and will need clarification is I'm not sure why I need the 'wait until <mouse down = false>' lines of coding. - I just did them because i saw a picture of someone else doing them, and without them it doesn't work. @ Shadaez, thanks for the help. I get what you mean.
wait until mousedown = false would just run the code when you lift the button rather than as soon as you click, it's just how most buttons work. Click reply to this and it won't do it until you let go
Well that makes sense. Thank you heaps for your help. And thank you too, Jookia. Can always rely on this thread to help me out when I need it.
Does anyone have any advice for someone struggling with love2D's printf function? This is giving me a headache. [IMG]http://puu.sh/8eJVL.png[/IMG] The problem is basically summed up by this: The user is supposed to be able to type anything they like in the text input box. To stop it from extending off of the screen, i'm using printf to wrap the text when it gets to a certain point. I'm also trying to make the rectangular "background" for the text wrap with it. This appears to work, but you tend to end up with this case of the text running ahead of the rectangle. In the image, if I had kept writing, it would have caught up and ended up looking normal. Here is the code concerned. There are a few other problems with it, like all the hardcoded x and y values. [code] function love.update(dt) reqlen = const_reqlen - string.len(text) textheight = (font2:getHeight(text)*(math.floor(font2:getWidth(text)/700)+1)+6) end function love.draw() love.graphics.setFont(font1) love.graphics.setBlendMode("subtractive") love.graphics.setColor(40,40,40) love.graphics.rectangle("fill", 15, 15, font1:getWidth("You have to type "..const_reqlen.." more characters")+10, font1:getHeight("You have to type "..const_reqlen.." more characters")+6) love.graphics.rectangle("fill", 55, 65, font2:getWidth(text)+10, textheight) love.graphics.setColor(255,255,255) love.graphics.setBlendMode("alpha") love.graphics.print("You have to type "..reqlen.." more characters", 20, 20) love.graphics.setFont(font2) love.graphics.printf(text, 60, 70, 700 ) love.graphics.draw(cloud, 500,500) end [/code] The way i'm getting textheight is obviously not working, so I was wondering if you guys had any advice?
hi. so i've been using java recently for game dev things, and various stackOverflow questions i've read have told me: -not to mix AWT and swing components -override paint/paintComponent (depending on if its Canvas or JComponent) to perform drawing. however, i have been using a Canvas inside of a JFrame because as far as i know, Canvas is much faster than JComponent due to buffer strategies. Also, I have been using ignoreRepaint as some sources said I should. Additionally, I have been simply fetching the graphics object from my Canvas object (ex: (Graphics2D)renderTarget.getGraphics() ) and using that to draw, as opposed to doing it in the overridden paint method. Should I be calling super.paint in said overridden method? As a side note, I've been experiencing weird behavior with setting the color of the graphics object and using drawString. If I set the color in the constructor of the class where the Canvas is created, and fetch the graphics object from the Canvas to a different class and use drawString, the color does not seem to carry over. However if I set the color right before drawing in the aforementioned different class, it does work. If i'm not supposed to mix AWT and swing, is there a JFrame alternative apart of AWT I could use? Or is swing fast enough to be used and can AWT/Canvas be ignored? Sorry for the long and confusing post, but I feel very lost, and a lengthy explanation would be appreciated.
[QUOTE=Shotgunz;44592171]hi. so i've been using java recently for game dev things, and various stackOverflow questions i've read have told me: -not to mix AWT and swing components -override paint/paintComponent (depending on if its Canvas or JComponent) to perform drawing. however, i have been using a Canvas inside of a JFrame because as far as i know, Canvas is much faster than JComponent due to buffer strategies. Also, I have been using ignoreRepaint as some sources said I should. Additionally, I have been simply fetching the graphics object from my Canvas object (ex: (Graphics2D)renderTarget.getGraphics() ) and using that to draw, as opposed to doing it in the overridden paint method. Should I be calling super.paint in said overridden method? As a side note, I've been experiencing weird behavior with setting the color of the graphics object and using drawString. If I set the color in the constructor of the class where the Canvas is created, and fetch the graphics object from the Canvas to a different class and use drawString, the color does not seem to carry over. However if I set the color right before drawing in the aforementioned different class, it does work. If i'm not supposed to mix AWT and swing, is there a JFrame alternative apart of AWT I could use? Or is swing fast enough to be used and can AWT/Canvas be ignored? Sorry for the long and confusing post, but I feel very lost, and a lengthy explanation would be appreciated.[/QUOTE] As a rule of thumb whenever you're doing painting with AWT components, [B]never[/B] call the [I]getGraphics[/I] method in order to retrieve a Graphics object to draw with. You'll run into weird issues (such as the colour one you described) along with slower performance and flickering. Override the [I]paint[/I] method like you've been doing before (but be sure to call [I]super.paint[/I] before) - and when you want to trigger a repaint, use the [I]repaint[/I] method instead (this will schedule a repaint properly with the AWT event queue, and you won't run into strange bugs): [code] public void paint(Graphics graphics) { super.paint(graphics); //draw stuff Graphics2D graphics2d = (Graphics2D) graphics; graphics2d.drawString("Hello, world", 20, 20); graphics2d.drawRect(100, 100, 200, 200); } [/code] Somewhere else in your code (i.e. the game loop), have something which then will call the [i]repaint[/i] method: [code] public void gameLoop() { //update game logic //... //repaint this.repaint(); } [/code] Canvas is much faster with buffer strategies [B]only if you actually use them correctly[/B] - simply overriding the method won't do. You'll need to explicitly create a buffer strategy (with how many buffers you want) in your canvas' constructor: [code] public Canvas() { //do your initial settings here this.setBackground(Color.RED); //create a buffer strategy with two buffers this.createBufferStrategy(2); } [/code] However, this is a special case - you don't need to override the [I]paint[/I] method here because you'll be accessing the buffer strategy directly (not the Graphics object): [code] public void renderGame() { //get the buffer BufferStrategy bufferStrategy = this.getBufferStrategy(); Graphics2D graphics2d = (Graphics2D) bufferStrategy.getDrawGraphics(); //do some painting here graphics2d.setColor(Color.BLUE); graphics2d.fillRect(0, 0, 200, 200); //make sure you dispose of the graphics object //and swap the buffers graphics2d.dispose(); bufferStrategy.show(); } [/code] That should be the gist of it. Refer to [URL="http://gpsnippets.blogspot.com/2010/10/how-to-use-bufferstrategy-in-java.html"]this post[/URL] if you're stuck.
[QUOTE=Contron;44594926]snip[/QUOTE]thank you so much. you are a god.
For my raytracer I currently only supports spheres, which have a "Sphere" class which contains their details, I then have a List<Sphere> of all the sphere in the scene I can iterate through to check for collisions. I want to add planes now, but I want to iterates through all "collideable" objects in one for loop - but a list can only contain instances of a certain type, right? How can I have a list containing both planes and spheres, do they both need to have a parent class of a certain type or something along those lines? I want to do something like: [code] List<stuff> things = new List<stuff>(); things.Add(Sphere); things.Add(Plane); foreach( stuff s in things){ if s = Sphere do stuff if s = plane do other stuff } [/code] EDIt: I've got it working by making Sphere and Plane derived from a base class "Objects", then using: [code]foreach(Objects s in object_list){ if ((Sphere)s !=null) //sphere do stuff else if ( (Plane)s !=null) do other stuff }[/code] Is this an ok way to do it?
[QUOTE=Shotgunz;44595289]thank you so much. you are a god.[/QUOTE] Happy to help! [editline]20th April 2014[/editline] [QUOTE=chaz13;44595600]For my raytracer I currently only supports spheres, which have a "Sphere" class which contains their details, I then have a List<Sphere> of all the sphere in the scene I can iterate through to check for collisions. I want to add planes now, but I want to iterates through all "collideable" objects in one for loop - but a list can only contain instances of a certain type, right? How can I have a list containing both planes and spheres, do they both need to have a parent class of a certain type or something along those lines? I want to do something like: [code] List<stuff> things = new List<stuff>(); things.Add(Sphere); things.Add(Plane); foreach( stuff s in things){ if s = Sphere do stuff if s = plane do other stuff } [/code] EDIt: I've got it working by making Sphere and Plane derived from a base class "Objects", then using: [code]foreach(Objects s in object_list){ if ((Sphere)s !=null) //sphere do stuff else if ( (Plane)s !=null) do other stuff }[/code] Is this an ok way to do it?[/QUOTE] That's a fair enough way to do it - one base class/inteface from which all the other objects in the scene extend from. However, if you're wanting to check for collisions for each, a better way to do it could be: [code] if (object is Sphere) { //do something } else if (object is Plane) { //do something else } [/code] Hell, if you want to go even further, have the base class define a [I]checkCollisions[/I] method that both your Sphere and Plane class override - that way, all you'd need to do is: [code] foreach (Thing object in objectList) { object.checkCollisions(); } [/code]
Short Grammar question: I have this (Don't know how its called in english) [QUOTE][IMG]http://i.imgur.com/4wc7y9m.jpg[/IMG][/QUOTE] Is this the correct EBNF for it? [QUOTE] comp = "§" z1 {z2} "(" z1 (z2 ")"|")"); z1 = "1".."9"; z2 = "0".."9"; [/QUOTE]
[CODE]public Garroter() { musicOn = new JRadioButton("On:"); musicOn.addActionListener(new Music()); musicOff = new JRadioButton("Off:"); musicOff.addActionListener(new Music()); musicGroup = new ButtonGroup(); musicGroup.add(musicOn); musicGroup.add(musicOff); contentPaneW.add(musicOnLabel); contentPaneW.add(musicOn); contentPaneW.add(musicOff); contentPaneTwo.add(contentPaneW, BorderLayout.WEST); } [/CODE] [CODE] class Music implements ActionListener { String choice; AudioPlayer MGP = AudioPlayer.player; AudioStream BGM; AudioData MD; ContinuousAudioDataStream loop = null; public void actionPerformed(ActionEvent e) { choice = e.getActionCommand(); try { BGM = new AudioStream(new FileInputStream("Elevator_Music.wav")); MD = BGM.getData(); loop = new ContinuousAudioDataStream(MD); } catch (IOException error) { } if (choice.equalsIgnoreCase("on:")) { MGP.player.start(loop); } else if (choice.equalsIgnoreCase("off:")) { try { loop.close(); } catch (IOException ex) { Logger.getLogger(Garroter.class.getName()).log(Level.SEVERE, null, ex); } } }[/CODE] [url]https://www.youtube.com/watch?v=VMSTTg5EEnY[/url] So I can't get the music player part to quit looping/every time I click it, it decides to play over the previous play. How do I get it to stop?
Thanks for your help! :smile:
What would be the most accepted way to store menu information, such as button layouts and types? Hardcoding feels gross but it's the only practical way I can think of to store the info.
[QUOTE=phygon;44599582]What would be the most accepted way to store menu information, such as button layouts and types? Hardcoding feels gross but it's the only practical way I can think of to store the info.[/QUOTE] QT uses XML
Is it easier to design the interface in code or possibly with an external tool? Use whatever is the easiest.
[QUOTE=Joxstrap;44587622]Does anyone have any advice for someone struggling with love2D's printf function? This is giving me a headache. The problem is basically summed up by this: The user is supposed to be able to type anything they like in the text input box. To stop it from extending off of the screen, i'm using printf to wrap the text when it gets to a certain point. I'm also trying to make the rectangular "background" for the text wrap with it. This appears to work, but you tend to end up with this case of the text running ahead of the rectangle. In the image, if I had kept writing, it would have caught up and ended up looking normal. Here is the code concerned. There are a few other problems with it, like all the hardcoded x and y values. The way i'm getting textheight is obviously not working, so I was wondering if you guys had any advice?[/QUOTE] printf wraps the text on a per-word basis, while your textheight calculation works on purely pixels. printf might wrap the text at 680 pixels to save a word from being cut off, so your textheight calculation would be 20 pixels behind, etc. Luckily, there is [URL="https://love2d.org/wiki/Font:getWrap"]Font:getWrap()[/URL] which calculates the height (# of lines, actually, so just multiply it by height) exactly the same way printf does.
[QUOTE=Pappschachtel;44599625]QT uses XML[/QUOTE] I'd strongly suggest using JSON instead of XML if you're going that direction.
Sorry, you need to Log In to post a reply to this thread.