game-loop

Javascript - gameloop using delta time

风格不统一 提交于 2021-02-08 09:58:06
问题 I am trying to implement a gameloop that uses delta time. I got the following code from this article, however I feel it does not explain this type of gameloop well. I have researched on requestAnimationFrame and none of the explenations seem to be useful. Can someone simply break down how this loop works? function timestamp() { return window.performance && window.performance.now ? window.performance.now() : new Date().getTime(); }, var now, dt = 0, last = timestamp(), step = 1/60; function

Javascript - gameloop using delta time

只愿长相守 提交于 2021-02-08 09:57:29
问题 I am trying to implement a gameloop that uses delta time. I got the following code from this article, however I feel it does not explain this type of gameloop well. I have researched on requestAnimationFrame and none of the explenations seem to be useful. Can someone simply break down how this loop works? function timestamp() { return window.performance && window.performance.now ? window.performance.now() : new Date().getTime(); }, var now, dt = 0, last = timestamp(), step = 1/60; function

How to set up a 30fps loop in C++/Qt

让人想犯罪 __ 提交于 2021-01-28 19:30:11
问题 I am currently developing a small game/simulation for school in C++ with Qt and I have some background with Java. My question is how to setup a basic gameloop with Qt in an 800/600 window. I tried drawing into a GraphicsView-window with overriding the paintEvent but I can't set up a loop like that and I have some kind of mistake with overriding it. #include "mainwindow.h" #include <QGraphicsView> #include "graphicsview.h" MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { resize

Gaffer on games timestep: std::chrono implementation

前提是你 提交于 2020-12-01 07:43:09
问题 If you're not familiar with the Gaffer on Games article "Fix your Timestep", you can find it here: https://gafferongames.com/post/fix_your_timestep/ I'm building a game engine, and in an effort to get more comfortable with std::chrono I've been trying to implement a fixed time step using std::chrono for.. a couple of days now and I can't seem to wrap my head around it. Here is the pseudo-code I'm working towards: double t = 0.0; double dt = 0.01; double currentTime = hires_time_in_seconds();

Sleep/Wait without consuming CPU

半城伤御伤魂 提交于 2020-01-21 10:33:52
问题 So I am simulating this smartphone app to Windows. It's a game that runs it's logic and draw methods at a 1/60 rate. In milliseconds this is 16.6667 I've implemented this game loop: private const double UPDATE_RATE = 1000d / 60d; private void GameLoop() { double startTime; while (GetStatus() != GameStatus.NotConnected) { startTime = Program.TimeInMillis; //Update Logic while (Program.TimeInMillis - startTime <= UPDATE_RATE) { //Thread.Yield(); it consumed CPU before adding this too, adding

error #1009 addChld() as3 with loop

耗尽温柔 提交于 2020-01-15 10:14:28
问题 when i try to addChild my class it says "Cannot access a property or method of a null object reference. at class_obj() at Main()" error #1009 i need to know how to have a class that has a gameloop for testing things like collision and stuff please help! and if i dont have eventlistener enter frame on the object ir works but i need the listener for the loop. Main class package { import flash.display.MovieClip; import flash.events.Event; public class Main extends MovieClip { var mc:class_obj;

Annoying lags/stutters in an android game

喜你入骨 提交于 2020-01-09 05:00:06
问题 I just started with game development in android, and I'm working on a super simple game. The game is basically like flappy bird. I managed to get everything to work, but I get a lot of stutters and lags. The phone I'm using for testing is LG G2, so it should and does run games much heavier and complex than this. Basically there are 4 'obstacles' that are a full screen width apart from each other. When the game starts, the obstacles start to move (toward the character) at a constant speed. The

Is using “SwingUtilities.invokeLater()” inside a Java game loop a bad practice?

大兔子大兔子 提交于 2020-01-03 19:17:24
问题 So, I'm creating a isometric game in JAVA; to put it simply, it has a map made of tiles, and when the user drag the mouse on the screen, the map moves. To give you guys an idea, it currently looks like this: Before the actual prototype version, I built a small java application that had no "Game Loop" per se; the only thing updating the tile-map position was the event listeners for the mouse dragging, and it called the repaint() method after the movement update. It worked fine, and I could