Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (757)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (843)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Simple Day/Night Cycle Libgdx  (Read 2560 times)
0 Members and 1 Guest are viewing this topic.
Offline christomax

Innocent Bystander

« Posted 2013-08-26 10:49:13 »

Hello, this is my first post on here and sadly it has to be a question.  I've been searching the site for an explanation on how this would be done but I have yet to find something that I could understand so I thought I would ask for a little assistance. I'm working on a side-scrolling game and I have been trying to find an effective way to implement a day/night cycle. I'm new at libgdx but I am using this project to work on it some more, so please try to go easy on my brain. If more information is needed I will be keeping an eye on this because I'm not totally sure what all I would need to post. Thanks anyone who could possibly help with this!
Offline Opiop
« Reply #1 - Posted 2013-08-26 10:56:09 »

What exactly is wrong? Just have a time variable that is constantly increasing and then (if you have it) change your lighting depending on the time of day.
Offline PaidGEEK

Senior Devvie

Medals: 5
Projects: 3

« Reply #2 - Posted 2013-08-26 10:56:57 »

I normally keep a float in level class for time [0, 1]. 0 would be night and 1 is day. Then I calculate the current value with a sine curve (There's probably different ways).
After that you can use this value to position the sun sprite and stuff like that. If you're using LibGDX you can use it with sprite batch as a tint color, which would make nights dark and days bright.

Improvisational programmer.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline grevius
« Reply #3 - Posted 2013-08-26 11:10:47 »

i think there is a simple way.
You can create a image, like 1x1px, 1 pixel darker and i pixel lighter, and apply this texture to a prite with linear filter. in this case you create a gray like sky.
After that you can color the sky by .setColor of the sprite an so you have a different sky in different time of a day.
If you want animate it you can simple use Tween manager for animation, and set the color of the sprite to animate, so you don't have to calculate the phase of the day, but only create a repeatyoyo loop animation that pass from day to night and viceversa.
I hope my explanation is pretty simple to understand  Grin
Pages: [1]
  ignore  |  Print  

EgonOlsen (38 views)
2018-06-10 19:43:48

EgonOlsen (20 views)
2018-06-10 19:43:44

EgonOlsen (40 views)
2018-06-10 19:43:20

DesertCoockie (187 views)
2018-05-13 18:23:11

nelsongames (122 views)
2018-04-24 18:15:36

nelsongames (121 views)
2018-04-24 18:14:32

ivj94 (861 views)
2018-03-24 14:47:39

ivj94 (122 views)
2018-03-24 14:46:31

ivj94 (758 views)
2018-03-24 14:43:53

Solater (139 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!