Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Day/Night and Onscreen Clock! Plus Clear Lights

Star

Sponsor

Idea1.png

This is me taking a screenshot of my game and putting it in a paint program and making my own lights using another layer

Idea2.png

This is me having lights appear at night in my game. As you can see the lights go over top of the dark layer and don't actually clear it up. I wanna able to open up the dark layer.

Any ideas on how I could go about working around this?
 
Gubid, nice. I like the encapsulation. At first glance I wondered why create_lights couldn't be done in the initialize method instead of refresh. But then it occured to me that a light's state might change during a map scene (torch burns out, player turns light on, etc...)

funny, my wife does that too. "Are you coming to bed?". Except last night she had a couple 'beverages' & sat in the hot tub, she was out like a light!
 

Star

Sponsor

Wife? Why don't I have a wife yet. Strawberry, why aren't you my wife?!

Wow. This is amazing. Its like its all coming together now. I do have some silly questions though since I wish to improve my skills.

Did you overwrite game_event or is that a whole new class somehow?

Where did alpha 60 go? O_O

What does it mean when you divide the game_map_screen.x and y by 4 to get the ox and oy?

I was thinking we should have a turn off switch for insides. But then I thought. Why would a house not get darker at night. Although entering caves and such would have a permenant alpha. It would be easy to setup a switch for that but I'm a work on my phone.

I was also wondering if there was a way to gradually increase or decrease alpha by alpha += 1 or alpha -= 1 unless alpha == current_alpha. It would have to be done in update to keep it going.

I think once we get this thing finalized I'm going to add a random weather system as well that changes weather depending on the region.

Keep it up guys. This is hotter than sprite porn. :fap:
 
Alpha 60? i dont even remember seeing it. You can probably just add it back though.


Ok, I got this partialy working. There needs to be smarter logic when an overlap occurs to determine what can be blt'd and what needs to be sub'd.. but this points you in the right direction.

http://www.mediafire.com/?q69vji75ead4bar

Also, I do realize that the pictures are not exact inverses of each other.. but for whatever reason I cannot think of how to make them do that.
 
Star":qkdr53tl said:
Wife? Why don't I have a wife yet. Strawberry, why aren't you my wife?!

Did you ask her?

Wow. This is amazing. Its like its all coming together now. I do have some silly questions though since I wish to improve my skills.

Did you overwrite game_event or is that a whole new class somehow?

His Gubi-ness just added the @is_light parameter to identify the event as a "Light" event

Where did alpha 60 go? O_O

It was never there. I wondered that too, but it didn't bother me enough to ask.

What does it mean when you divide the game_map_screen.x and y by 4 to get the ox and oy?

This has always been a bit of a mystery to me too. real_x & real_y, as well as distance & display_x/y are all represented as 128 'units' per tile,
(4 units per pixel). I suppose it might have something to do with smoothing out movement?

I was thinking we should have a turn off switch for insides. But then I thought. Why would a house not get darker at night. Although entering caves and such would have a permenant alpha. It would be easy to setup a switch for that but I'm a work on my phone.

Interiors like a house are different in: in the day, they are slightly darker, with light sources as the windows. At night, a bit more dark, with candles/lamps as the light sources. We could have 2 page events as the light sources. The base light difference may not matter.

I was also wondering if there was a way to gradually increase or decrease alpha by alpha += 1 or alpha -= 1 unless alpha == current_alpha. It would have to be done in update to keep it going.

Yep, we should definitely include this. seeing the tint jump by 30 alpha is ugly.

I think once we get this thing finalized I'm going to add a random weather system as well that changes weather depending on the region.

Keep it up guys. This is hotter than sprite porn. :fap:

It's close! :scruff:


Gubid, add the aliased dispose method for the @nighttime sprite to Spriteset_Map. (if you haven't)

TTFN
 
Gubid":29cp1p17 said:
Alpha 60? i dont even remember seeing it. You can probably just add it back though.


Ok, I got this partialy working. There needs to be smarter logic when an overlap occurs to determine what can be blt'd and what needs to be sub'd.. but this points you in the right direction.

http://www.mediafire.com/?q69vji75ead4bar

Also, I do realize that the pictures are not exact inverses of each other.. but for whatever reason I cannot think of how to make them do that.

I had a hard time with that too. Kinda why I explored the 'subtract' strategy in the first place... :)


[edit]


Got to thinking about the fading instead of jumping 30 alpha every hour.
If you kept time by minutes instead of hours, and adjusted the dawn & dusk times to: dawn(4:00 - 7:30), dusk (4:30p - 8:00p)
it works out that the alpha changes by 1 every minute between those times.

alpha = [[[@minute - 720].abs - 270, 0].max , 210].min

if dawn(2:30 - 6:00) & dusk(6:00p - 8:30p) sounds better

alpha = [[[@minute - 720].abs - 360, 0].max , 210].min
 

