Balloon [] balloons = new Balloon[30]; void setup() { size(400, 400); frameRate(20); for (int i = 0; i < balloons.length; i++) { float w = random(20, 45); float h = w + random(5, 10); float x = random(w/2, width-w/2); float y = random(h/2, height-h/2); color c = color(random(255), random(255), random(200), random(128, 200)); balloons[i] = new Balloon(x, y, w, h, c); } } void draw() { background(255); for (int i = 0; i < balloons.length; i++) { // Only act on balloons that have not "popped" if (balloons[i].alive) { balloons[i].display(); //balloons[i].move(); if (balloons[i].hit()) balloons[i].alive = false; } } } class Balloon { // An alternative method to "pop" a balloon boolean alive = true; float x; float y; float w; float h; color c; float xSpeed; float ySpeed; Balloon(float bx, float by, float bw, float bh, color bc) { x = bx; y = by; w = bw; h = bh; c = bc; xSpeed = 3; ySpeed = 7; } void display() { fill(c, 150); ellipse(x, y, w, h); } boolean hit() { float a = w / 2.0; float b = h / 2.0; float ex = mouseX - x; // calculate relative to center of ellipse float ey = mouseY - y; float r = (ex * ex) / (a * a) + (ey * ey) / (b * b); return (r < 1); } void pop() { x= -1000; y= -1000; xSpeed = 0; ySpeed = 0; alive = false; } void move() { x += xSpeed; if (x < w/2 || x > width-w/2) xSpeed = -xSpeed; y += ySpeed; if (y < h/2 || y > height-h/2) ySpeed = -ySpeed; } }
I realized my balloons are not moving any suggestions?
Are you certain that they are being called to move, aside from the commented out line?
@eSpeX it is set to speed I am not why its not moving?
I see that you have a speed set, however you are not calling the draw() method when you instantiate the balloon object so my question was whether you are certain that your calling function was doing that for you. Had you put in some debugging to ensure you were even getting into the proper portions of the class.
Okay. I had a problem with this code first when the balloon were moving but what I needed the balloons to disappear when the mouse is over them. Then when I figured out how to do that the balloons stopped moving.
I can post that up if you want to take a look.
If the balloons were working prior to the mouseover, then the problem is in your solution for the mouse. It has effected the balloons in some manner and you need to understand how that is affecting the movement of the balloons.
In hte constructor of Balloon, you do set a speed. However, that speed is only used within the move method, so I'd say that as long as you don't call move (which, as eSpeX mentioned is commented out), the position of the Balloons is not updated. Try removing the comment from the line with ballons[i].move();
As slotema already pointed out for your - the method for move is comment. Is that processing ? What you see on the screen, comes in Setup() and Draw(). As setup execute it once, in contrast draw() is looping over time.
Thanks, got it to move.
Join our real-time social learning platform and learn together with your friends!