2d

Change canvas gradient object's properties.

var i = 0; var x = 960; var y = 540; var interval = window.setInterval(render, 100); function render() { gradient = cxt.createRadialGradient(x, y, i, x, y, i+10); gradient.addColorStop(0, "rgba(0,0,0,0)");//white inside gradient.addColorStop(.4, "rgba(255,255,255,1)");//white inside gradient.addColorStop(.6, "rgba(255,255,255,1)");//...

creating a 2D array of vectors

I have been trying to create a 2D array of vector for a game. Here is an example of what I am doing. struct TILE { int a; char b; bool c; }; TILE temp_tile; std::vector<TILE> temp_vec_tile; std::vector<std::vector<TILE>> tile; for (int x = 0; x < 10; x++) { for (int y = 0; y < 10; y++) { temp_tile.a = x; tem...

clockwise angle between two line

I want to calculate a clockwise angle between two line segment A and B. So the resulting angle must be between 0 to 360-1 degrees. I've seen all other answers in SO but they gave me negative angles. Thanks. ...

Calculate a vector from a point in a rectangle to edge based on angle

According to Daniel, in his answer, there is no easy way to modify the below function so I bit the bullet and started from scratch. Solution is below (as an answer). Actually, ignore my answer. See Tom Sirgedas' answer it's a lot shorter. I need to modify the solution found here: http://stackoverflow.com/questions/1343346/calculate-a...

Port AWT 2DGraphics to android ?

I'm working on a little 2D game just for fun and was wondering if I could make it run on android as well. I'm using a java.awt.Canvas with a BufferStrategy and drawing sprites with the Graphics2D class methods. I'm new to android, just finished some of the tutorials on the android page and already noticed there's no AWT in android. My ...

Create a Graph from points in a Grid that contains holes

I've got a continuous plane (2-D) containing polygonal obstacles. I am uniformly sampling the plane at discrete positions to create a uniform grid of points. The grid does not have points where obstacles lie (i.e. holes where ever an obstacle is) as shown in the image below. (Please view the image at http://i48.tinypic.com/2efnblg.png f...

Is it possible to reuse an instance of ColorFilter?

I'd like to dynamically change color of a bitmap in an Android application. I'm using Paint.setColorFilter() to do this but I'd like to avoid creating multiple instances of eg. PorterDuffColorFilter inside the game loop. Do you know a way to acomplish this? ...

Need Help With N Queens Program ( checking diagonals )

I'm working on an N Queens program that will allow the user to enter a Queen configuration as a String. For example, when prompted, the user might enter something like Q....Q.....Q..Q. which when displayed as a board would look like: Q . . . . Q . . . . . Q . . Q . Is not a solution! This program is simple in that it assumes that the ...

Java - Better way to block tiles (Login prob)

Ok so I have this 2D Tile RPG I am making.... here is a live applet: http://mystikrpg.com/so/ The code is also at http://mystikrpg.com/so/ Anyway, if you examine the code, it seems the I can only block tile 24 (which are the walls)... Do any of you awesome wise java experts see any way I can have MULTIPLE tiles that are blocked? I h...

2D game algorithm to calculate a bullet's needed speed to hit target?

I have a rather simple bird's-view 2D game where tower sprites defend against incoming moving sprites by shooting a bullet at them. My question: How do I calculate the needed bullet speed for the bullet to reach its moving target, provided that the bullet will always have the same defined speed? I'm using JavaScript and have these sprit...

Perfect circle to perfect circle and Perfect circle to straight line collision HANDLING in Java

I am a newbie at Java, but decided to make a application that has a bunch of balls bouncing around. Please keep in mind that I know almost nothing about normals, which I have seen mentioned a lot in this kind of thread. I have also only take Algebra 1, and know a little bit of trig (sin, cosin and tangent). Anyways... I have collision d...

Simple 2D graphics programming

I used DirectDraw in C and C++ years back to draw some simple 2D graphics. I was used to the steps of creating a surface, writing to it using pointers, flipping the back-buffer, storing sprites on off-screen surfaces, and so on. So today if I want write some 2D graphics programs in C or C++, what is the way to go? Will this same metho...

How to create isometry imitation in 2d Racing game?

How can I modify 2d racing game to seem like isometry? Flash + ActionScript3 ScreeShot The game is totally in 2d. Car moves like it should and while it drives the ground everything is fine. I've added a grey ramp. Now the car should move like the arrows are showing, creating illusion of a 3d (isometry). Ramp is divided in 3 sectors ...

Simple 2D rocket dynamics

I am currently experimenting with some physics toys in XNA using the Farseer Physics library, however my question isn't specific to XNA or Farseer - but to any 2D physics library. I would like to add "rocket"-like movement (I say rocket-like in the sense that it doesn't have to be a rocket - it could be a plane or a boat on the water or...

What package should I be using for 2d animation?

I am working with a client on a 2d map. The map is centered on the user's position and marks various headings and points of interest. As the user moves, the headings change and the points of interest move. My client is insistent on using OpenGL for this, but this seems like overkill. He has mentioned he thinks GDI+ and SDL are too slow...

2d graphics optimization tips

do u know any techniques allowing to speed up 2d primitives such as lines and circles? i develop application that allow to edit images containing such primitives. they can be moved and selected in the same way as windows desktop icons are (including group selection by rectangle). also objects that cursor is on are highlighted. it seems...

DirectX 2D Overlay

I've written a simple program that visualizes some data using a 3D-mesh in the center of my view. The mesh can be rotated and zoomed. Some points on the mesh need to have a description so I would like to add signs next to those points which contains some textual information. What is the best way to create such signs in DirectX9? Should ...

How to scale on-screen pixels?

I have written a 2D Jump&Run Engine resulting in a 320x224 (320x240) image. To maintain the old school "pixely"-feel to it, I would like to scale the resulting image by 2 or 3 or 4, according to the resolution of the user. I don't want to scale each and every sprite, but the resulting image! Thanks in advance :) ...

Tutorials for writing 2D shaders?

I am needing to write some 2D shaders (not 3D, so no vertex shader code or any of that) in HLSL, but have a lot of trouble finding good tutorials. Do you have any resources I can use? ...

C++ - Memory issues with two dimensional array

Hi guys, Following this nice example I found, I was trying to create a function that dynamically generates a 2D grid (two dimensional array) of int values in C++. It works fairly well the first couple of times you change the values but if crashes after that. I guess the part where memory is freed doesn't work as it should. Any ideas w...