• 9
• 9
• 10
• 9
• 10
• ### Similar Content

• Hello,
I am trying to make a GeometryUtil class that has methods to draw point,line ,polygon etc. I am trying to make a method to draw circle.
There are many ways to draw a circle.  I have found two ways,
The one way:
public static void drawBresenhamCircle(PolygonSpriteBatch batch, int centerX, int centerY, int radius, ColorRGBA color) { int x = 0, y = radius; int d = 3 - 2 * radius; while (y >= x) { drawCirclePoints(batch, centerX, centerY, x, y, color); if (d <= 0) { d = d + 4 * x + 6; } else { y--; d = d + 4 * (x - y) + 10; } x++; //drawCirclePoints(batch,centerX,centerY,x,y,color); } } private static void drawCirclePoints(PolygonSpriteBatch batch, int centerX, int centerY, int x, int y, ColorRGBA color) { drawPoint(batch, centerX + x, centerY + y, color); drawPoint(batch, centerX - x, centerY + y, color); drawPoint(batch, centerX + x, centerY - y, color); drawPoint(batch, centerX - x, centerY - y, color); drawPoint(batch, centerX + y, centerY + x, color); drawPoint(batch, centerX - y, centerY + x, color); drawPoint(batch, centerX + y, centerY - x, color); drawPoint(batch, centerX - y, centerY - x, color); } The other way:
public static void drawCircle(PolygonSpriteBatch target, Vector2 center, float radius, int lineWidth, int segments, int tintColorR, int tintColorG, int tintColorB, int tintColorA) { Vector2[] vertices = new Vector2[segments]; double increment = Math.PI * 2.0 / segments; double theta = 0.0; for (int i = 0; i < segments; i++) { vertices[i] = new Vector2((float) Math.cos(theta) * radius + center.x, (float) Math.sin(theta) * radius + center.y); theta += increment; } drawPolygon(target, vertices, lineWidth, segments, tintColorR, tintColorG, tintColorB, tintColorA); } In the render loop:
polygonSpriteBatch.begin(); Bitmap.drawBresenhamCircle(polygonSpriteBatch,500,300,200,ColorRGBA.Blue); Bitmap.drawCircle(polygonSpriteBatch,new Vector2(500,300),200,5,50,255,0,0,255); polygonSpriteBatch.end(); I am trying to choose one of them. So I thought that I should go with the one that does not involve heavy calculations and is efficient and faster.  It is said that the use of floating point numbers , trigonometric operations etc. slows down things a bit.  What do you think would be the best method to use?  When I compared the code by observing the time taken by the flow from start of the method to the end, it shows that the second one is faster. (I think I am doing something wrong here ).
Thank you.

• I'm working on an endless wave-based arkanoid/space invaders style hybrid. Bricks spawn above the screen and move down line by line. You must destroy all bricks before they hit the bottom of the screen. There will be multiple types of bricks and random power-up spawns. Currently I am just using a simple Log function that takes in the current wave as a parameter. This works to increase the number of bricks spawned each wave, but I want to find a way to make this much more complicated. Here is a list of everything that should be effected by the increase in difficulty:
1. Number of bricks
2. Types of bricks (1 hit bricks, 2 hit bricks, 3 hit bricks, etc.)
3. Speed that the bricks move down the screen
4. How often power-ups spawn
The biggest problem here is that I can't just increase all of these with each new wave. If I did that, it would quickly become far to difficult. What I would like is an algorithm that gives some amount of variance in the increase between all 4 of these. Say one wave we put 60% of the increase to number of bricks, 20% increase to power-up spawns, 10% to types of bricks and 10% to speed of bricks. But on the next wave those percentages are all moved around and we now have say 105% to work with so the overall difficulty has increased as well. The different types of bricks need to also change to the point where if someone has made it to a certain wave, such as wave 50 for example, there are no longer any 1 hit bricks. We now would have just 2-4 hit bricks, and if they are crazy good and make it all the way to round 100, Now it's just 3-5 hit bricks, etc.
If anybody has any good ideas or suggestions on this, I'd appreciate anything you've got! Thanks!

•

Hi, I am currently a college student studying to become a Game Developer. I need to interview current game developers for a class I'm taking. if anyone seeing this could answer just the 5 questions that I have provided below as well as your name, current position, and how many years you've been in the game industry. I'd really appreciate any responses.

Name:
Position:
Year in the industry:

What was the starting salary?
How many hours do you work?
What did you learn outside of school that was useful?
How did you get your job and how hard was it to find it?

-Alex Daughters
• By fazook
Hi, guys!
I have a rather abstract question, because I don't know which side to approach to its solution. So, I would appreciate any information.
I have a task to create a simple game that generates floor plans and I following by this perfect algorithm (https://www.hindawi.com/journals/ijcgt/2010/624817/). At the moment I use squarified treemaps (http://www.win.tue.nl/~vanwijk/stm.pdf) and here no problems. I create nested array in which elements are rooms with size. Problems starts when I trying to represent generated "rooms" as edges and vertexes (a, b, c, d steps in attached picture) That representation can give me access to this elements as special "entities" in future game versions.
I don't have skills in graphs (and do I need graphs?) and at the moment totally stucked at this step. How can I represent room walls as trees (or graphs?) at this step? Calculate size of squares (rooms) and convert sides to a vectors? Then in loop find shared vectors (same position by "x" or "y") and determine them as shared walls? The instinct tells me that there exist more elegant and efficient ways.

•    Hello , i would like to showcase my first game project, a simple endless casual arcade game called Apples Mania : Apple Catcher. The game has simple goal , scoring as high as possible by collecting falling apples while the difficulty gradually increases. Different apples are worth different amount of points and there are also 2 power-ups to help you in your challenge.
The game took me about 2 months to complete and polish and i made everything except for the music tracks and some of the sound files. Made in unity and blender3d.
Would appreciate any kind of feedback.

A trailer showing basic game-play:

# Android The main game loop FPS independent

## Recommended Posts

I am just a newbie game developer, I am trying to create a frame independent game loop.

I am currently using the following code

 private class MainGameThread extends Thread {
public static final int PAUSE_SLEEP_TIME = 10;
long previous = getCurrentTimeInMillis();
long totalElapsed = 0;
long gameTimeStart = 0;
long currentTime = getCurrentTimeInMillis();
long accumulatorTime = 0;

@Override
public void run() {
gameTimeStart = getCurrentTimeInMillis();
while (mIsRunning) {
// Pause game
while (mIsPaused) {
try {
} catch (InterruptedException e) {
e.printStackTrace();
}
}
long current = getCurrentTimeInMillis();
long elapsed = current - previous;
previous = current;
processGameInput();
updateGameState(elapsed);
totalElapsed += elapsed;
if (totalElapsed > MainGame.MS_PER_FRAME) {
drawGame();
totalElapsed -= MainGame.MS_PER_FRAME;
if (totalElapsed > MainGame.MS_PER_FRAME) {
Log.e("GAME", "Performance warning, rendering or update took too long");
}
}
checkIfGameShouldStop(gameTimeStart);
}
shutdownGracefully();
}

private void shutdownGracefully() {
}
}

It works, how ever it performs differently on different devices

In my game models update method I am performing the following actions

  mCenterX += (mVelocityVector.x * timeElapsed);
mCenterY += (mVelocityVector.y * timeElapsed + gameSpeed.getValue())

But I can't understand the final example

double t = 0.0;
double dt = 0.01;

double currentTime = hires_time_in_seconds();
double accumulator = 0.0;

State previous;
State current;

while ( !quit )
{
double newTime = time();
double frameTime = newTime - currentTime;
if ( frameTime > 0.25 )
frameTime = 0.25;
currentTime = newTime;

accumulator += frameTime;

while ( accumulator >= dt )
{
previousState = currentState;
integrate( currentState, t, dt );
t += dt;
accumulator -= dt;
}

const double alpha = accumulator / dt;

State state = currentState * alpha +
previousState * ( 1.0 - alpha );

render( state );
}

What does the State class object mean in this case.

Could someone please help to adapt this example to my case or explain the example from the article and how I could update my loop to be frame independent ?

Thanks

##### Share on other sites

I'm familiar with that article and have used it as reference for my own projects. The state object represents the state-of-being of objects being simulated in the game/physics/whatever simulation.

That is, the state contains position, velocity, rotation/orientation, etc. And each game object has 2 states: the most recently computed state (let's call it the previous state), and the one before that (let's call it the ultra-previous state).

Then, all that talk of accumulators and interpolation is saying to compute the "actual current state of the world" by interpolating between the ultra-previous state and the previous state. The motivation of this approach is to always "consume" all of the frame time available, in each cycle of the loop. And it probably helps for when you get into online multiplayer (a big topic on the gafferongames blog) - it probably helps ensure that each instance of the networked game has the same idea of what state each object in the game world is in.

Personally, I prefer not to go that route. Instead, I just carry over whatever remains in the accumulator, for the next game loop cycle. It saves the cost of interpolating between states, and it works well enough for my purposes.

(I just realized I said all that, but didn't say how to change your code, which was a party of your original question. But I'll leave that as an exercise for the reader :-D hopefully the explanation of state helped)

Edited by masskonfuzion

##### Share on other sites

As masskonfuzion says, at frame N there will be three states:

• The Physics state at frame N-1; that is the state of the previous frame (state in this case means position, orientation and scale of all objects; and maybe something else if needed, like velocity)
• The Physics state at frame N; that is the state of the current frame
• The graphics state, which is an interpolation somewhere between N-1 and N.

1 hour ago, masskonfuzion said:

And it probably helps for when you get into online multiplayer (a big topic on the gafferongames blog) - it probably helps ensure that each instance of the networked game has the same idea of what state each object in the game world is in.

Personally, I prefer not to go that route. Instead, I just carry over whatever remains in the accumulator, for the next game loop cycle. It saves the cost of interpolating between states, and it works well enough for my purposes.

Errr... really the main motivation for interpolating is to detach physics framerate from graphics framerate. So your physics may be updated at 30hz and your graphics rendered at 60hz; or physics at 120hz and graphics at 60hz.

Another big reason is to combine variable frame rate for graphics (which is good for smoothness and performance) and fixed frame for physics (which is good for simulation stability and required for achieving determinism). Without interpolation, you either update at fixed framerate, or at variable framerate. Interpolation gives you both.

You can even go beyond what gafferongames' teaches and put graphics in a separate thread; allowing to do graphics in a different CPU core, but this is a more advanced topic.

##### Share on other sites

Thanks everyone for answers. I have much simpler case. I don't need to have all these complex calculations depending on different forces currently acting on an object.

I have  a simple game. I have only one object a ball that is falling down, or a different shape. I need just to catch it or skip.

So I guess I don't need to integrate and save states between frames.

The only one variable that I change in my update method is

mCenterX += (mVelocityVector.x * timeElapsed);

mCenterY += (mVelocityVector.y * timeElapsed + gameSpeed.getValue())

These variables just represent the position of a falling shape and that is all.

The reason I tried to apply described method, just to develop even a simple game following best practices.

So maybe you could suggest me another way to achieve FPS independent rendering considering my requirements.

I would be grateful for any further help

Edited by durianodour

##### Share on other sites

At first glance your code looks fine, can you be more specific about how it's inconsistent across different devices?

You haven't provided your drawing code, but note that if you are using Repaint, the screen will not be repainted immediately (it will wait for the next RepaintManager cycle). If you are using Repaint, try changing it to paintImmediately.