How to make a clock with sprites?

Hello people!

I wonder How I can create clock with a sprite ...I know how work the sprites but...How can make the ''needle of the clock'' work perfectly with the time?
Well, a normal spritesheet for 1 char has 12 slots so you can have each slot correspond to each hour... now if you need to be able to move in between too, then you can maybe use another sheet or so...


then once you have the sprites ready, you can probably even just use events...


Where are you planning to show the clock anyways? and how is the time implemented?


I think this would probably be better off using scripts, bitmaps maybe
You can create a rectangle and rotate it depending on the current time.


Here's a clock example


http://himeworks.wordpress.com/2013/03/28/clock-graphic/
Hum well Is a script part in my new script I working on  ( Para World map  (is a special scene script who permit to choose where you want to go on a continent is all built with sprites )

who I have clock who always show the time and exemple one min equal one hour.

I know I can doing it in technical way but I  have a particuliar affection for sprite methods
If you have the clock images all on a single spritesheet, you may need to use Galv's Move Route Extras script, as the Change Graphic command in a move route does not allow you to pick a certain cell in the 12.
Ho because in scripts Is not possible to have 12 cell?
If you're gonna use scripts, then number of frames/cells doesn't really matter
It is possible, but the commands in the move route do not allow you to select individual cells - only the 3x4 group.

You COULD give your event 12 pages, each one with a different version of the clock, and set the condition on each page to Variable X = 1, 2, 3, 4 ... 11 (the first page would have no condition). Then have a parallel process event on that map that does this:

Code:
Conditional Branch: Variable X == 11  Control Variables [X] = 0Else  Control Variables [X] += 1Branch EndWait 60 Frames (or however long you want it to be between changing images - 60 frames is 1 second)
@Shaz: Ho cool I never know this thank you ! but I wanted to used it in a script not in event xD... Is because I forgot to mentionned is my mistake...

I have three picture

Layout : the background of the clock

The first needle : a image

and finally the second needle : a image of a clock needle

What i really wanted to know is How I can take my ''clock needles'' and make it rotated in clock way...or is impossible?
I'm sorry. I did note that you put it in script requests. I didn't see that you specifically wanted it as a script.


Do a search in the scripts forum (or the master list) for graphic/sprite scripts. I know somebody made a script that would let you rotate sprites.
If you load a clock sprite in, then load a minute hand and an hour hand in as 3 different Bitmap/Sprite combos, like so:

Spoiler
class Spriteset_Clock def initialize @back_sprite = Sprite.new @min_hand = Sprite.new @hour_hand = Sprite.new @back_sprite.bitmap = Cache.picture("Clock.png") @hour_hand.bitmap = Cache.picture("ClockHourHand.png") @min_hand.bitmap = Cache.picture("ClockMinuteHand.png")
Then you have them on screen. All you have to figure out now is how to rotate them. You can do this with their Sprite#angle property. The #angle property is an integer from 0 to 360, or a full circle in integer-based degrees. Thus, we need a way to calculate our angle from the time of day. I think it'd be something like:

Spoiler
calc_xy anchor_to_center end def calc_xy @sprite_hour.x = @sprite_back.x + (@sprite_back.width/2) @sprite_hour.y = @sprite_back.y + (@sprite_back.height/2) @sprite_min.x = @sprite_hour.x @sprite_min.y = @sprite_hour.y end def anchor_to_center @sprite_hour.oy = @sprite_hour.height/2 @sprite_min.oy = @sprite_min.height/2 end
After that you gotta figure out the updating of the clock. Because you want to supply your own time standard and not the default one, and to make this system much more dynamic, we will allow the user to supply hour and minutes to the update function.

We also have to calculate the angle of the hands:

Spoiler
def update(hour, min) @sprite_hour.angle = hour_angle(hour, min).floor @sprite_min.angle = minute_angle(hour, min).floor end def hour_angle(hour, min) 180 - ((0.5 * (60.0 * hour + min)) + 90) end def minute_angle(hour, min) 180 - ((6 * min) + 90) end
The hour_angle method is simply calculating an angle from the hour and min variables, then adding 90 (because my hands are at a 90 degree angle already, aka pointing right). Then to get it to rotate clockwise instead of counter clockwise, you must subtract your calculated angle from 180. Same with minute_angle.

Finally, we define the rest of our class, then initialize it:

Spoiler
def dispose @sprite_back.dispose @sprite_hour.dispose @sprite_min.dispose endendtest = Spriteset_Clock.newhour = 12min = 1count = 60loop do if (count -= 1) <= 0 count = 60 min += 1 if min >= 60 min = 1 hour += 1 if hour == 13 hour = 1 end end end Graphics.update Input.update test.update(hour, min) break if Input.trigger?🙂C)endtest.dispose
The final code is in this rar file. Just unzip it, and copy the two folders into a new project. (Images are in there, so you can see how it works.)

Original thread: https://forums.rpgmakerweb.com/threads/how-to-make-a-clock-with-sprites.20673/