Game Development Community

ScrollTo( ) -- combination dial scrollers

by Tim Scheiman · in Torque Game Builder · 07/03/2010 (2:05 pm) · 2 replies

Hey all.

Is there currently any way to scroll at a given speed to a given scrollPosition and then stop?

If you've got a 0-9 vertical numbers strip and you're trying to make it look like a combination lock spinner... it doesn't seem like that is immediately possible without source changes or hacky schedule-based callbacks.

Any ideas?

-Tim

#1
07/03/2010 (8:17 pm)
If you create a graphics that has your 0-9 in a vertical strip, you should be able to use the source rectangle to change the visible portion. Of course, this would use a hacky schedule-based callback.

If you're willing to use additional scene windows (as children of the main scene window), you have a less hacky method available. You still have a static sprite with 0-9 in a vertical strip. You then place it in a scene window that is the width you want the spinner to be with the '0' showing. You can then use moveTo to create the effect of spinning to a number.

Also, depending upon what effect you are going for, you could make a circular image with the 0-9 on a ring. Then you can use rotateTo to create a spinning-dial effect.

Really, in the last two cases, you don't need separate scene windows if you have carefully layered sprites to cover the "magic".
#2
07/03/2010 (10:04 pm)
Yeah, I was trying to avoid the extra scene window, and the ring doesn't quite convey downward-scrolling spinners quite as I'd need. And carefully layered sprites aren't really an option given that this entire combination puzzle is within a frame on top of another scene for a casual game (a zoom-in frame thing)...

What I've got so far (after posting this question) is a solution that sets the scrollY speed to some value, then schedules a callback to check every so often until the distance from the destination is <= some other value. It then sets the scrollpositionY and sets the speedY to zero.

It works like a champ, but it's ugly using script in such a way (especially scheduling)... Odd stuff can likely result (if you've got a very low framerate or you pause the game or go to menu, etc.)

It's dangerous to use scheduling this way... lazy coding practice.

I'm sure if I looked at the moveto source I could adapt a scrollTo function that was fairly reasonable...