Using imagemaps to create a flowchart, hotspots not working

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.
Post Reply
Message
Author
MisterPinetree
Newbie
Posts: 5
Joined: Mon Apr 22, 2024 10:25 pm
Contact:

Using imagemaps to create a flowchart, hotspots not working

#1 Post by MisterPinetree »

I'm at a complete loss here. I've been trying to get my imagemap working for a flowchart for days.

The first code block is the actual relevant block of code, the second code block is where I defined the Node class and list of nodes

Code: Select all

screen flowchart():

    default select_node = None
    
    frame:
        xysize (config.screen_width, config.screen_height)
        # this bg is just a blue-green screen 
        add "bg_flowchart"
        vbox:
            align (0.5, 0.5)
            viewport id "repaired_flowchart":
                xalign 0.5
                yalign 0.5
                # xysize (3865, 2185) 
                xysize(900, 2000)
                xinitial 0.5
                    
                # this code works, since it adds the images in the right spot
                for node in nodes:
                    add node.get_icon() pos (node.coordinates) size (40, 40)

                imagemap:
                    # I only need the ground image, just added the others in case there's a bug
                    ground "flowchart/images/flowchart_repaired_no_true.png"
                    idle "flowchart/images/flowchart_repaired_no_true.png"
                    hover "flowchart/images/flowchart_repaired_no_true.png"
                
                    for node in nodes:
                    	# this code doesn't work, since a sound isn't playing
                        hotspot (node.coordinates[0], node.coordinates[1], 40, 40):
                        	# sound playing is just to try and verify it's working
                        	hover_sound "sound/confirm-beep.mp3"
                        	# commented out cause not working anyway
                           	# action [Function(update_transform, node), SetVariable("select_node", node)]

Code: Select all

init python:
    from enum import Enum

    class Status(Enum):
        UNREAD = "unread"
        NOVEL = "novel"
        ESCAPE = "escape"
        END = "end"

    class Node:
        def __init__(self, coordinates, name, description, is_accessible, status=None, icon=None):
            self.coordinates = coordinates
            self.name = name
            self.description = description
            self.is_accessible = is_accessible
            self.status = status
            self.icon = icon

        def set_is_accessible(self, is_accessible):
            self.is_accessible = is_accessible

        def get_icon(self):
            if self.icon:
                return self.icon
            if self.status is Status.UNREAD:
                return 'flowchart/images/nodes/unread.png'
            elif self.status is Status.NOVEL:
                return 'flowchart/images/nodes/novel.png'
            elif self.status is Status.ESCAPE:
                return 'flowchart/images/nodes/escape.png'
            return None

    nodes = [
        Node((400, 0), "Fragment 0 ~ Scene 1", "Beginning", True, Status.NOVEL),
        Node((400, 80), "Fragment 0 ~ Scene 2", "Meeting Everyone", frag0_s1_complete, Status.UNREAD),
        Node((400, 160), "Fragment 0 ~ Scene 3", "Rules of the Game", frag0_s2_complete, Status.UNREAD),
        Node((400, 240), "End of Prologue", None, frag0_complete, Status.END, "flowchart/images/nodes/badend.png")
        ]
        
1. The images render correctly on the flowchart, so the coordinates are all correct
2. The hotspot doesn't work at all, even if I change it to a single massive hotspot
3. I don't care about giving the images a hover or idle effect, because my goal is just to make the flowchart interactable
4. Failing any help here, I would love some advice on how I can debug with Ren'Py. I have no visibility with logs, print statements, etc

I've looked at documentation, which isn't super helpful because it never actually documents all the attributes. I've also looked at some of the imagemap posts on this forum.

Attached are my ground image, and the rendered image I have so far with the nodes I've made so far. I'm hoping at the end to use some sort of crosshair to indicate the selected node and allow the user to select other nodes with the arrow keys.
Screenshot 2024-04-22 at 11.09.58 PM.png
(2.08 MiB) Not downloaded yet
flowchart_repaired_no_true.png
(156.44 KiB) Not downloaded yet

philat
Eileen-Class Veteran
Posts: 1922
Joined: Wed Dec 04, 2013 12:33 pm
Contact:

Re: Using imagemaps to create a flowchart, hotspots not working

#2 Post by philat »

A hotspot needs an action to be hoverable (use NullAction() as a placeholder if need be). You also wouldn't be able to see whether your hotspot is since your idle and hover images are the same.

Code: Select all

                imagemap:
                    ground "flowchart_repaired_no_true"
                    idle Solid("#FF09", xysize=(config.screen_width, config.screen_height)) 
                    hover Solid("#F009", xysize=(config.screen_width, config.screen_height))

                    for node in nodes:
                        hotspot (node.coordinates[0], node.coordinates[1], 40, 40) action NullAction()
The above is working for me (the red one is hovered).
screenshot0001.png
(9.8 KiB) Not downloaded yet

MisterPinetree
Newbie
Posts: 5
Joined: Mon Apr 22, 2024 10:25 pm
Contact:

Re: Using imagemaps to create a flowchart, hotspots not working

#3 Post by MisterPinetree »

Thank you, that was hugely helpful.

It seems to be working now, but strangely it seems to work "better" when I have the idle and hover code you provided? It's much more responsive. I still get the beep sound when I comment out the idle/solid code, but only about half the time.

I replaced the idle/hover with an identical image but different file, and I get the same issue

Code: Select all

              imagemap:
                    ground "flowchart/images/flowchart_repaired_no_true.png"
                    idle "flowchart/images/flowchart_repaired_no_true2.png"
                    hover "flowchart/images/flowchart_repaired_no_true3.png"

                    for node in nodes:
                        hotspot (node.coordinates[0], node.coordinates[1], 40, 40):
                            action NullAction()
                            hover_sound "sound/confirm-beep.mp3"
If I try to use a transparent background, the hotspot is more responsive again but it just doesn't look right (all the nodes become black)

Code: Select all

        imagemap:
                    ground "flowchart/images/flowchart_repaired_no_true.png"
                    idle "flowchart/images/transparent.png"
                    hover "flowchart/images/transparent.png"
It's really strange because the hotspots go from working every time (with "proper" idle/hover images) to like 50% of the time if I'm trying to not use the hover/idle effect.

Is there a way to use a different idle/hover image that creates a more subtle effect? Or no effect at all?

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]