Custom character positioning

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
Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Custom character positioning

#1 Post by Onishion »

Ok, so far I've been positioning my standard characters using the standard locations, "at right," "at center," etc. I wanted to come up with something a bit more specific though, I wanted to make a specific custom location that was more or less the default "at right," and then a second that was roughly halfway between that and "at center," so that I could position two characters more close together than the defaults. Obviously I could just manually "pos" the images at the exact location, but I wanted something simple and reusable.

So I tried to manage this myself, and got some slightly confusing results. characters that had been pegged to the ground and in the proper location, were now floating slightly "off the ground." Also, different images would be in wildly different locations, sometimes off the screen.

What I'm looking for is:

1. What is the code behind the default "at right" type command, so that I can duplicate and tweak that command?

2. What would be the best way to take something like a Livecomposite sprite and shift around it's default "center" so that it's autocentered onto that point? Do I just set it's anchor to (0.5,1.0)? is there a way to put that directly into a Live Composite's block, or do I have to reference the Livecomposite in a second image?

3. I want to animate the sprites, but I want those animations to be relative to the reference point. What's the best way to handle that? What I mean is, let's say that the new "at NuRight" reference point is at X900, and the "at NuCenter" one is at X750, and I want to make an animation that has it wiggle 30 pixels side to side with that point at its center, how would I do that animation? I believe that if I just use xpos then it uses absolute screen values, not relative, so an animation written to look right at "at NuRight" would be broken if called from "at NuCenter."

One tool that I think Renpy could really benefit from, perhaps, is something in the debug menu that you can toggle on that will cause an image to display a border line around where Renpy believes it's borders to be (given transparencies), and also a crosshair where the anchor point is, and also another crosshair where the point of rotation is.

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

Re: Custom character positioning

#2 Post by philat »

1. They're in 00definitions.rpy (in the renpy common folder). Search for transform right. You can override the defaults by redefining transform right in your script files.

2. I'm not sure I understand the question. Why wouldn't using anchor achieve what you want? Do note that using align will override anchor anyway -- align is equivalent to setting pos and anchor. http://www.renpy.org/doc/html/atl.html# ... erty-align

3. Use xoffset/yoffset (see above link).

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Custom character positioning

#3 Post by Onishion »

Ok, so

1. thanks, I'll check that out,

2. I can't figure out a good place to put an anchor in a Live Composite. If the following is my LC:

Code: Select all

image TestImage = LiveComposite(                                                                             
        (420,750), 
        (0,0), ConditionSwitch(
            "A == 1", "images/image1.png",
            "A == 2", "images/image2.png",
            ),
        )

#Where would I put an anchor command so that I could "show TestImage at right" and it would have that anchor built into it already? Any place I've tried putting it within that block, it throws back an error that it doesn't expect that anchor to be there. I've also tried the following:

image Test2:
    contains:
        "TestImage"
        xanchor 0.5

#but that tends to end up in entirely the wrong place when I "show Test2".

3. Ok, and I have poured over that page constantly while working on ATLs, so offsets will cause the image to move around relative to the pos values previously set, while pos values would always be relative to the screen? Got it. I'll see what I can do then.

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

Re: Custom character positioning

#4 Post by philat »

You don't need contains.

Code: Select all

image TestImage:
    LiveComposite(blahblah)
    xanchor 0.5
And again, showing something "at right" -- assuming you are using aligns -- will override the default anchor anyway.

Try for yourself to see how align, pos, and anchor work.

Code: Select all

image TestImage:
    "image path"
    xanchor 0.5

transform rightpos:
    xpos 0.9

transform rightanc:
    xanchor 1.0

transform rightal:
    xalign 0.9

label start:
    show TestImage at rightpos # shows image with default xanchor (0.5) at xpos 0.9
    "blah"
    show TestImage at rightpos, rightanc # pos and anchor are indepedent, so it shows xpos 0.9, xanchor 1.0
    "blah"
    show TestImage at rightal # align overrides the default xanchor, so the result is xpos 0.9, xanchor 0.9
    "blah"
    show TestImage at rightal, rightanc # right anchor is applied after right align -- therefore, the resulting position is xpos 0.9, xanchor 1.0
    "blah"
    show TestImage at rightanc, rightal # right align is applied after right anchor, overriding right anchor = is the same as just using align
    "blah"

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Custom character positioning

#5 Post by Onishion »

Ok, I fooled around with this a bunch, and came up with something that pretty much meets my needs, but I think I can streamline it to be a much more efficient bit of code (less assigning variables specific to each character), only I can't exactly figure out how to get the conditional I want into the transform.

What I want is to be able to say "show CharacterA at SpriteLoc(1)" then "show CharacterA at SpriteLoc(2)", and it'll put each character at a location that had been assigned to it. So basically what I have for that is:

Code: Select all

default SRight = 900
default SCenter = 715

default ASLoc = SRight
default BSLoc = SCenter

#First I tried:

transform SpriteLoc(Chr=1):
    if Chr == 1:
        pos (ASLoc,1.0) 
    elif Chr == 2:
        pos (BSLoc,1.0)
    else:
        pos (SRight,1.0)

# That didn't work because you apparently can't put an if-type statement into a transform, it throws back an indent error message, 
# but if this DID work like a traditional if statement would, it would do the thing I wanted. Next I tried:

transform SpriteLoc(Chr=1):
    ConditionSwitch(
        "Chr == 1", "pos (ASLoc,1.0)", 
        "Chr == 2", "pos (BSLoc,1.0)",
        "True", "pos (SRight,1.0)",
        )

#and tried it with and without "" around the position part, but not only could it not pull in the "Chr" variable I was trying to use,  I also couldn't get it to do anything with the second half.        
I know I'm kind of pushing it on what I'm doing there, and worst case I can go back to my previous version that required setting variables outside the call, but I'd really like this to work so that the "at" statement is as small as possible.

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

Re: Custom character positioning

#6 Post by philat »

Well, I don't know HOW simple vs. flexible you want to go, but something along the lines of the following seems pretty usable from my perspective. If you need to adjust the variables on the fly, you can write a function to do that using conditions outside of the transform (as far as I know, there is no way to use conditions directly in transforms).

ConditionSwitch is inapplicable -- that's for defining images themselves, not ATL elements to be used in transforms.

Code: Select all

default rsprite = (0.9, 1.0)
default lsprite = (0.1, 1.0)

transform SpriteLoc1(tup):
    pos tup

transform SpriteLoc2(x, y):
    pos (x, y)

label start:
    show image at SpriteLoc1(rsprite)
    show image at SpriteLoc2(0.9, 1.0)    

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Custom character positioning

#7 Post by Onishion »

Hmm. That was a bit similar to the system I had before the one I posted, with the difference being that I was trying to assign locations to individual characters, so that when multiple characters were on screen they would each know where they were meant to be. Kinda complicated to explain, sorry. I'm thinking at this point what I might do is forgo "show" statements entirely in my main story code, and replace them with calling a label that will show the indicated character at the appropriate location (ie "call Show(1)"). That could end up being more versatile anyway, since I could assign that label with multiple options elements like transitions and stuff that would only be used if asked for.

Post Reply

Who is online

Users browsing this forum: No registered users