Moving displayable upon action

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
synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Moving displayable upon action

#1 Post by synedraacus »

I have this issue with the imagemap: it is literally a map, and has a number of visitable points. The one you are currently at is marked by a little ship icon, and clicking on any adjacent point is updating some game data and moving the icon. However, the ship is moved instantaneously, while I'd like it to travel for half a second or so. How do I make it so?

Code for imagemap:

Code: Select all

screen map_screen():
    tag map
    modal True
    zorder 2
    if gl_no_rollback:
        $ renpy.block_rollback()
    imagemap:
        auto 'images/1024map_%s.png'
        hotspot monet.hotspot action Travel(monet)
        hotspot tartari.hotspot action Travel(tartari)
        #
        #More nodes here in no particular order
        #They are exactly the same
        #
        hotspot node7.hotspot action Travel(node7)
    add 'images/1024ship.png':
        anchor (0.5, 1.0)
        pos current_port.coordinates
        id 'ship'
Code for Travel action:

Code: Select all

    class Travel(Action):
        def __init__(self, map_point, **kwargs):
            super(Action, self).__init__(**kwargs)
            self.map_point = map_point

        def __call__(self):
            global current_port
            current_port = self.map_point
            ship = renpy.get_widget('map_screen', 'ship')
            ship.pos = current_port.coordinates
            renpy.hide_screen('map')
            renpy.jump(self.map_point.get_label())

        def get_sensitive(self):
            global current_port
            if self.map_point.check_connected(current_port):
                return True
            else:
                return False

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

Re: Moving displayable upon action

#2 Post by philat »

Pretty sure it's just a matter of supplying a transform to the ship.

Code: Select all

default coords = (0.5, 0.5)

screen test():
    add Solid("FFF", xysize=(50, 50)):
        at shiptransform(coords)

transform shiptransform(coords):
    linear 0.5 pos coords

label start:

    show screen test()
    "blah"
    $ coords = (0.1, 0.1)
   "blah"
    $ coords = (0.4, 0.4)
    "blah"


synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Re: Moving displayable upon action

#3 Post by synedraacus »

Thanks philat, I got this working (although I had to write a transform that takes into account both old and new coordinates), but stumbled into the next problem. My code (in Travel action) hides map screen after ship coordinates have been updated, so the transform is actually shown only when the screen is shown for the next time, which is weird. The player travels to a location, reads whatever happens there, departs and only after that his ship does finally arrive.
I have tried adding renpy.redraw(ship, 0), renpy.restart_interaction(), calling update() on ship Transform, and renpy.force_full_redraw() to the __call__ method, but it does not help. Neither does adding pause and hide screen statement to the location start label instead of the method (with or without on hide clause in transform). How do I make screen hiding wait until the transform has finished?

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

Re: Moving displayable upon action

#4 Post by philat »

No idea if this is the best way to get this done, but showing a separate blank screen with a timer and calling renpy.retart_interaction() works for me in a little test game. You can then hide both screens in the label that is jumped to or in the timer screen, I think.

The following code is to illustrate the concept only; I stripped your stuff down to a bare minimum for testing purposes, but you can probably use this as a springboard for your own stuff.

Code: Select all

screen test1():
    textbutton "Test" action Travel((400, 400), "testlabel")
    add Solid("FFF", xysize=(50,50)):
        at shiptransform(coords)

screen timer2(label):
    text "blahblah" pos (200, 200)
    timer 1.0 action Jump(label)

init python:
    class Travel(Action):
        def __init__(self, var, label, **kwargs):
            super(Action, self).__init__(**kwargs)
            self.var = var
            self.label = label

        def __call__(self):
            global coords
            coords = self.var
            renpy.show_screen("timer2", label=self.label)
            renpy.restart_interaction()

synedraacus
Regular
Posts: 58
Joined: Tue Jun 09, 2015 8:10 am
Github: synedraacus
Contact:

Re: Moving displayable upon action

#5 Post by synedraacus »

Thank you, I've got it working. There are a few details I had to adjust (like throw Hide actions to timer screen and fiddling with coordinate variables), but overall idea is great.

Post Reply

Who is online

Users browsing this forum: No registered users