# destructivArts

Member

77

205 Neutral

• Rank
Member

• Website
1. ## Xna 3d coordinates problem

Changing the order worked but it still is skewed. My view matrix is: view = Matrix.CreateLookAt(pos, target, up); and the Projection matrix is view = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, (float)Game.Window.ClientBounds.Width / (float)Game.Window.ClientBounds.Height, 1, 100); Edit: Ok, well changing the order worked but that wasn't why it was skewed. I was defining the vertices in an array of VertexPositionColor and I was overwriting the Object at index 1. ie. vert[0] = new VertexPositionColor(variables); vert[1] = new VertexPositionColor(variables); vert[1] = new VertexPositionColor(variables); So thank you for your help, worked perfectly
2. ## Xna 3d coordinates problem

I'm going through a book, and the example it gave me seems like is should work, but when I try and implement it, it falls short. My Camera class takes three vectors in to generate View and Projection matrices. I'm giving it a position vector of (0,0,5), a target vector of Vector.Zero and a top vector (which way is up) of Vector.Up. My Three vertices are placed at (0,1,0), (-1,-1,0), (1,-1,0). It seems like it should work because the vertices are centered around the origin, and thats where I'm telling the camera to look but when I run the game, the only way to get the camera to see the vertices is to set its position to (0,0,-5) and even then the triangle is skewed. Not sure what's wrong here. Any suggestions would be helpful. Just to make sure I've given you guys everything (I don't think these are important as the problem seems to be related to the coordinates, not the ability of the game to draw them): I'm using a VertexBuffer and a BasicEffect. My render code is as follows: effect.World = Matrix.Identity; effect.View = camera.view; effect.Projection = camera.projection; effect.VertexColorEnabled = true; foreach (EffectPass pass in effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawUserPrimitives<VertexPositionColor> (PrimitiveType.TriangleStrip, verts, 0, 1); }

4. ## Reviews with Perspective

Go look at the other one, this was a mistake. Sorry guys (Mods if you wanna delete this, thats cool) (Delete this one ;) ) Peter
5. ## where to go now?

Here's some ideas: Progression
6. ## Java tips

I took a class exactly like that. I signed up for the class and then over the summer taught myself the curriculum. So when I got to class, I was able to finish the projects the teacher assigned us while she was still teaching the new lesson. (ie. Today we're going to learn how to create a calculator program. To do that we need functions. She teaches, I type.) And while everyone else was working on the project, I was looking up stuff to make games with. If the class you're in is an AP track course you won't learn a whole lot more than the basics of java. Books and the internet are your best friends. I used Learn Java in 21 days (I didn't finish in 21 days, but it's still a good reference), and http://math.hws.edu/javanotes/. For game related programming tips I read Core Techniques and Algorithms in Game Programming. The code's in C++ but theres more in pseudo code and the C++ code is easy to read. Hope this helps, Peter
7. ## Updating the Player in a Quad Tree

Ok, I'll keep that in mind. One other question: I've implemented an ObservableInput object that calls this update function every frame: public void updateInput(MouseHandler m, KeyHandler k){ //Mouse mousePos = m.getMousePos(); //Keyboard keys = k.getKeyStates(); } For some reason it's not calling the update function for it's observers. I don't know if this has anything to do with it but I'm setting the Entities as observers when they are placed in a data list of a node. I'm removing them when they have to be shifted, and adding them again when they are placed. I know the ObservableInput object sees them, so I don't know why it's not updating. Just to be thorough, heres the entity update function. public void update(Observable obs, Object obj){ } And the players: @Override public void update(Observable o, Object obj){ System.out.println("1"); if(o instanceof ObservableInput){ ObservableInput obs = (ObservableInput)o; buttonState = obs.getButtonState(); mousePos = obs.getMousePos(); keys = obs.getKeyState(); } } I'll keep looking in the meantime, Thanks again for all the help! Peter
8. ## Updating the Player in a Quad Tree

Thank you, I looked up the Observer/Observable, and I won't actually have to change much to implement it. As to your concern about putting too much into a base class, can't I just create children classes for each kind of entity I need? All I would have to do is put empty functions into the entity class so that its children could use them. (Entity already takes care of animation updates, rendering, and collision detection.) Thanks again for the help! Peter
9. ## Updating the Player in a Quad Tree

I'm writing my game in Java, but this seems pretty language independent. I have a quad tree set up to organize all my game entities. All game entities are children of an entity class, and that is what the quad tree sees all its data as. Almost all entities simply get a list of nearby entities for their update function. The player, however, needs this in addition to the keyboard info and mouse info. (I think in typing this I've figured out the solution but I'll ask anyways.) How do I make the tree recognize that it is a Player object and know that it is ok to pass the keyboard and mouse states to it? I've thought of two ways to solve the problem, I'm just wondering which is most effective (or if there's a better way all together). 1.) When I loop through each nodes data, check if each data object's class equals the player class. Create a new player object equal to this data object, update it, and then replace the original with the new one. Example: if(data.getClass() == new Player().getClass()){ Player p = (Player)data; p.update(keyboard, mouse); data = p; } 2.) (And this is the way I think is best right now.) Create an update function in the Entity class that takes in the keyboard and mouse, which only its Player child class will ever call. In the Player class I just override it, and put in the player update code. Then all I have to do is check if the data's class is the same as Player (as I did above). I'm still new at this, so I'm just looking for input. If there's a better way, please let me know. Thanks, Peter
10. ## Making Screen follow the player?

