I wrote a simple little game for my toddler where he has to connect two dots by dragging his finger on the screen. On the computer, it is smooth and responsive. In Android, when you drag the line into the second circle and then release, it won't respond unless you hold your finger there for a few seconds. I tried on a Desire, a Sensation and a Transformer. Same each time. Is this typical or is there something wrong with my code?
float lastX, lastY;
float newX, newY;
float circle1X = random(50, 430);
float circle1Y = random(50, 350);
float circle2X = random(50, 430);
float circle2Y = random(450, 750);
float color1 = random(100);
float color2 = random(100);
float dist1;
float dist2;
int score = 0;
void setup() {
size(480, 800);
background(0);
strokeWeight(10);
stroke(255);
smooth();
textAlign(CENTER);
textSize(40);
}
void mousePressed() {
lastX = mouseX;
lastY = mouseY;
dist1 = dist(circle1X, circle1Y, lastX, lastY);
}
void mouseReleased() {
newX = mouseX;
newY = mouseY;
dist2 = dist(circle2X, circle2Y, newX, newY);
if (dist1 < 50 && dist2 < 50) {
// println("got it!");
color1 = random(100);
color2 = random(100);
circle1X = random(50, 430);
circle1Y = random(50, 350);
circle2X = random(50, 430);
circle2Y = random(450, 750);
score = score + 1;
}
}
void draw() {
background(0);
text(score, 20, 40);
colorMode(HSB, 100);
fill(color1, 80, 80);
ellipse(circle1X, circle1Y, 80, 80);
fill(100);
text("1", circle1X, circle1Y + 15);
fill(color2, 80, 80);
ellipse(circle2X, circle2Y, 80, 80);
fill(100);
text("2", circle2X, circle2Y + 15);
if (mousePressed == true) {
if (dist1 < 50) {
line(circle1X, circle1Y, mouseX, mouseY);
}
}
if (score == 10) {
fill(0);
rect(0, 0, width, height);
fill(100);
text("You Win!", width/2, height/2);
}
}
Of course, any suggestions on how to improve this are also welcome. i am very new to programming and always appreciate tips on how I can improve.
1