lua - swapping assets for night mode

  • #1, by F_KalWednesday, 05. April 2017, 21:11 3 years ago
    I'm trying to create a "lights-off" state for a room via script.
    I approached this by adding two single-frame animations for each affected scene object: One animation called LightOff and another one called LightOn.

    I've changed the duration of the LightOn/LightOff animations (2000ms) and chose infinite looping.

    Then via script I do the following:
    local anim = game.GameCurrentScene.SceneObjects["Object1"].ObjectAnimations["LightOff"]
    startAnimation(anim, true)
    but it doesn't work. There are also no errors in the player log.
    If inside the VS editor I set the default animation for Object1 into LightOff, it also doesn't swap the asset...

    Anybody having some idea why this is happening?

    Forum Fan

    107 Posts


  • #2, by afrlmeWednesday, 05. April 2017, 21:47 3 years ago
    Try. game.CurrentScene instead of game.GameCurrentScene.

    Instead of using animations you could duplicate the scene object & use a condition linked to them to detemine which should be shown. Better yet duplicate the scene & just replace the images - less hassle.

    Imperator

    6846 Posts

  • #3, by F_KalWednesday, 05. April 2017, 22:22 3 years ago
    thanks @AFRLme! I tried game.CurrentScene, but it had the same effect - then I tried using StopAnimation before starting the new one and magic! It now works!
    Not sure why StopAnimation is needed (I mean, can an object have multiple animations playing one on top of the other?)
    but since it works I'm happy :-)

    I had already tried duplicating the scene objects and controlling their visibility and that worked fine!

    Between duplicating the objects that you suggest and creating object animations that I proposed - would you say that one is more resource-efficient than the other?

    thank you so much!
    -Fotis

    PS. as for duplicating the whole scene, that would be tempting but then I'd have to replicate character positions, index of every animation in the scene, dialogs - not to mention mirror every correction that I make... so maybe it's not so lazy as it seems...?

    Forum Fan

    107 Posts

  • #4, by afrlmeWednesday, 05. April 2017, 22:33 3 years ago
    I meant create & finish day or night scene then duplicate it with the duplicate button on the scene list toolbar. It should automatically link to correct animation, images, conditions, values inside of the duplicated scene.

    As for stop animation. I guess it makes sense if you already have an animation already playing that is linked to the scene object. You are only supposed to play one animation per scene object at a time.

    Imperator

    6846 Posts

  • #5, by F_KalWednesday, 05. April 2017, 22:58 3 years ago
    ah, yes! I was referring to complications with duplicating the runtime state of the scene.
    My bad for not mentioning that the lights turn off with a switch inside the very room, which means that the animations playing while the switch happens and the positions of the characters (NPC/user) inside the scene would have to be "migrated" to the alternative scene so that the transition is smooth.
    But it certainly sounds a great trick for scenes that you enter after they have been set to dark (or illuminated).

    regarding stop animation, I can see your point. I assumed that startAnimation would auto-stop the previous animation (since you verified that there cannot be any concurrent animations running) but I'm sure there is some reason behind that!

    Thanks again!

    Forum Fan

    107 Posts

  • #6, by afrlmeWednesday, 05. April 2017, 23:40 3 years ago
    It would be easy to instantly switch scene & teleport npc & character in the scene to the new scene with same positioning with a bit of Lua script. I know you aren't planning on doing that, but just saying that it's possible.

    Imperator

    6846 Posts

  • #7, by F_KalThursday, 06. April 2017, 00:14 3 years ago
    you are certainly right @AFRLme and all your input is very very welcome!
    It's my lack of footing in lua that prevents me from attempting something like this at this point, but it definitely has some clear advantages and I can see myself revisiting it at some point when I am more confident and giving it a go!

    For now I've already completed the implementation the dummy way (using animation frames) and it works nicely so I'll call it a day (and go watch some episodes of the Expanse)

    As a warning: I suppose that (in theory) my implementation could cause issues with the visuals refresh speed: some objects becoming dark before the rest since they are switched in a serial manner, but I haven't seen anything thus far - and as they say "out of sight, is out of mind" :-P

    Thanks again!

    Forum Fan

    107 Posts

  • #8, by LebosteinThursday, 06. April 2017, 08:08 3 years ago
    Is it possible to work with color filters to darken a room?

    Key Killer

    601 Posts

  • #9, by afrlmeThursday, 06. April 2017, 12:02 3 years ago
    Is it possible to work with color filters to darken a room?
    Maybe with the openGL shader to tint the screen a specific hue? Or you could use openGL lighting... Or overlay some semi-transparent dark images over the scene - also a possibility.

    Imperator

    6846 Posts

  • #10, by F_KalThursday, 06. April 2017, 16:10 3 years ago
    Interesting question!

    my first implementation was with the scene brightness down to 10% - it was dark alright, but that was lacking the dramatic effect.

    My current approach is done with layers that I add on top of my "illuminated" artwork. I suppose that if somehow one could use shaders or some other trick to blend scene objects respecting special blending modes (eg. multiply, overlay, screen, color burn etc), one could stack 2-3 new layers and recreate the dark scene inside VS instead of PS. Definitely would save us from reexporting all animation frames and objects. That would also allow for a transition or fluctuation effect which would be awfully cool!

    IMO shifting the hue and brightness would be a first step, but adding new shadows and highlights that are prevelent while the main light source is off, would take it to the next step!

    Forum Fan

    107 Posts

  • #11, by afrlmeThursday, 06. April 2017, 16:24 3 years ago
    Yeah, you could have tinted screen a color & set the strength with the openGL shader or apply lighting (spotlights) in any color you like, but neither of those options would add shadows or anything as it's still a 2D game. Useful if you want to darken a room & give your character a flashlight or the scene shifts between dark & light due to it being a dark room with some flashing/pulsing fluorescent lights or emergency lighting.

    Imperator

    6846 Posts

Write post