Hey Leute,
Ich hab einen Canvas und der soll mir Kreise zeichnen. Der erste Kreis wird auch gezeichnet, wenn ich aber einen weiteren Kreis zeichnen möchte passiert garnichts.
Die Kreise hab ich in einer Liste gespeichert (unter Verwendung des Kompositums):
Hier ist der Aufruf(hinzufügen + zeichnen):
Java: MainActivity.java
@Override
public boolean dispatchTouchEvent(MotionEvent event) {
int action = event.getAction();
if (action == MotionEvent.ACTION_DOWN) {
Log.i("Debug", "ACTION_DOWN wurde ausgeführt");
float xView = this.getX();
float yView = this.getY();
float xTouch = event.getX();
float yTouch = event.getY();
int xCircle = ks.root.getDaten().getX();
int yCircle = ks.root.getDaten().getY();
int radius = ks.root.getDaten().getRadius();
/**
* Überprüfen, ob getroffen
*/
boolean getroffen = true;//(xTouch - (xView + radius)) * (xTouch - (xView + radius)) + (yTouch - (yView + radius)) * (yTouch - (yView + radius)) <= radius * radius;
if (getroffen) {
Log.i("Hit", "Kreis getroffen");
ks.einfuegen(new Kreis(x, y));
ks.ausgeben(canvas);
ks.root.getDaten().setHit();
} else {
if (!alreadyFailed) {
alreadyFailed = true;
} else {
//SPIEL BEENDET!
}
}
}
return true;
}
Alles anzeigen
Und hier meine Klasse Kreis:
Java: Kreis.java
package de.dechasa.liste;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import java.util.Random;
import de.dechasa.squarebrains.MainActivity;
public class Kreis implements Datenelement{
public final int RADIUS = 60;
public boolean hit = false;
int red, green, blue, alpha;
int x, y;
Paint paint;
final Paint UMRANDUNG = new Paint();
final Paint GETROFFEN = new Paint();
public Kreis(int maxWidth, int maxHight){
paint = createRandomPaint();
UMRANDUNG.setColor(Color.BLACK);
GETROFFEN.setColor(Color.WHITE);
x = new Random().nextInt(maxWidth) + 1;
y = new Random().nextInt(maxHight) + 1;
}
public Paint createRandomPaint(){
red = new Random().nextInt((255 - 0) + 1);
green = new Random().nextInt((255 - 0) + 1);
blue = new Random().nextInt((255 - 0) + 1);
alpha = new Random().nextInt((255 - 0) + 1);
Paint paint = new Paint();
paint.setColor(Color.argb(alpha, red, green, blue));
return paint;
}
public void setHit(){
hit = true;
}
public void ausgeben(Canvas c){
if(!hit){
c.drawCircle(x, y, RADIUS + 2, UMRANDUNG);
c.drawCircle(x, y, RADIUS, paint);
} else{
getroffen(c);
hit = false;
}
}
public void getroffen(Canvas c){
c.drawCircle(x, y, RADIUS + 2, UMRANDUNG);
c.drawCircle(x, y, RADIUS, GETROFFEN);
}
public int getX(){ return x;}
public int getY(){ return y;}
public int getRadius(){ return RADIUS;}
}
Alles anzeigen
Wenn ich die Methode ausgeben()das erstemal Ausführe tritt kein Problem auf, beim nächstenmal allerdings.
Der Kreis wird zwar eingefügt, aber nicht gezeichnet.
Kann mir jemand helfen?
Danke schon mal.
DodoProgramms