[SOLVED] Help with creating a dev tool for camera panning and zooming

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
Yare-yare
Newbie
Posts: 4
Joined: Fri Sep 02, 2022 9:42 am
Contact:

[SOLVED] Help with creating a dev tool for camera panning and zooming

#1 Post by Yare-yare »

Hello,

I'm currently working on a dev screen for a visual novel.
I'm having problem with setting camera settings on the go. Let me explain

Code: Select all

# the variables
default camera_zoom = 1.0
default camera_xpos = 0
default camera_ypos = 0

screen dev_screen():
###
	the rest of the code
###
if camera_ctrl: # A value to change on a keypress so I can hide the window anytime I want
        frame:
            align (0.0,1.0)
            xsize 512
            hbox:
                vbox:
                    grid 3 3:
                        button:
                            text "zoom = [r_zoom]"
                            action [SetVariable("camera_zoom", 1.0), Call("set_camera")] #This button displays the current zoom and sets it back to default if I want to

                        if camera_zoom > 0:
                            button:
                                text "<"
                                action [SetVariable("camera_zoom", camera_zoom - 0.05), Call("set_camera")] # Incrementing the value down and making change on the go
                        else:
                            text "<"

                        if camera_zoom < 10.0:
                            button:
                                text ">"
                                action [SetVariable("camera_zoom", camera_zoom + 0.05), Call("set_camera")] # Incrementing the value down and making change on the go
                        else:
                            text ">"

                        button:
                            text "xalign = [camera_xpos]"
                            action [SetVariable("camera_xpos", 0), Call("set_camera")]
                        bar:
                            xmaximum 246
                            value VariableValue("camera_xpos", 1920*2, offset=-1920) # a bar value for the xpos in camera
                        text ""

                        button:
                            text "yalign = [camera_ypos]"
                            action [SetVariable("camera_ypos", 0), Call("set_camera")]
                        bar:
                            xmaximum 246
                            value VariableValue("camera_ypos", 1080*2, offset=-1080) # a bar value for the xpos in camera
                        text ""
                    grid 2 1:
                        button:
                            text "SET"
                            action Call("set_camera") # Calls the label to change camera settings
                        button:
                            text "Default"
                            action Call("set_def_camera") # sets the camera back to normal

if config.developer == True:
    init python:
        config.per_frame_screens.append("dev_screen") #Ading the screen
        config.overlay_screens.append("dev_screen") #Ading the screen

label set_camera():
    [b]call set_def_camera[/b]
    pause 1
    camera:
        pos (camera_xpos, camera_ypos)
        zoom camera_zoom
    return

label set_def_camera():
    camera:
        pos (0, 0)
        zoom 1
    return
The problem that I have is every time I call the label set_camera (in any way like bar value change or setting back to default individual variables) without calling the label set_def_camera the change won't happen.

Could I get some help with that because I don't know what I am missing here ;-;
Currently I am using renpy 8.0.2 - I think I would preferably revert to a version where the 3d camera works better so I could add maybe more animation but that's a plan for the future - now I need a simple way to make animations with camera so I can test it in the game and write down the values to make quick coding :v

Thanks if anyone replies and I am sorry if my English don't sound that good :/
Last edited by Yare-yare on Tue Sep 13, 2022 1:04 pm, edited 1 time in total.

Mihara
Regular
Posts: 119
Joined: Thu Mar 11, 2010 2:52 pm
Contact:

Re: Help with creating a dev tool for camera panning and zooming

#2 Post by Mihara »

Before anyone gets in too deep trying to figure it out, are you sure ActionEditor is insufficient for your developer needs?

https://github.com/kyouryuukunn/renpy-ActionEditor3

Yare-yare
Newbie
Posts: 4
Joined: Fri Sep 02, 2022 9:42 am
Contact:

Re: Help with creating a dev tool for camera panning and zooming

#3 Post by Yare-yare »

The action editor is great but I need to see quick changes because the team while reviewing could have other idea about the position of the camera so instead typing in the console parameters or using the action editor they could just use a slider, although I think maybe I will switch to another idea (hovering over the edge and a scroll to zoom) but I need first to fix this issue with setting the camera back to default :v

