2014년 12월 13일 토요일

Random Item Sprite

I decided to try this one more time.
I have my program working except for one thing.  I need the sprite to change the image each time it is "called".  However, if I put the "random item" block in the "call" block the images rapidly cycle.  I DON'T want that to happen.  So I've tried putting the "random item" block in the global list.  But this isn't changing the image at all. ARGH! 

I hope someone can help!  Again, I need the sprite image to change each time it's "called", not any other time.  




And one more time... You're not CHANGING the image anyplace!  The ONLY time you change the image is when you initialize it.  Other than that, you're just comparing it, but never changing the image...  It's fine to do the random thing in the initialization and set it in the Screen1.Initialize, but you'll have to change the picture in the procedure each time it's called.



? I totally redid the program.  These are not the same blocks as before.

When I change the image in the "call" procedure,  block it cycles quickly,  which is not what I want.  I want it to pick a different image each time it's called, not every 2 seconds. So I put the random block in the global image last where it's doing nothing at the moment. If I put it in the "call" procedure block it quickly cycles. How do I stop that?



What did you set the Clock.Interval to?   The Clock fires as often as the developer wants.  The default is one second.   How often do you want the clock to fire?

If you read the documentation (  http://ai2.appinventor.mit.edu/reference/components/sensors.html#Clock ) or the AI2 free online eBook   http://appinventor.mit.edu/explore/ai2/tutorials.html   ... the links are at the bottom of the Web page.; you would know that.



If it's triggering too fast, and you're triggering it from the Timer (clock), your interval is probably way too small.  1000 is 1 second.  You're calling that procedure from the timer, so every time it fires, you get the proc.  So, it's you that's forcing it to change every time.

Also, FYI, the global initialization only happens once.  It's an initialize block... not a set block.  The global gets initialized when the screen opens.  After that, YOU have to set that variable.  Make a proc to set that randome thing, and call it whenever you need it.  The initialize block should only be used once.



Yes! It's the clock!!


댓글 없음:

댓글 쓰기