This site requires JavaScript, please enable it in your browser!
Greenfoot back
TotalBOSS01
TotalBOSS01 wrote ...

2014/6/25

cant get picture to change

TotalBOSS01 TotalBOSS01

2014/6/25

#
So im trying to get a picture to constantly change heres my code
  
  long curTime  = System.currentTimeMillis();  
    if (curTime <= 1000) 
    {  
    setImage(image1);
    }
    if(curTime >= 1000){
       setImage(image2);
    }
    if (curTime >= 2000){
      curTime = 0; 
    }
why doesnt this work
danpost danpost

2014/6/25

#
The method 'currentTimeMillis' is going to return a very large value (it would have returned the range of value you indicate on the first few seconds of the first day of 1970. It would be easier to count act cycles instead of using the system clock for what you are trying to do.
TotalBOSS01 TotalBOSS01

2014/6/25

#
danpost wrote...
The method 'currentTimeMillis' is going to return a very large value (it would have returned the range of value you indicate on the first few seconds of the first day of 1970. It would be easier to count act cycles instead of using the system clock for what you are trying to do.
how do u figure out how many seconds in an act cycle??
danpost danpost

2014/6/25

#
A scenario running at normal speeds (where the speed slider is set to somewhere around the middle of the bar) will run somewhere in the range of 50 to 60 cycles per second. You can program it using 60 and adjust from there (higher to slow the rate of change and lower to speed up the rate of change).
NikZ NikZ

2014/6/25

#
danpost wrote...
It would be easier to count act cycles instead of using the system clock for what you are trying to do.
It would be harder to compute milliseconds, as you would have to save the milliseconds at the start, then compare it to the present milliseconds (later). You would need at least two variables.
NikZ NikZ

2014/6/25

#
Your code is perfect for timing act cycles. You just need to add 1 (or more) to curTime every act, instead of getting currentTimeMillis()
You need to login to post a reply.