Here's what I've done: Create a camera object that follows the player. Every frame, subtract all your active objects x and y coordinates from the camera's, and set those values into each objects local position variable. If either value is negative or outside the cameras view, dont draw it. Otherwise draw the objects at their local position. Then you just have to base all mouse clicks off local positions and you already have it calculated. I don't know if I explained this well enough so heres an example: Lets say you have an enemy at a global position of 35,40; The camera's top left corner is at 0,100 and has dimensions of 100,100; You would draw the enemy on screen based on the calculation: int locX = entX - camX; >> locX = 35-0 = 35 int locY = camY - entY; >> locY = 100-40 = 60 so you would draw the entity at 35,60. Drawing things in this way accomplishes a lot. You know what is visible so you don't draw things that don't need to be. You don't have to reposition everything in the world every frame. You also have things local positions for mouse events. Hope this helps, Peter

Thanks again for the advice. I'm not to the point yet where I am doing stand alone builds of the game yet, and I'm running it from within Netbeans. Is it possible to alter the amount of memory available to Netbeans? Also I split the background apart into pieces. They're now 2000 x 1500 px and as I'm loading them I'm getting the same error as before. If the problem is the game is loading too many images at once, is there a way to check if an image is finished loading before continuing? Thanks again, Peter

Thanks! How would I do that from within the game? Because when the game is finished I don't want people to have to go through and do that just to run the game. I guess I'll go ahead and ask this just to be sure: Is the way I'm handling images and animations ok? Thanks again Peter

14. ## Scaling Graphics for different Resolutions

Recently a friend tried to run a game I am creating on his computer. We both have mac's but his being a laptop had a much different resolution than my desktop. When he tried to run it all the graphics were scaled poorly, as in I have a function that scales the graphics, but not uniformly. My question is this: What is the best way to allow the game to run on different resolutions? The only option I see is to scale the graphics uniformly and allow the screen to show less. ie. On a higher resolution computer, scale everything up uniformly so the backgrounds either fit perfectly or are larger than the screen. Any help is much appreciated, Thanks, Peter
15. ## 2D Collision detection, need some help.

Ok, First off, I haven't found any easy way of doing collision detection. I was in your position a few months ago for the first time and everyone here was a huge help, but you're going to have to program it yourself. Here's my method (and by my, I mean the method I got from people on here). The Simple Version 1. Find the movement vector of the object your going to move 2. Do a 'Wide Pass' to find anything that might be in its way 3. Find the first collision the object would encounter 4. find the new movement vector based on the collision 5. Apply the vector to the player's position The Complete Version: 1. First find how far the player is going to move in both the x and y directions. 2. A wide pass is designed to quickly, and in a small number of calculations, find any object that the player might hit on its current trajectory. To do this I cast out lines from 2 or 3 of the corners of the character. Which corners I use is based on which directions the player is moving. ie. if he's moving down and left I cast lines from the top left, bottom left and bottom right because those are the only corners that could possible hit something. You then loop through all the objects in your scene to see which ones cross these lines. 3. Loop through the wide pass list of objects finding which one is closest to the player, as this one will be the first to be hit. I find the points at which the lines intersect the object, pick the closest one and use that to determine which collision would come first. 4. Based on that point, you can find the new movement vector. 5. Add the vectors to the current position. I've found it easier, at least with java, to write my own class for a bound object rather than using java.awt.Rectangle, but that might just be me. Hope this helps. Peter