Hey guys I have a rather odd (or it may just be my stupidity) question. I have a little animation method which is shown below:
void setSprites(TextureRegion mainMob, TextureRegion upMob_STILL,
TextureRegion upMob_LEFT, TextureRegion upMob_RIGHT,
TextureRegion downMob_STILL, TextureRegion downMob_LEFT,
TextureRegion downMob_RIGHT, TextureRegion rightMob_STILL,
TextureRegion rightMob_LEFT, TextureRegion rightMob_RIGHT,
TextureRegion leftMob_STILL, TextureRegion leftMob_LEFT,
TextureRegion leftMob_RIGHT) {
if (timer < 4)
timer += .1f;
else
timer = 0;
// walking right animation
if (direction == 3) {
if (timer < 1) {
mainMob = rightMob_STILL;
} else if (timer > 1 && timer < 2) {
mainMob = rightMob_LEFT;
} else if (timer > 2 && timer < 3) {
mainMob = rightMob_STILL;
} else if (timer > 3) {
mainMob = rightMob_RIGHT;
}
}
// walking left animation
if (direction == 2) {
if (timer < 1) {
mainMob = leftMob_STILL;
} else if (timer > 1 && timer < 2) {
mainMob = leftMob_LEFT;
} else if (timer > 2 && timer < 3) {
mainMob = leftMob_STILL;
} else if (timer > 3) {
mainMob = leftMob_RIGHT;
}
}
// walking up animation
if (direction == 0) {
if (timer < 1) {
mainMob = upMob_STILL;
} else if (timer > 1 && timer < 2) {
mainMob = upMob_LEFT;
} else if (timer > 2 && timer < 3) {
mainMob = upMob_STILL;
} else if (timer > 3) {
mainMob = upMob_RIGHT;
}
}
// walking down animation
if (direction == 1) {
if (timer < 1) {
mainMob = downMob_STILL;
} else if (timer > 1 && timer < 2) {
mainMob = downMob_LEFT;
} else if (timer > 2 && timer < 3) {
mainMob = downMob_STILL;
} else if (timer > 3) {
mainMob = downMob_RIGHT;
}
}
}
As you can see I have quite a lot of parameters, but that should all be working. I call the method appropriately, but the “mainMob” texture region is never changed. If I avoid using these parameters by doing this
void setSprites() {
if (timer < 4)
timer += .1f;
else
timer = 0;
// walking Assets.right animation
if (direction == 3) {
if (timer < 1) {
Assets.mainCreeper = Assets.rightCreeper_STILL;
} else if (timer > 1 && timer < 2) {
Assets.mainCreeper = Assets.rightCreeper_LEFT;
} else if (timer > 2 && timer < 3) {
Assets.mainCreeper = Assets.rightCreeper_STILL;
} else if (timer > 3) {
Assets.mainCreeper = Assets.rightCreeper_RIGHT;
}
}
// walking left animation
if (direction == 2) {
if (timer < 1) {
Assets.mainCreeper = Assets.leftCreeper_STILL;
} else if (timer > 1 && timer < 2) {
Assets.mainCreeper = Assets.leftCreeper_LEFT;
} else if (timer > 2 && timer < 3) {
Assets.mainCreeper = Assets.leftCreeper_STILL;
} else if (timer > 3) {
Assets.mainCreeper = Assets.leftCreeper_RIGHT;
}
}
// walking Assets.up animation
if (direction == 0) {
if (timer < 1) {
Assets.mainCreeper = Assets.upCreeper_STILL;
} else if (timer > 1 && timer < 2) {
Assets.mainCreeper = Assets.upCreeper_LEFT;
} else if (timer > 2 && timer < 3) {
Assets.mainCreeper = Assets.upCreeper_STILL;
} else if (timer > 3) {
Assets.mainCreeper = Assets.upCreeper_RIGHT;
}
}
// walking Assets.down animation
if (direction == 1) {
if (timer < 1) {
Assets.mainCreeper = Assets.downCreeper_STILL;
} else if (timer > 1 && timer < 2) {
Assets.mainCreeper = Assets.downCreeper_LEFT;
} else if (timer > 2 && timer < 3) {
Assets.mainCreeper = Assets.downCreeper_STILL;
} else if (timer > 3) {
Assets.mainCreeper = Assets.downCreeper_RIGHT;
}
}
}
Everything works great this way. The “Assets.mainCreeper” is changed to whatever the current animation state should be. The only reason I can’t do it like that is that I have many different types of mobs so I would want to use parameters rather than making a class or method specific for each mob type. Is there some specific reason that using parameters makes this not work at all? From my code (in the parameter example) everything is the same as the parameterless example which would make me think it would work. Is there something with using parameters that stops this from working properly? I know this may be a long question but I appreciate the help!
P.s. after the current image is set to the “mainMob” texture region or the “Assets.mainCreeper” i draw that texture region seems obvious but i thought i would include it.