簡體   English   中英

如何根據一天中的實時時間旋轉360°晝/夜周期圖像?

[英]How to rotate 360° day/night cycle image based on the real time of the day?

日/夜圈示例: https //i.ibb.co/fFskJ28/exmp.png

我希望日/夜圓圈圖像(上面鏈接中的示例)根據實時(+1 UTC,無冬夏時間調整)旋轉。 您在圖片中看到的時間已經基於+1 UTC時間。 我已經在自己的游戲開發者項目中實現了這一目標,但現在我也希望在我的網站上顯示此日/夜圈圖像,以便訪問者也可以在那里看到日/夜循環。

我已經有用GML編寫的工作代碼,但是現在我想用PHP / Javascript編寫它,而我對Javascript的了解也不多,但是如果我想讓晝/夜周期圖像實時旋轉,那是必須使用的代碼。時間。

所以這是我用GML編寫的工作代碼:

//written in GML
// unix_timestamp([datetime])
//
//  Returns a Unix timestamp for the current time
//  or optionally given GameMaker datetime value.
{
    var timezone = date_get_timezone();

    date_set_timezone(timezone_utc);

    if (argument_count > 0) {
        var datetime = argument[0];
    } else {
        var datetime = date_current_datetime();
    }

    var timestamp = round(date_second_span(25569, datetime));

    date_set_timezone(timezone);

    return timestamp;
}

以下部分有點混亂,但是可以滿足我的所有需求,使變量“小時”和“分鍾”等於我所在國家/地區的實時小時/分鍾(+1 UTC)

//written in GML

rtime = unix_timestamp();

//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
rtime2 = (rtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
 equalise to the UTC+1 time


//remove all remaining days
{
while (rtime2 >= 86400)
   {
   rtime2 -= 86400;
   }
}

dtime = unix_timestamp();

//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
dtime2 = (dtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
 equalise to the UTC+1 time


//number of days from 1 jan 2019 00:00
day_unf = (dtime2 / 86400);
day = (floor(day_unf) + 1);

//count all remaining hours
hour_unf = (rtime2 / 3600);

hour = (floor(hour_unf))

qtime = unix_timestamp();

//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
qtime2 = (qtime - 1546300800+3600);//the +3600 is meant to add 1 hour to
 equalise to the UTC+1 time

//remove all remaining days
{
while (qtime2 >= 86400)
   {
   qtime2 -= 86400;
   }
}

removar = (hour * 60)

//count all remaining minutes
minute_unf = (qtime2 / 60);
minute_unf2 = (minute_unf - removar);

minute = (floor(minute_unf2))


xtime = unix_timestamp();

//removing all seconds from 1 jan 1970 00:00 - 1 jan 2019 00:00 (UTC+1 Amsterdam)
xtime2 = (xtime - 1546300800+3600);//the +3600 is meant to add 1 hour to 
equalise to the UTC+1 time


//remove all remaining days
{
while (xtime2 >= 86400)
   {
   xtime2 -= 86400;
   }
}

rem = (minute * 60);

rem2_unf = (hour * 3600);

xtime3 = (xtime2 - rem);
second = (xtime3 - rem2_unf);

if hour == 24{
    hour = 0;
}
//written in GML
pre1 = 15 * hour;
pre2 = 0.25 * minute;
pre3 = pre1 + pre2;
cycle_angle = pre3;
//cycle_angle is always a number between 0-360 and is used below to draw the day/night circle image in the right rotation degree.

draw_sprite_ext(spr_day_night_cycle,0,960,80,image_xscale*1.5,image_yscale*1.5,cycle_angle,c_white,image_alpha);

由於圖像是360度的圓圈,代表24小時一整天的時間,因此每經過的小時等於15°旋轉,而每分鍾等於0.25°旋轉。 例如,當時間為18:30時,它將旋轉277,5°(15 * 18 + 30 * 0.25),以表示將是白天,但日落已接近。

所以我的問題是:

問題1:如何根據我所在國家/地區的實時小時/分鍾使PHP / Javascript中的變量“小時”和“分鍾”(+ 1UTC,無需調整冬夏時間)

問題2:如果我在問題1中成功,如何像在GML中一樣,根據“小時”和“分鍾”變量在網站上旋轉白天/夜晚的圓圈圖像? (請參見下面的GML示例)

//written in GML
pre1 = 15 * hour;
pre2 = 0.25 * minute;
pre3 = pre1 + pre2;
cycle_angle = pre3;
//cycle_angle is always a number between 0-360 and is used below to draw the day/night circle image in the right rotation degree.

draw_sprite_ext(spr_day_night_cycle,0,960,80,image_xscale*1.5,image_yscale*1.5,cycle_angle,c_white,image_alpha);

在PHP中:

$date = new \DateTime();
$date->format('Y-m-d H:i:s'); //returns a string

DateTime對象中還有許多其他功能。 在這里閱讀

在JS中:

var today = new Date();
var time = today.getHours() + ":" + today.getMinutes() + ":" + today.getSeconds(); 

然后,您可以使用這些值,並使用CSS使用transform: rotate(360deg);將圖像從0-360度transform: rotate(360deg);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM