2d

use super.paintComponent(g) or getGraphics() in java

人盡茶涼 提交于 2019-12-01 10:55:45
i' m little bit confused about few things: Example code,that shows my problem,this isn't compilable // image private BufferedImage image; private Graphics2D graphic; private changeImage; . . . //thread loop while (running) { . . . render(); Graphics showGraphic = getGraphics(); showGraphic.drawImage(image, 0, 0, null); showGraphic.dispose(); } public void render(){ if(changeImage == 1) graphic.drawImage(ImageLoader.TREE, 0, 0, null); else if(changeImage == 2){ graphic.drawImage(ImageLoader.HOUSE, 0, 0, null); . . . graphic.fillRect(50,60,30,40); } } I create an global object Graphic2D and i

how many pixels is a meter in Box2D?

早过忘川 提交于 2019-12-01 10:34:06
Question is simple so, no codes! If someone knows Box2D and SDL2, then, please tell me how to wrap SDL_Rect with b2body. Ofcourse, it requires to know the conversion of metre to pixel and vice versa. This is because Box2D measures distance in metres. Can you give me a simple expression or function to convert metres(of Box2D) to pixels or pixels to metres(of Box2D)? Can you give me a simple expression or function to convert metres(of Box2D) to pixels or pixels to metres(of Box2D)? Unfortunately, this isn't as simple as it sounds, for us. Because, if your game is on worms, then your game world

Getter returning 2d array in C++

无人久伴 提交于 2019-12-01 09:23:47
问题 this is my first post on SO, even though i've spent some time already here. I've got here a problem with a function returning a 2d array. I have defined a private 2d int array property int board[6][7] in my Game class, but i don't know how to create a public getter for this property. These are relevant parts of my game.h: #ifndef GAME_H #define GAME_H class Game { public: static int const m_rows = 6; static int const m_cols = 7; Game(); int **getBoard(); private: int m_board[m_rows][m_cols];

Java Swing custom shapes (2D Graphics)

﹥>﹥吖頭↗ 提交于 2019-12-01 08:37:30
问题 I need to draw custom shapes. Now when a user clicks on several points on the panel I create a shape using a polygon. public void mouseClicked(MouseEvent e) { polygon.addPoint(e.getX(), e.getY()); repaint(); } But I don't know if this is the best way to draw custom shapes. It should be possible to edit a drawn shape : resize change its fill color change the stroke color copy/paste it move a single point of the polygon ... I have seen people creating an own class implementing the Shape class

Allocate a 2d array in C with one dimension fixed

≯℡__Kan透↙ 提交于 2019-12-01 08:06:04
I want to dynamically allocate 1 dimension of a 2D array (the other dimension is given). Does this work: int NCOLS = 20; // nrows = user input... double *arr[NCOLS]; arr = (double *)malloc(sizeof(double)*nrows); and to free it: free(arr) Not quite -- what you've declared is an array of pointers. You want a pointer to an array, which would be declared like this: double (*arr)[NCOLS]; Then, you'd allocate it like so: arr = malloc(nrows * sizeof(double[NCOLS])); It can then be treated as a normal nrows by NCOLS 2D array. To free it, just pass it to free like any other pointer. In C, there's no

libgdx Viewports - Why when I use FitViewport the touch input x and y is not accurate?

余生长醉 提交于 2019-12-01 07:55:21
问题 libgdx Viewports - Why when I use FitViewport the touch input x and y is not accurate? 回答1: Use viewport.unproject() instead of camera.unproject() so the cropping of the FitViewport is taken into acount. 来源: https://stackoverflow.com/questions/38226563/libgdx-viewports-why-when-i-use-fitviewport-the-touch-input-x-and-y-is-not-acc

Allocate a 2d array in C with one dimension fixed

蹲街弑〆低调 提交于 2019-12-01 07:20:00
问题 I want to dynamically allocate 1 dimension of a 2D array (the other dimension is given). Does this work: int NCOLS = 20; // nrows = user input... double *arr[NCOLS]; arr = (double *)malloc(sizeof(double)*nrows); and to free it: free(arr) 回答1: Not quite -- what you've declared is an array of pointers. You want a pointer to an array, which would be declared like this: double (*arr)[NCOLS]; Then, you'd allocate it like so: arr = malloc(nrows * sizeof(double[NCOLS])); It can then be treated as a

Get position of path at time

ぐ巨炮叔叔 提交于 2019-12-01 06:00:58
is there a nice way to calculate the position of a path (CGPath or UIBezierPath) at a given time (from 0 to 1)? Using CAShapeLayer for example, one can create an animated stroke end. I want to know the position of that stroke end at arbitrary times. Thanks in advance, Adrian You can definitely base your approach on the CADisplayLink and a tracking layer. However, if you don't mind doing a little bit of math on your own, the solution is not too complicated. Plus, you wont have to depend on setting up a display link and extra layers. In fact, you dont even have to depend on QuartzCore. The

2D Platformer Collision Problems With Both Axes

让人想犯罪 __ 提交于 2019-12-01 05:56:44
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

Filling up a 2D array with random numbers in javascript

不想你离开。 提交于 2019-12-01 05:50:35
I'm really sorry if anything like this has been posted here before but I couldn't find anything, I'm kinda new to the site still! So for a while now I've been learning a bit about game development through html5 and javascript and I stumbled upon making tileset maps, I now have a tileset and an 2D array that I want to put certain tiles in (the number varies between 6 and 10 in this case). I figured it could be a cool function to make the map choose between a small set of similar tiles so I don't have to specifically number every tile in the array(just define the type) The method I have