Best way to track and display score?

I’m trying to add score to my brickbreaker game. When the brick is hit, I want the score to appear above the brick and fade upward. I’ve made a score class, but it is all kinds of jacked up. I’m going to scrap the whole class and start over…I’ve been trying to pass the spritebatch through classes to get to the score class and all that and it’s just not working…

My bricks are drawn in my level class, my game logic is in GameScreen. I’m confused where to draw what and how to put it together…Any advice is very appreciated! I hope i’ve explained my problem correctly…

i think the easy way to do it is :

1- create a variable that hold your score
2-check if the ball hit a brick
if it does
3-add “point” to your score integer
4-draw a string that contain your score int in the X & Y coordinate of the brick
in the same time :
-you create a variable that will be the transparency setting of your string
and you do something like that
- TranSetting -=1 ;
if (tranSetting==0){
tranSetting=0; //just to stop decreasing
}
5-when you hit a brick again, the tranSetting back to it’s normal value and you redo everything from step #3

i dunno if i helped
good luck

Thanks. I meant organization-wise really. I’ve got it implemented already, but i’m not sure i’m doing it the best way. I’m fairly happy with it now though.

A man who carries a cat by the tail learns something he can learn in no other way.
~Mark Twain~

it doesn’t matter if you do it the best way for the first time, in fact, i believe it will “hurt” you specially if you are learning (copying) from other people, do it you way and then when it doesn’t work, you should ask for help, i think it’s the best way to learn

good luck

In the context of gamedev, that is absolute blasphemy. You could make a game loop run perfectly your computer but not on soneone else’s, but you would never notice. It’s extremely important to get it right the first time, otherwise you will develop bad habits…


package com.psillicoder.brickbreaker;

import com.badlogic.gdx.math.Rectangle;

public class Score {
	private static final int distance = 50;
	private int x;
	private int y;
	private String text;
	private int intScore;
	private int iDistance = 0;
	private boolean bDestroyed = false;
	public Score(int score, int x, int y) {
		this.intScore = score;
		this.x = x;
		this.y = y;
		text = "+" + score;
	}

	
	public void update() {
		//for (int i=0;i<=distance;i++) {
		if (iDistance <= distance) {
			if (iDistance==50) {
				bDestroyed = true;
			}else
			{
			this.y++;
			this.iDistance++;
			}
		
		}
	}
	
	public boolean isDestroyed() {
		return bDestroyed;
	}
	
	public int getX() {
		return this.x;
	}
	
	public int getY() {
		return this.y;
	}
	
	
	
	public String getScore() {
		String stringScore = "+" + this.intScore;
		return stringScore;
	}
}

That is my code for showing the score when the brick is hit and moving it up the screen until it disappears. I’m going to add some alpha blending too.