[SOLVED] Possible to Restrict Dragging Object Direction or Contain in Set Area

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
User avatar
AvalonMelody
Regular
Posts: 47
Joined: Thu May 29, 2014 2:14 am
Contact:

[SOLVED] Possible to Restrict Dragging Object Direction or Contain in Set Area

#1 Post by AvalonMelody »

Hello!

I'm just starting to dive into the drag functions of Renpy and I've got a small idea for a "move away shrubs/grass to find objects" interaction.

So far, I've got the draggable objects functioning, we can make a draggable bush and hide something behind it:

Code: Select all

    drag:
        drag_name "bush1"
        droppable False
        xpos 75
        ypos 600
        child "gui/botany/0/bush1.png"
But I'm wondering if there's a way to restrict the dragging direction or otherwise contain the area where you can drag (and drop) the object. Even just keeping the object to being only draggable on the X axis (or Y, maybe someone wants to make a climbing interaction?)

For example, right now the draggable object is free to move anywhere (we want to uncover what's behind the bush after all) but it's a bit immersion-breaking to be able to drag the bush into the sky or the treetops and leave it there.

I suppose the alternate is an image that can be transformed a few pixels to the left or right on clicking but it feels less exciting than dragging something, so I thought I'd ask the folks here if there's a way. ^-^)

Any insight is appreciated, cheers!
Last edited by AvalonMelody on Sat May 18, 2024 7:39 pm, edited 2 times in total.

jeffster
Miko-Class Veteran
Posts: 520
Joined: Wed Feb 03, 2021 9:55 pm
Contact:

Re: Possible to Restrict Dragging Object Direction or Contain in Set Area

#2 Post by jeffster »

https://renpy.org/doc/html/drag_drop.html#displayables says:
A Drag can be moved around inside is parent. Generally, its parent should be either a Fixed() or DragGroup.
Set the parent rectangle, and the drag would be limited to that rectangle.

PS. It's probably possible to limit dragging directions too, if we define dragged function callback for the draggable, and in that function it might be possible to somehow correct the coordinates of the draggable.
If the problem is solved, please edit the original post and add [SOLVED] to the title. 8)

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3809
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Possible to Restrict Dragging Object Direction or Contain in Set Area

#3 Post by Imperf3kt »

You could adjust the drag_offscreen property to limit the active area of the drag object
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
AvalonMelody
Regular
Posts: 47
Joined: Thu May 29, 2014 2:14 am
Contact:

Re: Possible to Restrict Dragging Object Direction or Contain in Set Area

#4 Post by AvalonMelody »

Wonderful, thanks so much for the quick replies.
With a mix of both fixed and drag_offscreen, I've managed to make some horizontally sliding bushes. No more plants in the sky.
I appreciate it, cheers!

User avatar
AvalonMelody
Regular
Posts: 47
Joined: Thu May 29, 2014 2:14 am
Contact:

Re: [SOLVED] Possible to Restrict Dragging Object Direction or Contain in Set Area

#5 Post by AvalonMelody »

Quick extra post just to show what the code looks like in case someone wants a reference.
I'm sure it could be cleaner and might have extraneous bits though, so if anyone wants to refine it, please feel free to comment and explain.
Always up for cleaner coding. :D

The bush image is a 200x200px png!

Code: Select all

screen draggingTest:    # Bush 1
    fixed:
        xsize 200
        ysize 200
        xanchor 0.5
        yanchor 0.5
        xpos 600
        ypos 600

        drag:
            drag_name "bush1"
            droppable False
            child "gui/drags/bush1.png"
            drag_offscreen (-100, 100, 0, 0) 

Post Reply

Who is online

Users browsing this forum: Bing [Bot]