common code for libgdx, probably useless for others.