Transform does not affect certain properties inside UDD

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
ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Transform does not affect certain properties inside UDD

#1 Post by ChesStrategy »

Need some help; I have the following code inside a UDD render() function:

Code: Select all

def render( self, width, height, st, at ):
     
        val = int( st )
        t = store.Transform( child=self.child, xpos=val )
        renpy.log( "st is {}".format( val ) )
        child_render = renpy.render( t, width, height, st, at )
        
        our_render = renpy.Render( self.width, self.height )
        our_render.blit( child_render, (0, 0) )
        
        renpy.redraw( self, 0 )
        return our_render
if I replace the line 'xpos=val' with 'alpha=val', the transform works; but it seems x/ypos, x/yanchor, a few other properties do not transform properly. Do I need to wrap the Transform with a Position() displayable? and pass the non-working properties into there?

This was a simplified example of my issue; I can provide further information as needed.

Regards,
Ches
Last edited by ChesStrategy on Mon Nov 16, 2015 12:48 pm, edited 1 time in total.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Transform does not affect certain properties inside UDD

#2 Post by xela »

You're blitting the damn thing to (0, 0)??? UDD is slightly lower in hierarchy than Transforms. There is a bunch of things you can do but the very simplest is to set the main render to the width of that of the outer container, use that to convert xpos to int and blit it using t.xpos. There is a chance that conversion is not required, I don;'t remember that offhand.
Like what we're doing? Support us at:
Image

ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Re: Transform does not affect certain properties inside UDD

#3 Post by ChesStrategy »

Hi Xela,

Sorry; I've corrected my post; the value should an absolute position; it should be int( st ); anyways...



With regards to blitting, I don't think Ill be able to do that; let me explain, the 'self.child' in the code/'original post' above can be a LiveComposite

The 'real' issue I have is, each 'part' of the livecomposite is a Transform(). I have not been able to get the nested transforms in the LC to work inside a UDD; because... based on what you said (and now I understand); they are a part of a lower hierarchy.

So this means that I need to partially build the LC in real time, with 'hypothetical' code like this:

Code: Select all


def buildLC( ..., st, at ):
   
   ...use st to calculate properties...

   rt_lc = LiveComposite( ( <some_width>, <some_height> ),
   (0,0), Transform( <some_child>, <supported_properties> )
   (50,50), Transform( <another_child>, <supported_properties> )
   (100,100), <Wrapper_displayable>( Transform( ..., ... ) )

   return rt_lc
(
It would be nice to have some wrapper_displayable that can position the transform for me; otherwise, Ill have to dynamically calculate the livecomposite offsets to 'simulate' the effect of moving something in the x/ypos; which can be a hassle.

Regards,
Ches

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Transform does not affect certain properties inside UDD

#4 Post by xela »

I still have no idea what you're trying to get done. You can pass the LC as an object to your UDD to get to it's size, in fact, I recall there was a func that could return the outer displayable but I couldn't find it in docs so unless I've dreamt that there was one, it got lost somewhere :)

In any case, this looks odd as you place the displayable at 100, 100 using LiveComposite, isn't it where it will blit to unless you offset it? I haven't used LC much...

And honestly... you're writing decent code for what seems like a complicated game, LiveComposite is a poor, sad wrapper around a Fixed... you can create your own Fixed, prolly with better syntax, inside UDD if you wish and it may even end up working better and be better manageable.
Like what we're doing? Support us at:
Image

ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Re: Transform does not affect certain properties inside UDD

#5 Post by ChesStrategy »

Hi Xela,

Thanks for the prompt response.
And honestly... you're writing decent code for what seems like a complicated game, LiveComposite is a poor, sad wrapper around a Fixed... you can create your own Fixed, prolly with better syntax, inside UDD if you wish and it may even end up working better and be better manageable.
Yes, worst case I can write my own, and based on what you said, it seems like I will have to do so. Obviously, where I can re-use code, that would reduce workload for me :) , that the primary reason behind why I used LC.

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Transform does not affect certain properties inside UDD

#6 Post by xela »

ChesStrategy wrote:Hi Xela,

Thanks for the prompt response.
And honestly... you're writing decent code for what seems like a complicated game, LiveComposite is a poor, sad wrapper around a Fixed... you can create your own Fixed, prolly with better syntax, inside UDD if you wish and it may even end up working better and be better manageable.
Yes, worst case I can write my own, and based on what you said, it seems like I will have to do so. Obviously, where I can re-use code, that would reduce workload for me :) , that the primary reason behind why I used LC.
Something along these lines:

Code: Select all

def MyCustomLiveComposite_1(size, **properties):

    properties.setdefault('style', 'image_placement')

    width, height = size

    rv = Fixed(xmaximum=width, ymaximum=height, xminimum=width, yminimum=height, **properties)
    rv.add(Transform(<some_child>, <supported_properties>))
    # ... bla bla bla, moar transforms
    rv.add(MyUDD(parent=rv)) # you can use the parent to get the proper size, or if size is a constant, just pass the size itself.

    return rv
You can customize parameters as you see fit to make it as reusable as you like, I am just suggesting a general approach.







==================
This is the original (using ancient Position for whatever reason, I thought the idea was to kill Position off and use Transforms instead as a general rule in Ren'Py development...):

Code: Select all

def LiveComposite(size, *args, **properties):
    """
    :doc: disp_imagelike

    This creates a new displayable of `size`, by compositing other
    displayables. `size` is a (width, height) tuple.

    The remaining positional arguments are used to place images inside
    the LiveComposite. The remaining positional arguments should come
    in groups of two, with the first member of each group an (x, y)
    tuple, and the second member of a group is a displayable that
    is composited at that position.

    Displayables are composited from back to front.

    ::

       image eileen composite = LiveComposite(
           (300, 600),
           (0, 0), "body.png",
           (0, 0), "clothes.png",
           (50, 50), "expression.png")
    """

    properties.setdefault('style', 'image_placement')

    width, height = size

    rv = Fixed(xmaximum=width, ymaximum=height, xminimum=width, yminimum=height, **properties)

    if len(args) % 2 != 0:
        raise Exception("LiveComposite requires an odd number of arguments.")

    for pos, widget in zip(args[0::2], args[1::2]):
        xpos, ypos = pos
        rv.add(Position(widget, xpos=xpos, xanchor=0, ypos=ypos, yanchor=0))

    return rv
Like what we're doing? Support us at:
Image

ChesStrategy
Regular
Posts: 96
Joined: Wed Jan 14, 2015 7:01 pm
Contact:

Re: Transform does not affect certain properties inside UDD

#7 Post by ChesStrategy »

Thanks Xela, I'll look over this; hopefully will not have any followup questions.

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Pandar