The pictures are not displaying

def drawGamePlayLevel1():
    global life, time, score, stageNum
    image(palace, 0, 0, width, height)

    if  (millis()-startTime)/1000 == 2:
        alive[0] = True
    if  (millis()-startTime)/1000 == 4:
        alive[1] = True
    if  (millis()-startTime)/1000 == 6:
        alive[2] = True
    if  (millis()-startTime)/1000 == 8:
        alive[3] = True
    if  (millis()-startTime)/1000 == 10:
        alive[4] = True
    if  (millis()-startTime)/1000 == 12:
        alive[5] = True
    if  (millis()-startTime)/1000 == 14:
        alive[2] = True
    if  (millis()-startTime)/1000 == 16:
        alive[3] = True
    if  (millis()-startTime)/1000 == 18:
        alive[4] = True
    if  (millis()-startTime)/1000 == 20:
        alive[1] = True
    for i in range(totalNum):
        if (alive[i] == True):
            y[i] = y[i] + 2

    for i in range (3, 6, 1):           
        aLeft = x[i]
        aRight = x[i] + w[i]
        aTop = y[i]
        aBottom = y[i] + h[i]
                
        bLeft = mouseX - princeW/2
        bRight = mouseX + princeW/2
        bTop = mouseY - princeH/2
        bBottom = mouseY + princeH/2
        
        if (alive[i] == True and aTop < bBottom and bTop < bBottom and aLeft < bRight and bLeft < aRight):
            life = life - 1 
            alive[i] = False
    
    for i in range (0, 3, 1):           
        aLeft = x[i]
        aRight = x[i] + w[i]
        aTop = y[i]
        aBottom = y[i] + h[i]
                
        bLeft = mouseX - princeW/2
        bRight = mouseX + princeW/2
        bTop = mouseY - princeH/2
        bBottom = mouseY + princeH/2
            
        if (alive[i] == True and aTop < bBottom and bTop < bBottom and aLeft < bRight and bLeft < aRight):
            score = score + 1
            alive[i] = False

Dear all, this is part of my code. I initial all as false at first, and set it to true when certain time is reached. But when time is reached, nothing is shown in the screen except the mouse… I want the images fall down from the top one by one every 2 seconds, and want it to be disappear when it collides with the mouse… Thank you so much!!! :sob:

won’t work

Try without /1000 and then check for > 1000

2 Likes

I think none of your conditions are ever true. You use exact timings (millis()-startTime)/1000 == 2 but how likely it is that timer evens with 2000 when that part of code is run. Draw() cycle runs by default 60 times a second, but it’s not guarantied. So you cannot know that 120th frame would be at 2000 millis. It could be 2001 or 1999 and your test misses it. Besides comparing a float to an integer is doomed to fail. By nature of floats result of division 2000/1000 is not 2.0, but can be something very close to it like 2.0000001.
So you should test (millis()-startTime)/1000 >= 1.95 and (millis()-startTime)/1000 <= 2.05. If it still doesn’t trigger your draw you need to widen the range a bit. You can probably narrow it a lot: (1.99 and 2.01) should work.

4 Likes