Storing variables of mouseX / mouseY?
in
Programming Questions
•
10 months ago
Hello,
I've been working on a project and have been seriously stumped for the past.. many hours. The first phase of what I'm working on is making it so when you click, it creates an ellipse, and the ellipse slowly starts to move towards the center. Everything except the movement aspect is working fine, but its that very movement that is driving me crazy. I've tried a ton of radically different things, but I'll post the simplest version that otherwise works. This is the [relevant] code:
- void draw() {
- orbMove();
for (int i = 0; i < magnoOrbSet.length; i++) {
if (mousePressed) {
orbX = mouseX;
orbY = mouseY;
stroke(71, 167, 128);
line(mouseX, mouseY, width/2, height/2);
noStroke();
magnoOrbSet[i] = new magnoOrb(orbX, orbY, 20, 20);
magnoOrbSet[i].display(); //all this does is display an ellipse
}
}
}
(The actual function that causes any movement is left out of this, but is called at the top of draw(), let me know if you'd like to see it). So what I think I basically need to do is create a new variable (set to a number, not to the mouse) for every ellipse that is created. And however its done, they all need to be easily altered in mass (since they're all slowly moving towards the center.
Does anybody have any ideas? I'm not the best programmer [yet] and I've been stuck on this for waay too long. Any input would be great.
Thanks
edit:
I figure I should just show the code for movement too
- void orbMove() {
- if (orbX<width/2) {
- orbX -= 1;
- }
- else {
- orbX +=1;
- }
- if (orbY<height/2) {
- orbY -=1;
- }
- else {
- orbY +=1;
- }
- }
1