Search Results

Search found 2852 results on 115 pages for '2d'.

Page 13/115 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • What is causing this behavior with the movement of Pong Ball in 2D? [closed]

    - by thegermanpole
    //edit after running it through the debugger it turned out i had the display function set to x,x...TIL how to use a debugger I've been trying to teach myself C++ SDL with the lazyfoo tutorial and seem to have run into a roadblock. The code below is the movement function of my Dot class, which controls the ball. The ball seems to ignore yvel and moves with xvel to the bottom right. The code should be pretty readable, the rest of the relevant facts are: All variables are names Constants are in caps dotrad is the radius of my dot yvel and xvel are set to 5 in the constructor The dot is created at x and y equal to 100 When I comment out the x movement block it doesn't move, but if i comment out the y movement block, it keeps on going down to the right. void Dot::move() { if(((y+yvel+dotrad) <= SCREEN_HEIGHT) && (0 <= (y-dotrad+yvel))) { y+=yvel; } else { yvel = -1*yvel; } if(((x+xvel+dotrad) <= SCREEN_WIDTH) && (0 <= (x-dotrad+xvel))) { x +=xvel; } else { xvel = -1*xvel; } }

    Read the article

  • Creating a simple 2d game with C++: Where to go first? [on hold]

    - by Lucas Vieira
    I'm starting to build a little school project. (I have a prior experience with php, python and java, and i'm learning c++ now). My part is simple, create a game, like this pong http://www.ponggame.org/ The problem is that I've never programmed a game before. I was looking the possibilities, maybe use QT? Or is there other library better for my case? Since i don't want to reinvent the wheel, where to start with? Thank you, guys!

    Read the article

  • How can I calculate the angle between two 2D vectors?

    - by Error 454
    I am working on some movement AI where there are no obstacles and movement is restricted to the XY plane. I am calculating two vectors, v, the facing direction of ship 1, and w, the vector pointing from the position of ship 1 to ship 2. I am then calculating the angle between these two vectors using the formula arccos((v · w) / (|v| · |w|)) The problem I'm having is that arccos only returns values between 0° and 180°. This makes it impossible to determine whether I should turn left or right to face the other ship. Is there a better way to do this?

    Read the article

  • How to make an Image still when at position at Slick 2D?

    - by SystemNetworks
    For example, I want to put a building down. if I press 2, it will show the building near the character and it is moving with my character. I have done that. Now I wanted to know how do i put it down and stop following my character? I have something called shiftX and shiftY (Which is the position of my character) And my character looks like it is moving because the map and images itself is moving which i call, probePositionX and probePositionY.

    Read the article

  • Accessing 2D array and passing string to label.text

    - by Amir
    Hi. I'm trying to create 2D array and initialize it with NSStrings. When I try to copy content of a cell from the array to a label.text, the application crashes. NSMutableArray *array = [NSMutableArray arrayWithCapacity:0]; [array addObject:[NSMutableArray arrayWithObjects: [NSArray arrayWithObjects: @"0-0", @"0-1", @"0-2", nil], [NSArray arrayWithObjects: @"1-0", @"1-1", @"1-2", nil], [NSArray arrayWithObjects: @"2-0", @"2-1", @"2-2", nil], nil]]; label.text = [[array objectAtIndex:0] objectAtIndex:0]; Any idea why and what am I doing wrong?

    Read the article

  • 2D World design question

    - by Maciek
    I'm facing a problem which is probably extremely common in game-design. Let's assume that we've got a 2D world The world's size is M x N rect The world may contain some items in it The items have (x,y) coords The world can be browsed via a window that is physically (m x n) large. The browser window can be zoomed in / out The browser window can be panned up/down + left right, while in the extents of the world's rect. How should I go about implementing this? I'm especially concerned about the browser window. Can anyone recommend any good reads ? This is not a homework - it's more of a task which I've set myself to complete.

    Read the article

  • Surface Detection in 2d Game?

    - by GamiShini
    I'm working on a 2D Platform game, and I was wondering what's the best (performance-wise) way to implement Surface (Collision) Detection. So far I'm thinking of constructing a list of level objects constructed of a list of lines, and I draw tiles along the lines. ( http://img375.imageshack.us/img375/1704/lines.png ). I'm thinking every object holds the ID of the surface that he walks on, in order to easily manipulate his y position while walking up/downhill. Something like this: //Player/MovableObject class MoveLeft() { this.Position.Y = Helper.GetSurfaceById(this.SurfaceId).GetYWhenXIs(this.Position.X) } So the logic I use to detect "droping/walking on surface" is a simple point (player's lower legs)-touches-line (surface) check (with some safety approximation - let`s say 1-2 pixels over the line). Is this approach OK? I`ve been having difficulty trying to find reading material for this problem, so feel free to drop links/advice.

    Read the article

  • WPF component for 2D tree diagram

    - by pdm2011
    I'm looking for a well-documented, supported WPF component that provides an API for visualisation of 2D tree diagrams. Ideally something easy to use, customisable (i.e. supports various flavours of nodes and splines) and preferably with automated layout control. Tools that look good so far are GoXam (http://www.nwoods.com/components/silverlight-wpf/goxam-overview.htm) and yFiles WPF (http://www.yworks.com/en/products_yfileswpf_about.html). Just wondering if anyone has experience with either of these, or can recommend an alternative? Thanks!

    Read the article

  • declaring a 2D array of pointer objects

    - by Tyler Stennette
    I'm having a tough time figuring out how to instantiate a 2D array of pointer objects. Here is how I'm doing it: Pieces* chessBoard[9][9]; When I want to set it to an actual object pointer, I'm doing the following: chessBoard[1][1] = new Rook(p1Rook); Rook is a class that inherits attributes from the Pieces class and p1Rook is a char variable set to 'R'. This class also implements virtual functions (not pure virtual) from Pieces such as move() or getPiece() that are unique to the particular chess piece. However, when I compile my program, I get the following error: ChessBoard.cpp:69: error: expected type-specifier before ‘Rook’ ChessBoard.cpp:69: error: cannot convert ‘int*’ to ‘Pieces*’ in assignment Can someone please explain what I should change to get rid of this rather annoying persistent error? I would appreciate it.

    Read the article

  • Rewriting a simple Pygame 2D drawing function in C++

    - by Dominic Bou-Samra
    I have a 2D list of vectors (say 20x20 / 400 points) and I am drawing these points on a screen like so: for row in grid: for point in row: pygame.draw.circle(window, white, (particle.x, particle.y), 2, 0) pygame.display.flip() #redraw the screen This works perfectly, however it's much slower then I expected. I want to rewrite this in C++ and hopefully learn some stuff (I am doing a unit on C++ atm, so it'll help) on the way. What's the easiest way to approach this? I have looked at Direct X, and have so far followed a bunch of tutorials and have drawn some rudimentary triangles. However I can't find a simple (draw point).

    Read the article

  • XNA 2d camera with arbitrary zoom center

    - by blooop
    I have a working 2D camera in XNA with these guts: ms = Mouse.GetState(); msv = new Vector2(ms.X, ms.Y); //screenspace mouse vecor pos = new Vector2(0, 0); //camera center of view zoom_center = cursor; //I would like to be able to define the zoom center in world coords offset = new Vector2(scrnwidth / 2, scrnheight / 2); transmatrix = Matrix.CreateTranslation(-pos.X, -pos.Y, 0) * Matrix.CreateScale(scale, scale, 1) * Matrix.CreateTranslation(offset.X, offset.Y, 0); inverse = Matrix.Invert(transmatrix); cursor = Vector2.Transform(msv, inverse); //the mouse position in world coords I can move the camera position around and change the zoom level (with other code that I have not pasted here for brevity). The camera always zooms around the center of the screen, but I would like to be able to zoom about an arbitrary zoom point (the cursor in this case), like the indie game dyson http://www.youtube.com/watch?v=YiwjjCMqnpg&feature=player_detailpage#t=144s I have tried all the combinations that make sense to me, but am completely stuck.

    Read the article

  • Visit neighbor of a position in a 2d-array

    - by Martin
    I have the following two dimensional array: static int[,] arr = new int[5, 5] { { 00, 00, 00, 01, 00 }, { 00, 00, 01, 01, 00 }, { 00, 00, 01, 01, 00 }, { 00, 00, 01, 01, 00 }, { 00, 00, 00, 01, 00 }, }; I have to a implement a method called Hit(int x, int y). When we hit a 0 in the array (i.e. Hit(0, 0), Hit(1, 1), but not Hit(3, 0)) I would like all the adjacent zeros to the zero we hit to be incremented by 10. So if I call Hit(1, 1), the array should become the following. static int[,] arr = new int[5, 5] { { 10, 10, 10, 01, 00 }, { 10, 10, 01, 01, 00 }, { 10, 10, 01, 01, 00 }, { 10, 10, 01, 01, 00 }, { 10, 10, 10, 01, 00 }, }; Any idea how I could implement that? It sounds to me like a Depth First Search/Recursive sort-of algorithm should do the job, but I haven't been able to implement it for an 2d array. Thanks for the help!

    Read the article

  • Quartz 2D animating text?

    - by coure06
    i have to animate text around a circle. The text will also scale up/down. Whats the best approach to accomplish this? (i am using Quartz 2D) My approach is: -- Calculate point using sin and cos methods. -- Move Pen there and draw text with alpha and size. -- Clear the screen -- Calculate next point using sin and cos methods. -- Move pen there and draw text with alpha and size. -- clear the screen so on... any better way?

    Read the article

  • Finding the sum of 2D Arrays in Ruby

    - by Bragaadeesh
    Hi, I have an array of two dimensional Arrays. I want to create a new two dimensional array which finds the sum of these values in the 2D arrays. Sum at x,y of new array = Sum at x,y of arr1 + Sum at x,y of arr2 + .... |1,2,4| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| Now adding the above two dimensional arrays will result in, |3,4,6| |4,6,8| |4,6,8| |4,6,8| How to achieve this in Ruby (not in any other languages). I have written a method, but it looks very long and ugly.

    Read the article

  • Creating a 2d matrix from an array (java)

    - by anna
    I'm supposed to write a method that creates a 2d matrix from an array, for instance: ({1, 2, 3, 4}, 3) should return the matrix {{1, 2, 3}, {4}} public class Matrix { public static int[][]toM(int[] array, int a) { int[][]matrix = new int [(array.length + a- 1)/ a][a]; for (int i = 0; i < array.length; i++){ int value = array[i]; value = value++; for (int row = 0; row < (array.length + a- 1)/a; row++) { for (int col = 0; col < a; col++) { matrix[row][col]= value++; } } } return matrix; } } I'm getting [[4, 5, 6], [7, 8, 9]]?

    Read the article

  • 2d array, using calloc in C

    - by BigBirdy
    Hi, I'm trying to create a 2D array of chars to storage lines of chars. For Example: lines[0]="Hello"; lines[1]="Your Back"; lines[2]="Bye"; Since lines has to be dynamically cause i don't know how many lines i need at first. Here is the code i have: int i; char **lines= (char**) calloc(size, sizeof(char*)); for ( i = 0; i < size; i++ ){ lines[i] = (char*) calloc(200, sizeof(char)); } for ( i = 0; i < size; i++ ){ free(lines[i]); } free(lines); I know that each line can't go over 200 chars. I keep getting errors like "error C2059: syntax error : 'for'" and such. Any ideas of what i did wrong?

    Read the article

  • XNA 2D mouse picking

    - by Corndog
    I'm working on a simple 2D Real time strategy game using XNA. Right now I have reached the point where I need to be able to click on the sprite for a unit or building and be able to reference the object associated with that sprite. From the research I have done over the last three days I have found many references on how to do "Mouse picking" in 3D which does not seem to apply to my situation. I understand that another way to do this is to simply have an array of all "selectable" objects in the world and when the player clicks on a sprite it checks the mouse location against the locations of all the objects in the array. the problem I have with this approach is that it would become rather slow if the number of units and buildings grows to larger numbers. (it also does not seem very elegant) so what are some other ways I could do this. (Please note that I have also worked over the ideas of using a Hash table to associate the object with the sprite location, and using a 2 dimensional array where each location in the array represents one pixel in the world. once again they seem like rather clunky ways of doing things.)

    Read the article

  • 2D Ball Collisions with Corners

    - by Aaron
    I'm trying to write a 2D simulation of a ball that bounces off of fixed vertical and horizontal walls. Simulating collisions with the faces of the walls was pretty simple--just negate the X-velocity for a vertical wall or the Y-velocity for a horizontal wall. The problem is that the ball can also collide with the corners of the walls, where a horizontal wall meets with a vertical wall. I have already figured out how to detect when a collision with a corner is occurring. My question is how the ball should react to this collision--that is, how its X and Y velocities will change as a result. Here's a list of what I already know or know how to find: *The X and Y coordinates of the ball's center during the frame when a collision is detected *The X and Y components of the ball's velocity *The X and Y coordinates of the corner *The angle between the ball's center and the corner *The angle in which the ball is traveling just before the collision *The amount that the ball is overlapping the corner when the collision is detected I'm guessing that it's best to pretend that the corner is an infinitely small circle, so I can treat a collision between the ball and that circle as if the ball were colliding with a wall that runs tangent to the circles at the point of collision. It seems to me that all I need to do is rotate the coordinate system to line up with this imaginary wall, reverse the X component of the ball's velocity under this system, and rotate the coordinates back to the original system. The problem is that I have no idea how to program this. By the way, this is an ideal simulation. I'm not taking anything like friction or the ball's rotation into account. I'm using Objective-C, but I'd really just like a general algorithm or some advice. Many thanks if anyone can help!

    Read the article

  • java 2D and swing

    - by user384706
    Hi, I have trouble understanding a fundamental concept in Java 2D. To give a specific example: One can customize a swing component via implementing it's own version of the method paintComponent(Graphics g) Graphics is available to the body of the method. Question: What is exactly this Graphics object, I mean how it is related to the object that has the method paintComponent? Ok, I understand that you can do something like: g.setColor(Color.GRAY); g.fillOval(0, 0, getWidth(), getHeight()); To get a gray oval painted. What I can not understand is how is the Graphics object related to the component and the canvas. How is this drawing actually done? Another example: public class MyComponent extends JComponent { protected void paintComponent(Graphics g) { System.out.println("Width:"+getWidth()+", Height:"+getHeight()); } public static void main(String args[]) { JFrame f = new JFrame("Some frame"); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setSize(200, 90); MyComponent component = new MyComponent (); f.add(component); f.setVisible(true); } } This prints Width:184, Height:52 What does this size mean? I have not added anything to the frame of size(200,90). Any help on this is highly welcome Thanks

    Read the article

  • Java 2D Resize

    - by jon077
    I have some old Java 2D code I want to reuse, but was wondering, is this the best way to get the highest quality images? public static BufferedImage getScaled(BufferedImage imgSrc, Dimension dim) { // This code ensures that all the pixels in the image are loaded. Image scaled = imgSrc.getScaledInstance( dim.width, dim.height, Image.SCALE_SMOOTH); // This code ensures that all the pixels in the image are loaded. Image temp = new ImageIcon(scaled).getImage(); // Create the buffered image. BufferedImage bufferedImage = new BufferedImage(temp.getWidth(null), temp.getHeight(null), BufferedImage.TYPE_INT_RGB); // Copy image to buffered image. Graphics g = bufferedImage.createGraphics(); // Clear background and paint the image. g.setColor(Color.white); g.fillRect(0, 0, temp.getWidth(null),temp.getHeight(null)); g.drawImage(temp, 0, 0, null); g.dispose(); // j2d's image scaling quality is rather poor, especially when // scaling down an image to a much smaller size. We'll post filter // our images using a trick found at // http://blogs.cocoondev.org/mpo/archives/003584.html // to increase the perceived quality.... float origArea = imgSrc.getWidth() * imgSrc.getHeight(); float newArea = dim.width * dim.height; if (newArea <= (origArea / 2.)) { bufferedImage = blurImg(bufferedImage); } return bufferedImage; } public static BufferedImage blurImg(BufferedImage src) { // soften factor - increase to increase blur strength float softenFactor = 0.010f; // convolution kernel (blur) float[] softenArray = { 0, softenFactor, 0, softenFactor, 1-(softenFactor*4), softenFactor, 0, softenFactor, 0}; Kernel kernel = new Kernel(3, 3, softenArray); ConvolveOp cOp = new ConvolveOp(kernel, ConvolveOp.EDGE_NO_OP, null); return cOp.filter(src, null); }

    Read the article

  • 2D Platformer Collision Problems With Both Axes

    - by AusGat
    I'm working on a little 2D platformer/fighting game with C++ and SDL, and I'm having quite a bit of trouble with the collision detection. The levels are made up of an array of tiles, and I use a for loop to go through each one (I know it may not be the best way to do it, and I may need help with that too). For each side of the character, I move it one pixel in that direction and check for a collision (I also check to see if the character is moving in that direction). If there is a collision, I set the velocity to 0 and move the player to the edge of the tile. My problem is that if I check for horizontal collisions first, and the player moves vertically at more than one pixel per frame, it handles the horizontal collision and moves the character to the side of the tile even if the tile is below (or above) the character. If I handle vertical collision first, it does the same, except it does it for the horizontal axis. How can I handle collisions on both axes without having those problems? Is there any better way to handle collision than how I'm doing it?

    Read the article

  • Agile language for 2d game prototypes?

    - by instanceofTom
    Occasionally ( read: when my fiancé allows ) I like to prototype different game or game-like ideas I have. Usually I use Java or C# (not xna yet) because they are the languages I have the most practice with. However I would like to learn something more suited to agile development; a language in which it would be easier to knock out quick prototypes. At my job I have recently been working with looser (weak/dynamically typed) languages, specifically python and groovy, and I think something similar would fit what I am looking for. So, my question is: What languages (and framework/engine) would be good for rapidly developing prototypes of 2d game concepts? A few notes: I don't need blazing fast bitcrunching performance. In this case I would strongly prefer ease of development over performance. I'd like to use a language with a healthy community, which to me means a fair amount of maintained 3rd party, libraries. I'd like the language to be cross-platform friendly, I work on a variety of different operating systems and would like something that is portable with minimum effort. I can't imagine myself using a language with out decent options for debugging and editor syntax highlighting support. Note: If you are aware of a Java or C# library/framework that you think streamlines producing game prototypes I open to learning something new for those languages too

    Read the article

  • Java Graphics on java, 2d array board game.

    - by FILIaS
    I wanna fix a 2D board for a game. I've already fixed other panels for the gui and everything goes well. But the panel for the board cant be printed on the window. I'm a bit confused about it as i think i've followed the same ideas as for the others panels i need. Here's what i've done: /** *Method used to construct the square in the area of the *gui's grid. In this stage a GUISquare array is being constructed, * used in the whole game as *a mean of changing a square graphical state. *@param squares is the squares array from whom the gui grid will be *constructed. *@see getSquare about the correspondance beetween a squareModel and * a GUISquare. */ private void initBoardPanel(SquareModel[][] squares){ BoardPanel.setLayout(new GridLayout(myGame.getHeight(),myGame.getWidth())); //set layout Squares=new GUISquare[myGame.getHeight()][myGame.getWidth()]; grid=new JPanel[myGame.getHeight()][myGame.getWidth()]; for (int i=0; i< myGame.getHeight(); i++){ for (int j=0; j<myGame.getWidth() ; j++){ grid[i][j] = new JPanel( ); GUISquare kout=new GUISquare(i,j); kout.setSquare(myGame.getSquares()[i][j]); kout.draw(myGame.getSquares()[i][j].getGoTo(),myGame.getSquares()[i][j].getNumber()); /*draw method is been called. the first parameter is the number of the square that the player will be moved to if lands in this one square,the second parameter is just the number of the square */ kout.setVisible(true); grid[i][j].add(kout); grid[i][j].setVisible(true); BoardPanel.add(grid[i][j]); BoardPanel.setVisible(true); BoardPanel.setBackground(Color.WHITE); GUISquare temp=this.getSquare(squares[i][i]); Squares[i][j]= temp; } } this.add(BoardPanel,BorderLayout.WEST); // this.pack(); //sets appropriate size for frame this.setVisible(true); //makes frame visible } /** * Transformer for Rand/Move * <br>This method is used to display a square on the screen. */ public void draw(int goTo ,int number) { JPanel panel = new JPanel(); JLabel label1 = new JLabel(""+"Move To"+goTo); JLabel label2 = new JLabel(""+number); JSeparator CellSeparator = new JSeparator(orientation); panel.add(CellSeparator); panel.setLayout(new BorderLayout()); panel.add(label1, BorderLayout.CENTER); panel.add(label2, BorderLayout.LINE_START); } I've posted only one draw method...but all versions are alike.

    Read the article

  • 2d java Graphics

    - by LukeG
    I am new to java 2d graphics and I have problem handling mouseclick event. Is it possible for you to tell me why there is nothing going on after updating mouse status to clicked ? What I want to do is to change the image in array at 0 2 to another image. Nothing happens tho. Thanks for your help in advance. import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image; import java.awt.event.*; import java.awt.*; import javax.swing.ImageIcon; import javax.swing.*; public class Board extends JPanel implements MouseListener { private static boolean[] keyboardState = new boolean[525]; private static boolean[] mouseState = new boolean[3]; private static Image[][] images; Image house; int w = 0; int h = 0; int xPos; int yPos; ImageIcon ii = new ImageIcon(this.getClass().getResource("house.gif")); ImageIcon iii = new ImageIcon(this.getClass().getResource("house1.gif")); public Board() { house = ii.getImage(); h = house.getHeight(null); w = house.getWidth(null); images = new Image[10][10]; for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { images[i][j] = house; } } } public void paint(Graphics g) { Graphics2D g2d = (Graphics2D) g; for(int i = 0; i < 10; i++) { for(int j = 0; j < 10; j++) { g2d.drawImage(images[i][j],w*i,h*j,null); } } //g2d.drawImage(house,15,15,null); } public void checkMouse() { if(mouseState[0]) { images[0][2] = iii.getImage(); repaint(); super.repaint(); } } @Override public void mousePressed(MouseEvent e) { mouseKeyStatus(e, true); checkMouse(); } @Override public void mouseReleased(MouseEvent e) { mouseKeyStatus(e, false); repaint(); } public static boolean mouseButtonState(int button) { return mouseState[button - 1]; } private void mouseKeyStatus(MouseEvent e, boolean status) { if(e.getButton() == MouseEvent.BUTTON1) mouseState[0] = status; else if(e.getButton() == MouseEvent.BUTTON2) mouseState[1] = status; else if(e.getButton() == MouseEvent.BUTTON3) mouseState[2] = status; }

    Read the article

  • Java exercise - display table with 2d array

    - by TheHacker66
    I'm struggling to finish a java exercise, it involves using 2d arrays to dinamically create and display a table based on a command line parameter. Example: java table 5 +-+-+-+-+-+ |1|2|3|4|5| +-+-+-+-+-+ |2|3|4|5|1| +-+-+-+-+-+ |3|4|5|1|2| +-+-+-+-+-+ |4|5|1|2|3| +-+-+-+-+-+ |5|1|2|3|4| +-+-+-+-+-+ What i have done so far: public static void main(String[] args) { int num = Integer.parseInt(args[0]); String[][] table = new String[num*2+1][num]; int[] numbers = new int[num]; int temp = 0; for(int i=0; i<numbers.length; i++) numbers[i] = i+1; // wrong for(int i=0; i<table.length; i++){ for(int j=0; j<num;j++){ if(i%2!=0){ temp=numbers[0]; for(int k=1; k<numbers.length; k++){ numbers[k-1]=numbers[k]; } numbers[numbers.length-1]=temp; for(int l=0; l<numbers.length; l++){ table[i][j] = "|"+numbers[l]; } } else table[i][j] = "+-"; } } for(int i=0; i<table.length; i++){ for(int j=0; j<num; j++) System.out.print(table[i][j]); if(i%2==0) System.out.print("+"); else System.out.print("|"); System.out.println();} } This doesn't work, since it prints 1|2|3|4 in every row, which isn't what i need. I found the issue, and it's because the first for loop changes the array order more times than needed and basically it returns as it was at the beginning. I know that probably there's a way to achieve this by writing more code, but i always tend to nest as much as possible to "optimize" the code while i write it, so that's why i tried solving this exercise by using less variables and loops as possible. Thanks in advance for your help!

    Read the article

< Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >