Jump to content
  • Advertisement

johnyX

Member
  • Content Count

    10
  • Joined

  • Last visited

Community Reputation

124 Neutral

About johnyX

  • Rank
    Member
  1. Currently I have this. As I said it doing periodical "lags" each 1/2 second (in same intervals and same lenghts). /* Time vars */ private float oldTimeSinceStart = 0; private float accumulatedTime = 0; private float maxDeltaTime = 0.1f; // 10 FPS private float fixedTime = 0.016f; // 60 FPS /* - - - - - */ public MainThread(SurfaceHolder surfaceHolder, GamePanel gamePanel) { super(); this.surfaceHolder = surfaceHolder; this.gamePanel = gamePanel; } @Override public void run() { while (running) { try { canvas = null; canvas = this.surfaceHolder.lockCanvas(); synchronized (surfaceHolder) { float timeSinceStart = System.nanoTime(); float deltaTime = (timeSinceStart - oldTimeSinceStart) / 1000000000; oldTimeSinceStart = timeSinceStart; deltaTime = Math.min(deltaTime, maxDeltaTime); accumulatedTime += deltaTime; while (accumulatedTime >= fixedTime) { accumulatedTime -= fixedTime; this.gamePanel.update(); } this.gamePanel.draw(canvas); } } catch (Exception e) {} finally { if(canvas!=null) { try { surfaceHolder.unlockCanvasAndPost(canvas); } catch (Exception e) {} } } } } In the code where this.gamePanel.update() is, I didn't found a solution how to update game objects with time (as you wrote - Update(float time) { UpdatePhysics(time); UpdateAI(time); UpdateEtc(time);  }   so I let it like this). Its strange about these lags on phones (it doing more than on two's I've wrote), could you please check if everything above is okay?  :/ .
  2. Okay tested currently available devices to me. I can't test A7600-F tablet and Xperia Z3 Compact phone right now, but tested these devices:   Galaxy S - Android 2.3.3 - game running correctly.   old Galaxy Ace - Android 2.3.6 - I'm getting periodical lags here (about each half second) - same as in S3 mini. I don't think it's HW issue.   S3 Mini - Android 4.1.2 - problem too, I'm getting there periodical lags - but it must be doing something in code, because this phone is newest from these two's and is perceptible faster. I'm getting same lags about each half second.   But every phone of these three has +- same objects speed as others, so that's great! Just that "lagging"...
  3. Thank you SeanMiddleditch I've read and understand much more from your writing, than from posted link. On A7600-F tablet it seems it's running perfectly, although it reachs distance in one second lower than it should (from distance calculation (screenWidth /4) * fixedTime). //I've edited divide a little bit //Now with 4, it reaches whole screen width in 3 seconds. With 2, it was reaching screen width in 1 second.       On my old gold Ace, it runs very slow, but that's probably problem of whole phone, because it's framerate is very low on today's phones hardware (and it cannot reach at least 30fps, and target 60fps at all). It runs smoothly, but with periodical lag spikes. But I don't take this device seriously about games because of it's "age".   I'll try two more phones later today.   By the way, in your code is "Update(fixedTime);", I think it shouldn't matter if I make distance calculation before update or right in it, because there are just constant values, right? Because I'm calling only Update(); at the moment. (Just to be sure )
  4. I'm sorry but I can't understand this link you refered. Maybe I'm dumb, but I've seen this page so many times and still didn't get it. Don't you have any explanations/tutorials for obtuse people like me?   My delta is calculated as, float deltaTime = (timeSinceStart - oldTimeSinceStart) / 1000000000; //in order to get it in seconds   Device framerate is about ~30fps (tablet), 25fps on my very old Galaxy ace S5830i and about 70-80fps on Xperia.
  5. I'll try to put here key things of whole app.   Each update I'm updating game objects X position and then (in same update) drawing them on canvas. Position of objects are done as object.x += speed;   Speed is calculated in Mainthread, while running. Using calc = (screenWidth /2)* deltaTime. speed = Math.round(calc) should I get distance (speed), that object have to travel for 1 second - every device updates in 1 second (but it evidently doesn't always).   Then, - if I have distance calculated before game starts (I mean player play) and I don't change it, the game is ok (but distance sometimes not, as you can see on Xperia - 86px per update is extreme large.   - if I have distance calculated also durring game, it's breaking my objects on scene, making some moving faster than others.
  6. That's my problem. If I calculate it in game when player plays, my object's positions getting messed up (but I don't know why). Only thing I'm doing to them is moving their position x += speed (or distance as Nanoha said), on each update. I don't know why it fails.
  7. Yes exactly this I'm doing. After calculation I have just object.X += speed. - - -   Sorry for misunderstanding, what do you mean with that displacement?     Note: I'm calculating this before player can play. Once he plays (or I allow him to), I stop any calculations and "speed" remains constant. So this result is just indicative (but I'm ok with that - that's reason why I'm doing this - to get average same speed, exact isn't necessary). Reason why this speed remains constant is, that I can't manipulate with it ingame (it would break my objects on scene).
  8. I'm using round to round it only for draw (since object can't pass 0.5 pixel). Then, next calculation is added to drawed object.X - that means to the rounded value.
  9. Hi, I would need help; I have game object which isn't moving in correct speed calculated from deltaTime bellow. It should reach half of the screen in one second, on any device. Devices tested: tablet A7600-F - deltaTime = 0.03355443; (res. 720x1280) Xperia Z3 Compact - deltaTime = 0.13421772; (res. 720x1280) Calculation: calc = (screenWidth /2)* deltaTime. //I have app in landscape mode speed = Math.round(calc); - - - - - Got: speed on tablet - 21px per update; speed on xperia - 86px per update; You can see these results are very different (actualy it should be something about 8px - 20px). Game object is then extreme fast on Xperia (on tablet it's just a bit faster - speed is more than half of the screen per second). What am I missing?
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!