Advertisement
Guest User

Untitled

a guest
May 25th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1.  
  2. import android.graphics.Canvas;
  3. import android.graphics.Paint;
  4. import android.graphics.Typeface;
  5.  
  6. import java.util.Formatter;
  7.  
  8. import edu.nu.mybouncingball.Ball;
  9.  
  10. /**
  11. * Created by jcicero on 5/23/2016.
  12. */
  13. public class StatusMessage {
  14. // Status message to show Ball's (x,y) position and speed.
  15. private StringBuilder statusMsg = new StringBuilder();
  16. private Formatter formatter = new Formatter(statusMsg);
  17. private Paint paint;
  18.  
  19. // Constructor
  20. public StatusMessage(int color) {
  21. paint = new Paint();
  22. // Set the font face and size of drawing text
  23. paint.setTypeface(Typeface.MONOSPACE);
  24. paint.setTextSize(24);
  25. paint.setColor(color);
  26. }
  27.  
  28. public void update(Ball ball) {
  29. // Build status message
  30. statusMsg.delete(0, statusMsg.length()); // Empty buffer
  31. formatter.format("Ball@(%3.0f,%3.0f),Speed=(%2.0f,%2.0f)", ball.X, ball.Y,
  32. ball.speedX, ball.speedY);
  33. }
  34.  
  35. public void draw(Canvas canvas) {
  36. canvas.drawText(statusMsg.toString(), 10, 30, paint);
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement