game-loop

android game loop vs updating in the rendering thread

喜夏-厌秋 提交于 2019-11-29 22:25:33
I'm making an android game and am currently not getting the performance I'd like. I have a game loop in its own thread which updates an object's position. The rendering thread will traverse these objects and draw them. The current behavior is what seems like choppy/uneven movement. What I cannot explain is that before I put the update logic in its own thread, I had it in the onDrawFrame method, right before the gl calls. In that case, the animation was perfectly smooth, it only becomes choppy/uneven specifically when I try to throttle my update loop via Thread.sleep. Even when I allow the

Why is a “main” game loop necessary for developing a game?

旧城冷巷雨未停 提交于 2019-11-29 21:15:52
I find that most game development requires a main game loop, but I don't know why it's necessary. Couldn't we implement an event listener and respond to every user action? Animations (etc.) could then be played when a event occurs. What is the purpose of a main game loop? The argument that you "need a loop because otherwise what calls the event listener" does not hold water. Admittedly on any mainstream OS, you do indeed have such a loop, and event listeners do work that way, but it is entirely possible to make an interrupt driven system that works without any loops of any kind. But you still

How to show alert dialog in a running thread?

[亡魂溺海] 提交于 2019-11-29 20:51:24
问题 I'm developing an Android Game.In this game, There are tracks on which trains run. This is running thread. I want to show an alert dialog when there is a collision between. when I'm applying alert dialog showing error can't create handler inside thread that has not called looper.prepare() . 回答1: You must need to create AlertDialog inside UI thread else it will never work. If you are in different thread use MessageHandler or can use runOnUiThread (using runnable) to create your dialog inside.

Game loop in Win32 API

久未见 提交于 2019-11-27 21:54:09
问题 I'm creating game mario like in win32 GDI . I've implemented the new loop for game : PeekMessage(&msg,NULL,0,0,PM_NOREMOVE); while (msg.message!=WM_QUIT) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { TranslateMessage(&msg); DispatchMessage(&msg); } else // No message to do { gGameMain->GameLoop(); } } But my game just running until I press Ctrl + Alt + Del ( mouse cursor is rolling ). 回答1: I've always been using something like that: MSG msg; while (running){ if (PeekMessage(&msg, hWnd, 0, 0,

In JavaFX how do I move a sprite across the screen?

浪尽此生 提交于 2019-11-27 04:34:26
I'm new to JavaFX and am trying to write a game where an animated 2D character walks across the screen (for example like the original Legend of Zelda game). I had done this in Swing, by creating my own Sprite class and overriding the paintComponent() method in Swing, and putting my own g2d.drawImage(...); call in there, where it would copy the correct subframe from a Sprite to the correct x,y destination in a JPanel, thus achieving the movement of an animated (walking) 2D image across the screen. How can I do this in JavaFX? I found this excellent example on how to create a sprite: http://blog

In JavaFX how do I move a sprite across the screen?

天涯浪子 提交于 2019-11-26 11:15:15
问题 I\'m new to JavaFX and am trying to write a game where an animated 2D character walks across the screen (for example like the original Legend of Zelda game). I had done this in Swing, by creating my own Sprite class and overriding the paintComponent() method in Swing, and putting my own g2d.drawImage(...); call in there, where it would copy the correct subframe from a Sprite to the correct x,y destination in a JPanel, thus achieving the movement of an animated (walking) 2D image across the