Flashlight effect?

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Message
Author
User avatar
GlassHeart
Regular
Posts: 105
Joined: Fri Mar 11, 2011 12:13 pm
Completed: Hand in hand with destiny, Out of Sight, Summer Found Me (Again), Signed X, Trapped
itch: https://selavi.itch.
Location: Romania
Contact:

Flashlight effect?

#1 Post by GlassHeart »

This is what I want :
Image

Basically you have a black background and you use the cursor as a flashlight. The area around the cursor's location will be "lit up" revealing an image. Any ideas if this is even possible?
Image Image

User avatar
kkffoo
Regular
Posts: 133
Joined: Wed Sep 22, 2010 3:17 am
Completed: Tea For Two [KN]
Location: UK
Contact:

Re: Flashlight effect?

#2 Post by kkffoo »

Have a black layer on top larger than bottom layer, cut feathered hole, move black layer around?

User avatar
GlassHeart
Regular
Posts: 105
Joined: Fri Mar 11, 2011 12:13 pm
Completed: Hand in hand with destiny, Out of Sight, Summer Found Me (Again), Signed X, Trapped
itch: https://selavi.itch.
Location: Romania
Contact:

Re: Flashlight effect?

#3 Post by GlassHeart »

That's not a bad idea... I have no idea how I would move it around to follow the cursor, but it's a place to start. Thank you!
Image Image

TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Flashlight effect?

#4 Post by TrickWithAKnife »

Well, it is possible to change the mouse pointer to another image, but it has some problems.
Either it will only change for a very short period, then revert back to the original mouse pointer, or it will stay on your custom pointer permanently. I presume neither of those would be suitable for what you need.

As for getting an image to follow the mouse pointer, I'm fairly sure it's impossible.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

User avatar
PyTom
Ren'Py Creator
Posts: 16093
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Flashlight effect?

#5 Post by PyTom »

You can get an image to follow the mouse cursor, but you need a CDD to do it. You'd also want to use the AlphaBlend displayable to do the flashlight effect - there's an example of it in the tutorial.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Flashlight effect?

#6 Post by TrickWithAKnife »

CDD is really complicated for non-programmers.