laure44
Regular
Posts: 84
Joined: Mon Mar 08, 2021 10:55 pm
Projects: Arkan'sTower, Gemshine Lorelei!
Location: France
Contact:

Re: Help with creating a dev tool for camera panning and zooming

#4 Post by laure44 »

I have absolutely no idea what's going on to be honest, so I've messed with your code a little and tried another way to achieve what you need. You don't need to press a button to see the result anymore and I've also added a Copy button to copy the camera statement to the clipboard.

Code: Select all

default camera_zoom = 1.0
default camera_xpos = 0
default camera_ypos = 0

init python:
    import pygame.scrap
    def dev_clipboard(txt):
        pygame.scrap.put(pygame.scrap.SCRAP_TEXT, txt.encode("utf-8"))

    def camera_change():
        global camera_zoom, camera_xpos, camera_ypos
        renpy.show_layer_at([Transform(zoom=camera_zoom, xpos=camera_xpos, ypos=camera_ypos)], camera=True)

screen dev_screen():

    default show_copied = False
    if show_copied:
        timer 1.5 action ToggleScreenVariable("show_copied")

    if camera_ctrl:
        frame:
            align (0.0,1.0)
            xsize 512
            vbox:
                grid 3 3:

                    button:
                        text "zoom = [r_zoom]"
                        action SetVariable("camera_zoom", 1.0), Function(camera_change)
                    button:
                        if camera_zoom <= 0:
                            sensitive False
                        text "<"
                        action SetVariable("camera_zoom", round(camera_zoom-0.05,2)), Function(camera_change)
                    button:
                        if camera_zoom >= 10.0:
                            sensitive False
                        text ">"
                        action SetVariable("camera_zoom", round(camera_zoom+0.05,2)), Function(camera_change)

                    button:
                        text "xalign = [camera_xpos]"
                        action SetVariable("camera_xpos", 0), Function(camera_change)
                    bar:
                        xmaximum 246
                        value VariableValue("camera_xpos", 1920*2, offset=-1920)
                        changed camera_change()
                    text ""

                    button:
                        text "yalign = [camera_ypos]"
                        action SetVariable("camera_ypos", 0), Function(camera_change)
                    bar:
                        xmaximum 246
                        value VariableValue("camera_ypos", 1080*2, offset=-1080)
                        changed camera_change()
                    text ""

                hbox:
                    textbutton "Default" action SetVariable("camera_zoom", 1.0), SetVariable("camera_xpos", 0), SetVariable("camera_ypos", 0), Function(camera_change)
                    textbutton "Copy":
                        action [
                            Function(dev_clipboard, txt="camera:\n    zoom "+str(camera_zoom)+" xpos "+str(camera_xpos)+" ypos "+str(camera_ypos)), # Copies the result to clipboard
                            SetScreenVariable("show_copied", True)
                        ]
                    if show_copied: # Shows that it has been copied
                        text "Copied!"

if config.developer == True:
    init python:
        config.per_frame_screens.append("dev_screen") #Ading the screen
        config.overlay_screens.append("dev_screen") #Ading the screen


Yare-yare
Newbie
Posts: 4
Joined: Fri Sep 02, 2022 9:42 am
Contact:

Re: Help with creating a dev tool for camera panning and zooming

#5 Post by Yare-yare »

This works so smooth :shock: It's perfect :D Thank you very much laure44 !

I'm gonna share the whole dev screen later if someone is interested (currently I'm on a deadline I cannot waste time ;-; )
I have implemented a live image tag viewer (so we can see what current expression on a character is shown :v ),
a simple drag-able window with variables changer (like switching cool variables, incrementing int values and changing string values),
For my purpose I have some hotkeys for changing
I know most of this thing can be done by using the included developer tools or addons (like the action editor), but it's a bigger challenge and more flexibility when you do it yourself :v

P.S. I am a noob so don't judge me pls.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot]