|
Author |
Topic: several falling objects (Read 477 times) |
|
jno
|
several falling objects
« on: Sep 9th, 2004, 1:57pm » |
|
Hey. I'm trying to make serveral falling objects in my program. (in y pos). But when i call meteor(); in void loop it just draws one image. Some one there who can help me develope the code?. (This is how far i have got): //Variables int speed = 10; int start = int(random(100,400)); BImage ship, meteorImage1, meteorImage2; void loop(){ meteor(); } //meteor code void meteor(){ int acc = int(random(1,9)); int num = int(random(1,2)); speed = speed+acc; if (speed < 0) { speed = height; } meteorImage1 = loadImage("meteor"+num+".gif"); image(meteorImage1,start,speed); println(num); //Why does it allways become 1 ?? }
|
|
|
|
fjen
|
Re: several falling objects
« Reply #1 on: Sep 9th, 2004, 10:43pm » |
|
you are mixing up typecasting to int with round() ... see below. int(1.999999f) // returns 1 round(1.999999f) // returns 2 so your "int num = int(random(1,2));" does return 2 sometimes, just very rarely ... try: int num = round(random(1,2));
|
« Last Edit: Sep 9th, 2004, 10:49pm by fjen » |
|
|
|
|
|