Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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 581 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 opiop65

JGO Kernel


Medals: 154
Projects: 7
Exp: 3 years


JumpButton Studios


« 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 Member


Medals: 5
Projects: 3


twitter.com/PaidGEEK


« 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  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

UprightPath (20 views)
2014-09-20 20:14:06

BurntPizza (26 views)
2014-09-19 03:14:18

Dwinin (40 views)
2014-09-12 09:08:26

Norakomi (70 views)
2014-09-10 13:57:51

TehJavaDev (95 views)
2014-09-10 06:39:09

Tekkerue (49 views)
2014-09-09 02:24:56

mitcheeb (70 views)
2014-09-08 06:06:29

BurntPizza (52 views)
2014-09-07 01:13:42

Longarmx (39 views)
2014-09-07 01:12:14

Longarmx (45 views)
2014-09-07 01:11:22
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org 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‑gaming.org
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!