Be a Supporter!

Real-time Clock Tutorial

  • 9,684 Views
  • 75 Replies
New Topic Respond to this Topic
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Real-time Clock Tutorial Jun. 21st, 2005 @ 10:39 AM Reply

<-------------------------------------------------------------->
This tutorial is very simple, any beginner flash artist can do it.
<-------------------------------------------------------------->

<-->
STEP 1
<-->
Make a symbol, and inside it, make 3 movie clips. One for the second hand, one for the minute hand, and one for the hour hand. Give the second hand an instance name of "sHand", the minute hand an instance name of "mHand", and the hour hand an instance name of "hHand". Make sure that they are centered, and that the registration point of the hands is where you want them to rotate about.

<-->
STEP 2
<-->
Place the following code in your clock symbol.:

|-----|
CODE
|-----|

onClipEvent (enterFrame) {
var my_date:Date = new Date();
hours = my_date.getHours();
minutes = my_date.getMinutes();
seconds = my_date.getSeconds();
hHand._rotation = (1/(12/(hours+minutes/60)))*360;
mHand._rotation = (1/(60/minutes))*360;
sHand._rotation = (1/(60/seconds))*360;
}

<-->
STEP 3
<-->
Edit your graphics to whatever you want them to be. You can make as many clocks as you want.
Advanced AS'ers, you can even edit the script to make a 24 hour clock or whatever you want!

<-------------------------------------------------------------->
Example Time!
<-------------------------------------------------------------->
http://img192.echo.cx/my.php?image=clock1pz.swf

<-------------------------------------------------------------->

Post your best clocks!

<-------------------------------------------------------------->
This has been a Glaiel Gamer tutorial.

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 10:52 AM Reply

What about digital clocks?


BBS Signature
Flea-Productions3
Flea-Productions3
  • Member since: Apr. 13, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 10:59 AM Reply

Here is my horrendous creation!

N00B Clock

Enjoy it.

KJDunwoody
KJDunwoody
  • Member since: May. 9, 2004
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 10:59 AM Reply

Cool.
How did you come up with that?

I wish i could have.
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:00 AM Reply

Digital clocka are even easier, you just need 3 dynamic text boxes, 1 for "seconds", 1 for "minutes" and 1 for "hours"

or, here's a code for you.

onClipEvent (enterFrame) {
var my_date:Date = new Date();
hours = my_date.getHours()+1;
minutes = my_date.getMinutes()+1;
seconds = my_date.getSeconds()+1;
if(hours>12){
hours -= 12
}

disp = hours+":"+minutes+":"+seconds
}

*Remove the bold part for a 24 hour clock

Now, all you need is a dynamic text box in the clock symbol, and set the "variable" part to "disp".

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:01 AM Reply

At 6/21/05 10:59 AM, -KJDunwoody- wrote: Cool.
How did you come up with that?

I wish i could have.

My next game has unlockable "toys" and I decided to put a clock as one. So I did a tiny bit of work and came up with this.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:05 AM Reply

Here's a better code for a digital clock, mistake in the first one.
onClipEvent (enterFrame) {
var my_date:Date = new Date();
hours = my_date.getHours();
minutes = my_date.getMinutes();
seconds = my_date.getSeconds();
if (hours>12) {
hours -= 12;
}
if (seconds<10) {
seconds = "0"+seconds;
}
if (minutes<10) {
minutes = "0"+minutes;
}
if (hours<10) {
hours = "0"+hours;
}
disp = hours+":"+minutes+":"+seconds;
}

KJDunwoody
KJDunwoody
  • Member since: May. 9, 2004
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:14 AM Reply

At 6/21/05 11:01 AM, Glaiel_Gamer wrote: My next game has unlockable "toys" and I decided to put a clock as one. So I did a tiny bit of work and came up with this.

Cool.
Do you have hotmail?

I would like to talk to you.
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:20 AM Reply

I have AIM, KingGoboWoboFaun
glaielgamesmail@comcast.net

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:21 AM Reply

At 6/21/05 11:01 AM, Glaiel_Gamer wrote: My next game has unlockable "toys" and I decided to put a clock as one. So I did a tiny bit of work and came up with this.

Last time I saw that, it was looking good. Hows it coming along?


Sup, bitches :)

BBS Signature
KJDunwoody
KJDunwoody
  • Member since: May. 9, 2004
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:24 AM Reply

At 6/21/05 11:20 AM, Glaiel_Gamer wrote: I have AIM, KingGoboWoboFaun

AIM isn't Good enough BITCH!

Because I don't have it.
Glaiel-Clock
Glaiel-Clock
  • Member since: Jan. 8, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:26 AM Reply

OH CRAP I FORGOT TO MENTION SOMETHING!
IN your hand symbols MAKE SURE THAT THEY ARE POINTING AT THE 12!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!!!
(This is my rarely-used alt account)

DEADSiM2, I have 5/13 games and 8/20 toys completed.

Toast
Toast
  • Member since: Apr. 2, 2005
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:30 AM Reply

