We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Here I am adding an element with every four incremental hits. Here, only one element should add every set = 4 ,8 ,12,16,20 ..... but it is not happening can any one help me with this
void draw(){
sets = hits;
if (sets > 0 && sets%4==0) {
Balls P = new Balls();
Ballscollection.add(P);
println(sets);
}
hits++;
}
Answers
If I change the code as this:
I see the value to increase by 4.
Notice I println() sets, not set.
though it is printing sets correctly but when I add balls in ArrayList it adds more than one I dont know why this is happening.
Well, it adds one "balls" (why the plural on the class name?) every 4 frames. At 60 frames per second, it adds quickly lot of balls... Not sure what is your problem, exactly.
Problem is, I want to add one ball at one time which is not happening but I have the same thought as yours may be because of high frame Rate is adding more balls so can you tell me how to avoid this and yes I can't slow down my frame Rate.
Just use
if (frameCount % FREQUENCY == 0) {}
Where FREQUENCY is the # of frames to skip.
Thanks GoToLoop ! but I have to add new ball after score gets increased by 4 unit so it is like as soon as you scored 4,8,12,16,20 ...... a new ball gets added every time in the game.
Then don't increment
hits
on each frame! Only when the score is increased.