Star

Sponsor

Brewmeister":1xqhx68k said:
Did you ask her?
Yeah, we've been engaged for about 2 months now. :D

When I change maps, things seem to get darker, like it's reapplying all the things again

http://www.mediafire.com/?j5e54k87n0nud4f

Also the lights seem to follow the player when maps change. I'm trying to figure out how to dispose and refresh everything when the maps change. Thought I'd bring it up to you guys so we can work it out faster.

Also I was planning on having 24 minutes for a total day. But we can have a variable at the beginning that asks the script user how many real time minutes in they want per day. Then we can do your idea of updating the alpha throughout.


Just one thing about this idea though, I think it's probably better that the Game maker is able to change the hours according to what they want. Not what's going on in a script. Changing the hour of the day should be done in events so it's easier to make things on time and not off schedule. So if I have 60 seconds to gradually change the alpha to the max alpha of that current hour would be awesome.

I'm trying to implement and inside_variable but with not selfclearing properly I can't see if it's gonna work right.

Also this is offtopic but.
file.php
+
Balls-of-Steel-1-icon.png
=
file.php
 
Cool, when's the "big day"?

If you started with Gubid's last version, it's missing the dispose method.

Code:
  alias dns_dispose dispose in Spriteset_Map

  def dispose

    dns_dispose

    @nighttime.dispose

  end

 

If an hour = a minute, then a minute = a second. perfect! the alpha changes by 1 every second.
I'm going to try this out, and I'll post a compressed version back...

http://www.hbgames.org/user_files/Star_ ... g_Test.exe

It's really laggy because I'm updating every frame just to make the test quicker.
No matter how often the gamemaker updates a 'minute', it will adjust the alpha by 1 each game minute for a nice gradual change.
If the gamemaker needs a jump in time, they can just force set the game variable to the desired minute (1440 minute per day)
I set the update on a parallel process, so just test play & watch. A whole day should go by in about 72 seconds.

I also split up the classes since the one script was getting rather large.
 

Star

Sponsor

We haven't decided when the big day is, but it's probably gonna be sometime this year.

I can't see it. Remember your computer hammers through this stuff. I think there should be another way to make the update not refresh so fast. Like maybe add 1 to the minute variable until it reaches 20 or so and then refresh. I was hoping to make a whole day go by in 24 real time minutes. If RMXP has a frame rate of about 20 per second then if we wait to refresh till after it accumulates 20 a second should go by.

If I can figure out what each of this means

alpha = [[[@minute - 720].abs - 270, 0].max , 210].min
where does minute = $game_variables[MINUTE_VAR] this increase?

what's abs? I think I might be able to help out if I can understand this
 
I only refreshed it so fast because I didn't want to wait 4 minutes for it to start to change, and another 3 1/2 minutes to fade to day.
You would put a Wait: 20 frames in your event to make it only update every second.

That is the formula for a line that goes from (0,360) to (12, -360), and it's mirror (24,360) to (12, -360), using the min & max to chop it off at 210 & 0.
(saw tooth wave)
I looked up the natural progression of light through a normal day, and it's so close to a linear transition at dusk & dawn, I figured linear would look very natural.
the curve is inverted, because we're subtracting the alpha. (0 alpha = noon daylight).

Green curve is the formula: y = (x - 720).abs - 270
Red curve is what gets returned because of the .min & .max being applied.

light_dist_normal.png


.abs is a object method to return the absolute value. (mirrors the curve by returning a positive y value)
you increase the $game_variables[MINUTE_VAR] yourself from an event. I did it in a parallel event on the map for testing.
I could have written it: alpha = [[[$game_variables[MINUTE_VAR] - 720].abs - 270, 0].max , 210].min
 

Star

Sponsor

I kinda get it, but then again graphs wasn't my specialty in math. I narrowed down what was the lagging issue in your code to this

Code:
def create_lights

    for event in $game_map.events.values

      for i in 0...event.list.size

        if event.list[i].code == 108 #comment

          if event.erased and event.list[i].parameters[0].include?("light")

            @lights.delete(event)

            next

          elsif event.list[i].parameters[0].include?("light")

            @lights[event] = Light.new(event) unless @lights.keys.include?(event)

            event.is_light = true

            next

          end

        end

      end

      #in the event page is changed and it is no longer a light.. remove it.

      if @lights[event] != nil and event.is_light == false

        @lights.delete(event)

      end

    end

  end

not sure what in it is doing it.
Argh, this thing is giving me a total headache. I was using the in-game timer to count down to 60 to change the hour. So I was thinking that maybe if I used alpha = [current_hour lowest_or_highest_darkness] + ($game_system.timer/2) I could get it to gradually reduce by 1 until it got to the 30 mark for each hour. But I can't get it to update right, on top of that it keeps saying $game_system.timer as a nil value and i have no idea why, since it initializes at 0 in Game_System.


