We are about to switch to a new forum software. Until then we have removed the registration on this forum.
If i have an array of object from this
class Shot {
PVector loc;
PVector vel;
int r,g,b;
Shot (PVector loc, PVector direction, int r, int g, int b) {
this.loc=new PVector ();
vel=new PVector();
this.loc = loc.get();
vel= direction.get();
vel.normalize();
vel.mult(9);
this.r=r;
this.g=g;
this.b=b;
}
void displayShot() {
loc.add(vel);
noStroke();
fill(r,g,b);
ellipse(loc.x, loc.y, 4, 4);
}
}
and i want to shoot them by ckicking. How could i make it work without shooting too many of those(by to many i mean one each draw). because my game works perfect but it shoots a lot, its nice but THERE ARE TO MANY GOING OUT.
Answers
well i dont know how to show that class nicely. here is the method that shoots
the d boolean goes for the click (left or right)
Could you post the entire code nicely formatted (like your second post)?
i dont even know how the second happend
that was the best i could
i forgot to put where the methot is used,
lM && rM=true when mousePressed()
=false when mouseReleased()
please read the sticky post at the top of the forum about formatting code. then go back and fix your comments. i've done the first one for you.
http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text
For shots you may use an ArrayList instead of simple array, as it helps to maintain its size dynamically. You may add a shot to the ArrayList with a key press and delete it from list when it goes off-screen.
i ve just solved my problem by doing this
for each draw it sums one and each time it sums up to 8 it shoots
http://studio.ProcessingTogether.com/sp/pad/export/ro.9Q6oRai8-41WJ
nice work
also this works better i think.
Also Ater, i dont really know how to use well the ArrayList. I made my entire game using simple arrays :/
So why don't you copy the "Fireworks"'s example.
It uses an array and doesn't launch another Firework when it doesn't find 1 isInactive among them.
its better true. this way works but i will try to improve it to that way because i just put a shotgun that creates 5 objects an thats really messy.
thanks
I think the initial over-shooting is caused by the use of the variable mousePressed instead of the function mousePressed()
The latter is counted only one every time whereas the first is ounted again and again - look at the reference
Chrisir
i ve used a boolean that s true when mouse pressed and false when mouse released. with the void mousePressed() anda void mouseReleased()
Ok, this is different from what I thought
But still wrong. Just use shoot in mousePressed.
The way you do it now generates multiple shoots because it's multiple cycles of draw till you release the mouse
Yeah i know, i want to let the user have his mouse pressed and shot automaticaly, but not so fast as it was before. ive fixed anyways. thanks :D i will share my game later when its "finished"...
you could also use a timer with millis()
I DID NOT KNOW THAT :D thanks a lot :D:D:D:D:D:D:D (i really didn t know, i ve started with processing 2 months ago :/)