[SOLVED] sin(x) going too fast to be effective

well thank you guys for the help; this code seems to be working great :smiley:


	private static float x = 0;
	private static float derp = 0;
	
	public static void star(SpriteBatch batch) {
		for (x = derp; x < derp + 10; x += 1f) {
			batch.draw(Assets.star, 200, (MathUtils.sinDeg(x) * 50) +200 );
		}
		derp += 10;
		if (derp > 360){
			derp = 0;
		}
	}

please excuse the naming of the derp variable lol

You may be getting the effect you want in this specific case, but this is not how you should be doing it. Common practice is to draw an object only once per time step. You, on the other hand, are calling batch.draw 10 times every single time you call star.

This will work better. you aren’t wasting resources drawing the same thing over and over again and you don’t need to hold onto the x variable.

	
   private static float derp = 0;
   
   public static void star(SpriteBatch batch) {
         batch.draw(Assets.star, 200, (MathUtils.sinDeg(derp) * 50) +200 );

      derp += 10;   // if it is waving too quickly, increment derp my less.
      if (derp > 360){
         derp = 0;
      }
   }

Thanks actual! That code does make more sense then my for loop face palm thanks again 8)

Yeah thats what i sayd :slight_smile:
Its for you to figure out .

Ah the guy above me spoiled it already.