Android, how important is deltaTime?

Posted by iQue on Game Development See other posts from Game Development or by iQue
Published on 2012-09-11T17:11:46Z Indexed on 2012/09/11 21:50 UTC
Read the original article Hit count: 357

Filed under:
|
|
|
|

Im making a game that is getting pretty big and sometimes my thread has to skip a frame, so far I'm not using deltaTime for setting the speed of my different objects in the game because it's still not a big enough game for it to matter imo. But its getting bigger then I planned, so my question is, how important is delta Time?

If I should use delta time there is a problem, since speedX and speedY are integers(they have to be for eclipse to let you make a rectangle of them), I cant add delta time very functionally as far as I understand, but might be wrong? Ive tried adding deltaTime to the code below, and sometimes my enemies just not move after spawn, they just stand there and run in the same place

Will add an some code for how I set / use speed:

     public void update(int dx, int dy) {   
        double theta = 180.0 / Math.PI * Math.atan2(-(y - controls.pointerPosition.y), controls.pointerPosition.x - x);

        x +=dx * Math.cos(Math.toRadians(theta));
        y +=dy * Math.sin(Math.toRadians(theta));
    currentFrame = ++currentFrame % BMP_COLUMNS;    
}

     public void draw(Canvas canvas) {
    int srcX = currentFrame * width;
    int srcY = 1 * height;
    Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
    Rect dst = new Rect(x, y, x + width, y + height);
    canvas.drawBitmap(bitmap, src, dst, null);
}

So if someone with some experience with this has any thoughts, please share. Thank you!

Changed code:

    public void update(int dx, int dy, float delta) {   
        double theta = 180.0 / Math.PI * Math.atan2(-(y - controls.pointerPosition.y), controls.pointerPosition.x - x);
        double speedX = delta * dx * Math.cos(Math.toRadians(theta));
        double speedY = delta * dy * Math.sin(Math.toRadians(theta));
        x += speedX;
        y += speedY;
    currentFrame = ++currentFrame % BMP_COLUMNS;    
}

     public void draw(Canvas canvas) {
    int srcX = currentFrame * width;
    int srcY = 1 * height;
    Rect src = new Rect(srcX, srcY, srcX + width, srcY + height);
    Rect dst = new Rect(x, y, x + width, y + height);
    canvas.drawBitmap(bitmap, src, dst, null);
}

with this code my enemies move like before, except they wont move to the right (wont increment x), all other directions work.

© Game Development or respective owner

Related posts about 2d

Related posts about android