Skip to main content
Removing update meta-tag, as discussed here https://gamedev.meta.stackexchange.com/a/2510/39518
Link
DMGregory
  • 140.8k
  • 23
  • 257
  • 401
added 872 characters in body
Source Link

A method called setRegion() sets the current animation frames of the object:

protected void setRegion(String name, float frameDuration) {
    currentFrame = atlas.findRegion(name, 0);
    if (currentFrame == null) {
        currentFrame = atlas.findRegion(name, -1);
    }
    width = currentFrame.getRegionWidth();
    height = currentFrame.getRegionHeight();
    animationStateTime = 0;
    animation = new Animation(frameDuration, atlas.findRegions(name),      Animation.PlayMode.LOOP);
}

And in the update() of the objects this is called:

            currentFrame = (TextureAtlas.AtlasRegion) animation.getKeyFrame(animationStateTime, isLooping);

The getCurrentFrame() method only returns currentFrame variable. The alpha is a field with a value between 0 and 1. (getAlpha() returns only the field)

My question is that considered a "heavy" activity? Can this be a significant impact on the FPS values? Because I'm running my game on old devices (like Galaxy S2) and the FPS can get pretty low values. I'm trying to find the cause to it.
I used to have a reference to every list but with the time I realized I'm going to have too much lists, so I decided to do it like this. Maybe you know a better way of holding references to all game objects?

My question is that considered a "heavy" activity? Can this be a significant impact on the FPS values? Because I'm running my game on old devices (like Galaxy S2) and the FPS can get pretty low values. I'm trying to find the cause to it.
I used to have a reference to every list but with the time I realized I'm going to have too much lists, so I decided to do it like this. Maybe you know a better way of holding references to all game objects?

A method called setRegion() sets the current animation frames of the object:

protected void setRegion(String name, float frameDuration) {
    currentFrame = atlas.findRegion(name, 0);
    if (currentFrame == null) {
        currentFrame = atlas.findRegion(name, -1);
    }
    width = currentFrame.getRegionWidth();
    height = currentFrame.getRegionHeight();
    animationStateTime = 0;
    animation = new Animation(frameDuration, atlas.findRegions(name),      Animation.PlayMode.LOOP);
}

And in the update() of the objects this is called:

            currentFrame = (TextureAtlas.AtlasRegion) animation.getKeyFrame(animationStateTime, isLooping);

The getCurrentFrame() method only returns currentFrame variable. The alpha is a field with a value between 0 and 1. (getAlpha() returns only the field)

My question is that considered a "heavy" activity? Can this be a significant impact on the FPS values? Because I'm running my game on old devices (like Galaxy S2) and the FPS can get pretty low values. I'm trying to find the cause to it.
I used to have a reference to every list but with the time I realized I'm going to have too much lists, so I decided to do it like this. Maybe you know a better way of holding references to all game objects?

added 936 characters in body
Source Link

My drawObject() code:

private void drawObject(GameObject object, float x, float y) {
    if (object == null) {
        return;
    }
    if (object.getVisibility()) {
        TextureAtlas.AtlasRegion currentFrame = object.getCurrentFrame();
        if (currentFrame != null) {
            float objectAlpha = object.getAlpha();
            Color color = batch.getColor();
            if (objectAlpha != 1) {
                color.a = object.getAlpha();
                batch.setColor(color);
            }
            batch.draw(currentFrame, x - object.getOriginX(), y - object.getOriginY(), object.getOriginX(), object.getOriginY(), currentFrame.getRegionWidth(), currentFrame.getRegionHeight(), object.scaleX, object.scaleY, object.getSpriteDirection());
            color.a = 1;
            batch.setColor(color);
        }
    }
}

My question is that considered a "heavy" activity? Can this be a significant impact on the FPS values? Because I'm running my game on old devices (like Galaxy S2) and the FPS can get pretty low values. I'm trying to find the cause to it.
I used to have a reference to every list but with the time I realized I'm going to have too much lists, so I decided to do it like this. Maybe you know a better way of holding references to all game objects?

My question is that considered a "heavy" activity? Can this be a significant impact on the FPS values? Because I'm running my game on old devices (like Galaxy S2) and the FPS can get pretty low values. I'm trying to find the cause to it.
I used to have a reference to every list but with the time I realized I'm going to have too much lists, so I decided to do it like this. Maybe you know a better way of holding references to all game objects?

My drawObject() code:

private void drawObject(GameObject object, float x, float y) {
    if (object == null) {
        return;
    }
    if (object.getVisibility()) {
        TextureAtlas.AtlasRegion currentFrame = object.getCurrentFrame();
        if (currentFrame != null) {
            float objectAlpha = object.getAlpha();
            Color color = batch.getColor();
            if (objectAlpha != 1) {
                color.a = object.getAlpha();
                batch.setColor(color);
            }
            batch.draw(currentFrame, x - object.getOriginX(), y - object.getOriginY(), object.getOriginX(), object.getOriginY(), currentFrame.getRegionWidth(), currentFrame.getRegionHeight(), object.scaleX, object.scaleY, object.getSpriteDirection());
            color.a = 1;
            batch.setColor(color);
        }
    }
}

My question is that considered a "heavy" activity? Can this be a significant impact on the FPS values? Because I'm running my game on old devices (like Galaxy S2) and the FPS can get pretty low values. I'm trying to find the cause to it.
I used to have a reference to every list but with the time I realized I'm going to have too much lists, so I decided to do it like this. Maybe you know a better way of holding references to all game objects?

added 71 characters in body
Source Link
Loading
Source Link
Loading