Isn't it forbidden to have an alt account?


BBS Signature
I-Jaf
I-Jaf
  • Member since: Jul. 2, 2003
  • Offline.
Forum Stats
Member
Level 09
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:36 AM Reply

You know there's a clock in the samples?

liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 11:38 AM Reply

At 6/21/05 11:30 AM, Dark_Toaster wrote: Isn't it forbidden to have an alt account?

No, just to use the alt account to get around bans.


Sup, bitches :)

BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 02:00 PM Reply

At 6/21/05 11:36 AM, JafitMan wrote: You know there's a clock in the samples?

I don't care.

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 21st, 2005 @ 10:55 PM Reply

That post needed to be posted, though. It was VERY important.

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Real-time Clock Tutorial Jun. 27th, 2005 @ 03:45 PM Reply

At 6/21/05 10:39 AM, Glaiel_Gamer wrote: <-------------------------------------------------------------->
This has been a Glaiel Gamer tutorial.

lol. This looks VERY similar to a dial clock AS snippet I created and posted a little while ago, even down to the Instance Names... nvm, it's all good =)


- - Flash - Music - Images - -

BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 02:18 PM Reply

really? Hmm... I never saw that topic.....

speddyfeddy1234
speddyfeddy1234
  • Member since: Feb. 23, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:31 PM Reply

riiiight, :p jp

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:35 PM Reply

At 6/28/05 02:18 PM, Glaiel_Gamer wrote: really? Hmm... I never saw that topic.....

Just checked, it's not quite the same. I made it for AngelClock quite a while ago, didn't realise there was one in the Flash sample files...

http://www.newgrounds.com/bbs/topic.php?id=284910


- - Flash - Music - Images - -

BBS Signature
Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:37 PM Reply

ok. I didn't realize there was one in there either. Oh well.

speddyfeddy1234
speddyfeddy1234
  • Member since: Feb. 23, 2005
  • Offline.
Forum Stats
Member
Level 03
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:38 PM Reply

Yay, now we all are friends again! Lets look for treasure!

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:42 PM Reply

At 6/28/05 03:38 PM, speddyfeddy1234 wrote: Yay, now we all are friends again! Lets look for treasure!

Inglor.onReadJackshit=func(content);

function func(content):Punch{
if(Content.Spamness>5){
content.Spamness--;
func(content);
return Punch;
}
}

this is what you get, 8 punches, if you know what this means, I'll take that back :P

Denvish
Denvish
  • Member since: Apr. 25, 2003
  • Offline.
Forum Stats
Member
Level 46
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:51 PM Reply

No, no, no, you got it all wrong...

Denvish.onReadJackshit=func(content);

function func(content):Ban{
if(content.Spamness>5){
content.Spamness--;
func(content);
return Ban;
}
}

lol@stealing code


- - Flash - Music - Images - -

BBS Signature
Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:57 PM Reply

nice stealing :)

but got it wrong , you just banned him alot of times (recursion tutorial coming soon)

Denvish.onReadJackshit=func(content.Spamness);

function func(content):Number{
Spamness=Spamness*(Spamness>12)+7*(Spamness>12);
if(Spamness>5){
return Spamness+func(Spamness-1);
}
return 0;
}

This actually bans him for a day for each Spamness >5 and maxs at 7 days

I love recursive stuff :)

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 03:58 PM Reply

Or

GG.onReadJackshit=func(content);

function func(content):nothing{
if(content.Spamness>5){
content.Spamness--;
func(content);
return nothing; // I have no mod powers
}
}

Glaiel-Gamer
Glaiel-Gamer
  • Member since: Dec. 28, 2004
  • Offline.
Forum Stats
Member
Level 28
Game Developer
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 04:01 PM Reply

At 6/28/05 03:57 PM, Inglor wrote: nice stealing :)

but got it wrong , you just banned him alot of times (recursion tutorial coming soon)

Denvish.onReadJackshit=func(content.Spamness);

function func(content):Number{
Spamness=Spamness*(Spamness>12)+7*(Spamness>12);
if(Spamness>5){
return Spamness+func(Spamness-1);
}
return 0;
}

This actually bans him for a day for each Spamness >5 and maxs at 7 days

I love recursive stuff :)

If you love recursion so much, try this

function hurt(username){
username.punch
if(modpower){
username.ban
}
hurt(username)
}
hurt("speddyfeddy1234")

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 04:02 PM Reply

oops, I made a baddy :P

Denvish.onReadJackshit=Ban(content);

function Ban(content):BanType{
return "You have been banned for" + func(content.Spamness) + "Days, Reason:"+content;
}
function func(Spamness):Number{
Spamness=Spamness*(Spamness>12)+7*(Spamness>12);
if(Spamness>5){
return Spamness+func(Spamness-1);
}
return 0;
}

Inglor
Inglor
  • Member since: Jan. 26, 2003
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to Real-time Clock Tutorial Jun. 28th, 2005 @ 04:04 PM Reply

GG didn't get the recursive function calling either, but oh well ;) like i said, tutorial coming soon ;)