I want a score to add up to a score variable every time the user clicks on a bitmap. The score is then going to be used in another class. But so far i cant get it to work, i dont get any errors when running but it just always displays 0 (which is the default string in the Text View).
This is the method that counts the score and should "set" it in another script:
@Override public void run(){
Point size = new Point();
Display display = getWindowManager().getDefaultDisplay();
display.getSize(size);
Random wR = new Random();
Random hR = new Random();
int width = size.x;
int height = size.y;
int randomW = wR.nextInt(width-50)+50;
int randomH = hR.nextInt(height-50)+50;
CheckScore scoreClass = new CheckScore();
while (running){
if(!surface.getSurface().isValid())
continue;
Canvas canvas = surface.lockCanvas();
canvas.drawColor(Color.rgb(85, 107, 47));
canvas.drawBitmap(incect[frame], randomW, randomH, null);
if ((touch.x >= randomW && touch.x <(randomW + xBitmap) && (touch.y >= randomH && touch.y < (randomH+yBitmap)) && move == true)){
randomW = wR.nextInt(width-50)+50;
randomH = hR.nextInt(height-50)+50;
if (randomW > width - 200){
randomW = width - 200;
}
if (randomH > height - 200){
randomH = height - 200;
}
canvas.drawBitmap(incect[frame], randomW, randomH, null);
hasMoved = true;
scoreClass.score = score;
score = score +1;
}
And this is the scripts that should recieve the score and display it:
package com.example.bena.23;
import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;
public class CheckScore extends AppCompatActivity {
int score;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.score);
getScore();
}
public void getScore(){
TextView text = (TextView)findViewById(R.id.thisScore);
text.setText(Integer.toString(score));
}
}
I only wrote the method (run()) because of the script size. I would much appreciate if some one could help me in the matter.