I messed around with the code for a snowblossom demo that was somewhere in the wiki (sorry, couldn't find it again to link).
There was some code for a repulsor, so I messed around with that, and eventually managed to get an image to follow the mouse cursor.

Anyway, if you still need it, here is the code. As I said, I just modified code from the wiki, so there are probably much better ways to do it. Also, it could look a bit weird if the player goes fullscreen.

script.rpy:

Code: Select all

image bg creepyroom = "Background.jpg"
        
label start:
    scene black

    "Where is that light switch...?"
    scene bg creepyroom
    call repulsor_demo
    "That was really creepy! I'm glad it's over!"
    return
whateveryouwanttocallit.rpy:

Code: Select all

init python:
    import math

    def repulsor_update(st):

        # If we don't know where the mouse is, give up.
        if repulsor_pos is None:
            return .01

        px, py = repulsor_pos

        # For each sprite...
        for i in repulsor_sprites:

            distance = 0.5 # Shouldn't really matter, as the image will jump to the mousepointer.
            i.x = px - (config.screen_width * 1.25) # Half the size of the "flashlight" image
            i.y = py - (config.screen_height * 1.25) # Half the size of the "flashlight" image
            # The flashlight image is basically 2.5 times the width and height of the game window. (800x600)
            #It could look a bit odd if the player switches to fullscreen.

        return .01

    # On an event, record the mouse position.
    def repulsor_event(ev, x, y, st):
        store.repulsor_pos = (x, y)


label repulsor_demo:

    python:
        # Create a sprite manager.
        repulsor = SpriteManager(update=repulsor_update, event=repulsor_event)
        repulsor_sprites = [ ]
        repulsor_pos = None

        # Ensure we only have one image displayable.
        smile = Image("Flashlight2.png") #Flashlight

        # Add a number of sprites. Left this in, as there may be uses to have more than one sprite. And I'm lazy.
        for i in range(1):
            repulsor_sprites.append(repulsor.create(smile))

        # Position the sprites.
        for i in repulsor_sprites:
            i.x = renpy.random.randint(2, 798)
            i.y = renpy.random.randint(2, 598)

        del smile
        del i

    # Add the repulsor to the screen.
    show expression repulsor as repulsor

    " " #To wait for a mouse click.

    hide repulsor

    # Clean up.
    python:
        del repulsor
        del repulsor_sprites
        del repulsor_pos
        
    return
This is set up for a window size of 800x600. It's fairly easy to adjust for other sizes.
There are 2 extra files I used: http://i49.tinypic.com/309585j.png and http://i47.tinypic.com/2h5pld5.jpg

That's it. Perhaps it will be of use to you or someone else, or perhaps someone will be able to make improvements to it.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

User avatar
GlassHeart
Regular
Posts: 105
Joined: Fri Mar 11, 2011 12:13 pm
Completed: Hand in hand with destiny, Out of Sight, Summer Found Me (Again), Signed X, Trapped
itch: https://selavi.itch.
Location: Romania
Contact:

Re: Flashlight effect?

#7 Post by GlassHeart »

TrickWithAKnife, that was perfect. I've coupled it with a $ mouse_visible = False and it looks even better. Thank you soooo much!
Image Image

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Flashlight effect?

#8 Post by Levrex »

TrickWithAKnife wrote:

Code: Select all

init python:
    import math

    def repulsor_update(st):

        # If we don't know where the mouse is, give up.
        if repulsor_pos is None:
            return .01

        px, py = repulsor_pos

    # On an event, record the mouse position.
    def repulsor_event(ev, x, y, st):
        store.repulsor_pos = (x, y)
That's it. Perhaps it will be of use to you or someone else, or perhaps someone will be able to make improvements to it.
That's pretty much wonderful.
If i'm not mistaken, with changes in the code above this could be combined with mousearea, so when the "light" hovers over something, a certain action ensues?

It would be a real light in the darkness for horror visual novels... maybe.
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

junna
Veteran
Posts: 347
Joined: Sat Sep 08, 2012 4:16 am
Projects: DreamWalker; History; Adversity Competition
Contact:

Re: Flashlight effect?

#9 Post by junna »

Levrex wrote:
TrickWithAKnife wrote:

Code: Select all

init python:
    import math

    def repulsor_update(st):

        # If we don't know where the mouse is, give up.
        if repulsor_pos is None:
            return .01

        px, py = repulsor_pos

    # On an event, record the mouse position.
    def repulsor_event(ev, x, y, st):
        store.repulsor_pos = (x, y)
That's it. Perhaps it will be of use to you or someone else, or perhaps someone will be able to make improvements to it.
That's pretty much wonderful.
If i'm not mistaken, with changes in the code above this could be combined with mousearea, so when the "light" hovers over something, a certain action ensues?

It would be a real light in the darkness for horror visual novels... maybe.
or those CSI style glow-in-the dark luminol things.
chibi avvie by Meg (buprettyinpink).
WIP=>Image
Image<=helping out

TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Flashlight effect?

#10 Post by TrickWithAKnife »

GlassHeart wrote:TrickWithAKnife, that was perfect. I've coupled it with a $ mouse_visible = False and it looks even better. Thank you soooo much!
Ahh, I didn't think of that, but it's very useful for something I'm working on. Thanks.

Levrex wrote:If i'm not mistaken, with changes in the code above this could be combined with mousearea, so when the "light" hovers over something, a certain action ensues?
I'd love to have something like that. Right now I'm trying to figure out how to get the image that is following the mouse to stay on screen when using imagemaps.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

User avatar
Arowana
Miko-Class Veteran
Posts: 531
Joined: Thu May 31, 2012 11:17 pm
Completed: a2 ~a due~
Projects: AXIOM.01, The Pirate Mermaid
Organization: Variable X, Navigame
Tumblr: navigame-media
itch: navigame
Contact:

Re: Flashlight effect?

#11 Post by Arowana »

What a cool idea! Thanks so much for the code, TrickWithAKnife! I'm definitely bookmarking it for future use. xD
Complete: a2 ~a due~ (music, language, love)
In progress: The Pirate Mermaid (fairytale otome)
On hold: AXIOM.01 (girl detective game)

Image

TrickWithAKnife
Eileen-Class Veteran
Posts: 1261
Joined: Fri Mar 16, 2012 11:38 am
Projects: Rika
Organization: Solo (for now)
IRC Nick: Trick
Location: Tokyo, Japan
Contact:

Re: Flashlight effect?

#12 Post by TrickWithAKnife »

Everyone is being very kind, but this code is far from complete.
I'm having trouble with other interactions while the image that follows the mouse cursor is being shown.

I hope if someone someone else figures out how to improve this code, they will share with the rest of us, or perhaps make a simply explained cookbook guide.
"We must teach them through the tools with which they are comfortable."
The #renpy IRC channel is a great place to chat with other devs. Due to the nature of IRC and timezone differences, people probably won't reply right away.

If you'd like to view or use any code from my VN PM me. All code is freely available without restriction, but also without warranty or (much) support.

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Flashlight effect?

#13 Post by Levrex »

Answering my own question about "something" and "certain action"...

Well, while trying to implement "hovered" and "unhovered" into the function itself, i quickly realised that it's a lot easier to stop trying to reinvent the wheel and add mousearea screen in the label directly, like you would do normally.

Example screen:

Code: Select all

screen mouser:
    mousearea:
        area (0, 0, 50, 50)
        hovered Jump("boom")
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

User avatar
Hellboy
Regular
Posts: 86
Joined: Mon Dec 24, 2012 9:37 pm
Location: Heredia. Costa Rica.
Contact:

Re: Flashlight effect?

#14 Post by Hellboy »

This is very cool, but what could be causing the CTC and quick menu to show in the screen while I move the flashlight. Is there a way to hide them while the user moves the flashlight around?
Image
FREE and easy 3D customization, posing, and animation software with pre-made people and environments:
DAZ Studio Pro 4.9

User avatar
Alex
Lemma-Class Veteran
Posts: 3093
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Flashlight effect?

#15 Post by Alex »

Try to add this line

Code: Select all

window hide
to hide textbox with ctc-indicator and quick menu - later you could show it up again by this line

Code: Select all

window show

Post Reply

Who is online

Users browsing this forum: Semrush [Bot]