• What do you need help with? Version 5
    5,752 replies, posted
-this isn't the right thread for this, sorry-
-snipped due to request-
[QUOTE=Jookia;38998875]Seriously? [code]CreateEntity() { entityVector.push_back( Entity() ); Entity& e = entityVector.back(); e.SetData( whatever ); }[/code][/QUOTE] Perfect! References are one of the greatest features of C++, and yet so many programmers seem to forget they exist and instead use clunky, dangerous pointers.
[QUOTE=Larikang;39005464]Perfect! References are one of the greatest features of C++, and yet so many programmers seem to forget they exist and instead use clunky, dangerous pointers.[/QUOTE] It's probably because there are a lot of things you can't do with pointers. You could very simply just use references whenever you don't need to do that magic, though, since I don't think they actually have any overhead at all.
I have a question about SDL. If I have a few isometric tiles next to each other they will obviously overlap but because of the alpha channel this wont be a problem but if I want to select a tile by clicking on it it recognizes both images because technically I am clicking on both of the textures. Is there a way to bind some sort of ID to a surface so the program know on what tile I clicked on? Or does anybody know a tutorial that will cover this.
[QUOTE=Larikang;39005464]Perfect! References are one of the greatest features of C++, and yet so many programmers seem to forget they exist and instead use clunky, dangerous pointers.[/QUOTE] The concept of pointers is neither "clunky" nor "dangerous". I think you mean to describe how the methods of which programmers use pointers can be "clunky" and "dangerous". C/C++'s ability to grant users access to raw memory can be quite useful but how dangerous it is depends on how the user wrote the code, not the language. I agree that I wouldn't encourage using raw pointers in a large scale application because accidents do happen in the backend of the code, but if you're using pointers localised to a single function call or a small segment of code, there's no "danger" in comparison with references. However, a wiser coder would probably use a wrapper class or STL object instead of a raw pointer in the overhead engine of the application. But the original question asked about pointers and dynamic allocation/dynamic memory, NOT references. I never stated that references would not work, I said that raw assignment would lead to copies of an object, which is sloppy coding. You can use pointers, and you can use references as well. Also, don't ignore the third point I had in my post. [quote] [b]3. Useful for optimizing function parameters and returns. Though, you could also use references as well.[/b][/quote] [editline]28th December 2012[/editline] [QUOTE=sparky28000;39007378]I have a question about SDL. If I have a few isometric tiles next to each other they will obviously overlap but because of the alpha channel this wont be a problem but if I want to select a tile by clicking on it it recognizes both images because technically I am clicking on both of the textures. Is there a way to bind some sort of ID to a surface so the program know on what tile I clicked on? Or does anybody know a tutorial that will cover this.[/QUOTE] You mean you have two textures over eachother that are physically overlapping, but because of your alpha they aren't visually overlapping?
[QUOTE=DarkCybo7;39007395]You mean you have two textures over eachother that are physically overlapping, but because of your alpha they aren't visually overlapping?[/QUOTE] Yes, exactly like that.
[QUOTE=sparky28000;39007590]Yes, exactly like that.[/QUOTE] That's trickier. The only way I think you would check if your mouse clicked one or the other is doing something like: 1. User clicks mouse: Get mouse x and y 2. Find the two tiles clicked on by the mouse. 3. Get the pixel data for both tile images. 4. Check the top tile to see if there is a visible pixel where the user clicked (mouse x and mouse y). if so, he clicked the top tile. 5. Repeat last step for bottom tile.
[QUOTE=DarkCybo7;39007635]That's trickier. The only way I think you would check if your mouse clicked one or the other is doing something like: 1. User clicks mouse: Get mouse x and y 2. Find the two tiles clicked on by the mouse. 3. Get the pixel data for both tile images. 4. Check the top tile to see if there is a visible pixel where the user clicked (mouse x and mouse y). if so, he clicked the top tile. 5. Repeat last step for bottom tile.[/QUOTE] That's what I thought, but it seemed really devious. I hope anybody here knows another way.
It isn't as bad as it sounds. If you do go with the pixel-checking route, I'll refer you to these two articles. [url]http://lazyfoo.net/articles/article03/index.php[/url] [url]http://lazyfoo.net/SDL_tutorials/lesson31/index.php[/url] His code: [code]Uint32 get_pixel32( SDL_Surface *surface, int x, int y ) { //Convert the pixels to 32 bit Uint32 *pixels = (Uint32 *)surface->pixels; //Get the requested pixel return pixels[ ( y * surface->w ) + x ]; } [/code]
Does anyone know of a good tutorial on basic 2D level changing (ala cave story)?
Getting more into LWJGL/OpenGL in Java. Having some trouble understanding how to use 3D though. I have a camera that I can move around forward and back etc, but since it is in Ortho It isn't really "3D". How do I change it? Here is my initialization code: [CODE] public void engineInit(){ // Display initialization try{ Display.setDisplayMode(new DisplayMode(WINDOW_WIDTH,WINDOW_HEIGHT)); Display.setTitle(WINDOW_TITLE); Display.create(); Display.setVSyncEnabled(true); }catch(LWJGLException le){ le.printStackTrace(); } glEnable(GL11.GL_TEXTURE_2D); // enable alpha blending glEnable(GL11.GL_BLEND); glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // OpenGL initialization glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, WINDOW_WIDTH,WINDOW_HEIGHT,0,1,-1); glMatrixMode(GL_MODELVIEW); gameStart(); while(!Display.isCloseRequested()){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); gameUpdate(); Display.update(); Display.sync(60); } gameStop(); } // gameUpdate // Called every frame public void gameUpdate(){ player.update(); glPushMatrix(); glTranslatef(300,300,0); glBegin(GL_QUADS); glVertex3f(0,0,0); glVertex3f(0,10,0); glVertex3f(10,10,0); glVertex3f(10,0,0); glEnd(); glPopMatrix(); } [/CODE]
You'll have to call glPerspective instead of glOrtho. Anyone wants to help me with Quaternions? I need a class that converts to/from euler angles, all the tutorials I can find show code that uses a different coordinate system than I do and I'm not genious enough to rewrite them.
[QUOTE=WeltEnSTurm;39023261]You'll have to call glPerspective instead of glOrtho. Anyone wants to help me with Quaternions? I need a class that converts to/from euler angles, all the tutorials I can find show code that uses a different coordinate system than I do and I'm not genious enough to rewrite them.[/QUOTE] Different coordinate system? Like a left handed one?
drrr. Wrong thread. :suicide:
[QUOTE=Meatpuppet;39024009]Different coordinate system? Like a left handed one?[/QUOTE] Right is X, Forward is Y, Up is Z
Hey guys, new to programming. I've been trying to learn Java. I feel like I have a decent grasp of the language, with classes and methods and all that. One thing that completely baffles me, though, are exceptions. How do you work around exceptions-- what are they exactly? I read somewhere that they are events that "disrupt the normal flow of instructions". It sounded simple enough, but I've followed a few miscellaneous tutorials, and the tutorials wouldn't run correctly because of exceptions. Why would the authors of these tutorials not do anything about exceptions if they stopped the programs from working? For example, all of the examples on this site: [url]http://zetcode.com/tutorials/javagamestutorial/[/url] The ones that used images would not run for me. Thanks in advance.
Exceptions are thrown by you or the programmer of the library if something unexpected happens. You can catch an exception and choose what happens (printing an error message for instance), or you ignore it, then the program quits with an error message. A throw basically goes up the call stack (quits the function it currently runs, checks, quits again, up to the program entry point) until a catch block is found, if there is none it quits.
[QUOTE=socks;39025603]Hey guys, new to programming. I've been trying to learn Java. I feel like I have a decent grasp of the language, with classes and methods and all that. One thing that completely baffles me, though, is exceptions. How do you work around exceptions-- what are they exactly? I read somewhere that they are events that "disrupt the normal flow of instructions". It sounded simple enough, but I've followed a few miscellaneous tutorials, and the tutorials wouldn't run correctly because of exceptions. Why would the authors of these tutorials not do anything about exceptions if it stopped the program from working? For example, all of the examples on this site: [URL]http://zetcode.com/tutorials/javagamestutorial/[/URL] The ones that used images would not run for me. Thanks in advance.[/QUOTE] Look up throw/catch statements. Exceptions are thrown when something goes haywire. They stop the program to tell you that something went wrong, and a little bit about what went wrong by the type of exception thrown, so you can get an idea of how to fix it. By catching them you can still get the error by printing it to the console, but let the program keep running without stoping it. [URL]http://www.javamex.com/tutorials/exceptions/exceptions_try_catch_block.shtml[/URL] [CODE] [B]try[/B] { somethingThatThrowsAnErrorSometimes(); } [B]catch[/B] (Exception e) { e.printStackTrace(); } [/CODE]
[QUOTE=WeltEnSTurm;39023261]You'll have to call glPerspective instead of glOrtho. [/QUOTE] That did it, thanks :)
Thanks! Read over those tutorials. They were quite helpful! So i have this code: [CODE]import java.awt.*; import java.io.*; import javax.swing.*; import javax.imageio.*; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.ImageIcon; import javax.swing.JPanel; import javax.swing.Timer; class IFrame extends JFrame { public IFrame() //constructor { super("Image Demo");setBounds(50,50,100,100); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Container con=this.getContentPane(); setSize(640,480); GCanvas canvas=new GCanvas(); con.add(canvas);setVisible(true); } public static void main(String arg[]) {new IFrame();} } class GCanvas extends Canvas implements ActionListener { Image img=null; int x, y; Timer timer; public void paint(Graphics g) { try { img=ImageIO.read(new File("bin/bob.png")); x = y = 5; timer = new Timer(25, this); timer.start(); } catch(IOException e) {System.out.println("ok");System.exit(0);} g.drawImage(img,x,y,this); } public void actionPerformed(ActionEvent e) { x += 1; y += 1; if (y > 240){ y = -45; x = -45; } repaint(); } }[/CODE] I'm trying to move a sprite in this. I got the image to load, but the sprite did not move. How would I go about fixing this? (this is sort of a combination of two tutorials from different websites)
I'm not familiar with that framework, but I don't see anything calling actionevent.
How would you call actionEvent/where would you put the calling?
[QUOTE=socks;39032688]How would you call actionEvent/where would you put the calling?[/QUOTE] I read through that tutorial. It looks like the timer is what calls it. Try putting a System.out.println("whatever") inside of actionPreformed to see if it's being called.
Hmm, I tried that and it is being called. I printed out the values of the x and y variables, and this is what I got: x: 21 y:31 x: 21 y:31 x: 21 y:31 x: 21 y:31 x: 21 y:31 x: 21 y:31 x: 21 y:31 x: 21 y:31 (I had changed the beginning values just for experimentation) I think that it might be that it keeps resetting to the original value in the paint method, and then gets 1 added to it in the ActionEvent. Not sure how i would fix this though. UPDATE: I deleted the x = y = ... and it worked... how would i have a beginning value though?
That means that the x=y= part was being called again, beween when you set the new values and when they were drawn. Change the int x, y; to int x, y = whatever;
cool. works great. thanks for the help!
Hi, i'm looking to implement scripting into my application, and I don't really know what to use/where to start. I'm using C# and i'd like use C# as the scripting language, but I could use something else I guess if its better.
Ok, so I've been seeing (in OpenGL and GLFW) pushMatrix and popMatrix, and how it's used for creating classes to generate objects/textures/etc, can anyone inform me when, and how I should use them? Say I wanted to create a class, Object, that had a function, Create(). Also, a function called Rotate(). How would I make those functions?
[QUOTE=Killowatt;39035315]Hi, i'm looking to implement scripting into my application, and I don't really know what to use/where to start. I'm using C# and i'd like use C# as the scripting language, but I could use something else I guess if its better.[/QUOTE] I'm panning on doing the same thing with my game. When I get around to implementing it, I'm going to try out [url=http://www.csscript.net/]CS-Script[/url].
Sorry, you need to Log In to post a reply to this thread.