Okay. I did something bad. Cause I couldn't figure out how to pull @total_sec from Sprite_Timer and I ended up turning total_sec into a Global Variable. I'm not sure why I couldn't figure it out but I'm sure you guys can.

It's smoother now and it runs by a timer which is easily disappear able by setting visible to false, still working in the background etc.

But it keeps skipping just a tiny bit so that it being on my computer which is still pretty fast but not brew fast will notice it on a much slower computer greatly. It's only refreshing every second but it's something not right about it. Also I tried your version of create_lights and fill_night brew and it was actually more laggy than this one so this one's over my head now.

http://www.mediafire.com/?yil2cmc7f2vsbr7
 
Yeh, I've been trying to think of a way to make it more efficient too.

:facepalm: What if we used the sprites opacity to control the fading. (in an 'update' method)
Then we would only need to call refresh when a light changes. (gets turned off/on)
 
That is actually what I tried to apply. Perhaps creating a separate viewport and setting up separate lights (sprites) using that and adjust their blend mode? I mean, that is what the blend mode is for right? Isnt there a subtract method? I have never used it so I dont know. In which case, then all you need to do is update the viewport and update the sprites and WALA! you have active light system.

EDIT:
Hmm. ok, so looking into it. The blend mode stuff is only for blending a color into the picture.. and it only affects the bitmap contained there in and not the viewport. Hence it will not work for what we need. The only method to be faster is to use a BLT method and do the detection stuff on rectangle overlap, and dice that into pieces to apply what you can as fast as you can, and resort to the hard method for the remaining pieces that it cannot easily determine. Its that, or call on the Win32api and work some magic with a dll call.
 

Star

Sponsor

http://www.mediafire.com/download.php?7c95us2oboa38h9
This is a phenomenal update!

I managed to avoid drowning.

Just kidding. But I managed to implement an internal clock and add in an on screen clock as well as a cute sun and moon sprite on it. You now don't have to handle when the hour changes it does everything automatically on every map.

You can also stop the clock and restart the clock at the same time it was stopped at. You also can set what hour you want to change it too and everything will change to that time. You can switch between AM and PM and military time as well.

Now I feel worthy enough to have my name next to creators: Brewmeister Gubid and Star :D
 
@levanan, sorry for the slow reply. Not ignoring you, and I do intend to look at your script. I'll give you some feedback in that thread, and if we see anything we like, we'll add you to the credits here. In the meantime, feel free to evaluate what we have so far & make suggestions.
I think I speak for Gubid & Star as well as myself when I say the doing these Joint Development projects are actually fun, so it's more a learning experience than it is a 'hurry up & get this done' kinda thing.

@Star, I'm getting distracted by some server things that need to get done, so I'll take a look at the latest as soon as I can.

Be Well
 
I was talking this over with another programmer and without direct access to the GPU then we really have 2 choices.

1. DLL Call Out and setup a radial paint brush that paints opaque onto the bitmap canvas that we provide it, and have it return it.
2. Figure out how to slice and dice the bitmap using overlaying rect's and blt what we can, then sub the rest. (what I was looking at doing)

I dunno how else to do it without access to the gpu. That is how I am used to doing these things, and rmxp/vx dont really give us that option. Initializing gpu space for this seems silly.
 

Star

Sponsor

I know this probably already went over my head. But gpu is graphics processing unit. I had to look it up. What's going on with the script? Is there things that need improving? Besides adding more light graphics for bigger and smaller lights. But that's easily done.

@levanan wow. I had no idea a script like this was already out. Too bad we already made this one from scratch but it was lots of fun and does eveything I ever wanted.

Although like brew said. If we see anything we like we'll add you to the credits if we use it. I personally would want to learn from it though.
 
Interesting thread really... had to wait until Raven could check it out (as I don't feel like installing the XP RTP on my PC :p ), but now that I looked at it... pretty impressive. You guys should release this as a bundle with instructions in the script section - I'd like to see it in a grabable package, and a maintained thread, rather than a loose request thread like this one where it'll vanish sooner than anyone wants - unless you don't want to release it. :p
I seriously think this is one of the top "realism" scripts released for the RM series so far... it actually focusses on making the game look great instead of just different, and does a damn good job on it.

Personally, what I'd add is an easy way to access the current time. I'm saying that because I have no idea how you guys set it up so far (as I couldn't look at the script without an editor, eh?), but I guess it'd probably be best kept at $game_system.current_time or something like that. A format that stores both hours and minutes would be the most complementary for working with conditionals, so if minutes is as detailed as you want to go, you could work with 0 to 1440 (aka minutes in a day) for just this value. This is something I've missed in EVERY other script similar to this, including scripts that claimed to have "easy timer access"...

That being said: Good work, keep it up... and I like to see the community working together like this, makes me feel all warm and fuzzy inside :p
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top