[SOLVED] Desperate help needed on positioning images.

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
mugenjohncel
Hentai Poofter
Posts: 2117
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines
Contact:

[SOLVED] Desperate help needed on positioning images.

#1 Post by mugenjohncel » Sun Jan 17, 2010 3:00 am

I am now desperate and begging for assistance.

I have this VN where you sell fried lizards. And in the middle of it all is a clock system where every decision you make will have to revolve around the clock. This is a very important component of the VN... without it, everything falls apart.

What I have here is the working code (thanks Alex) that works almost perfectly (position, rotation, everything) but doesn't quite disappear out of screen as intended. So PyTom provided an edited and updated code (thanks) which eliminates the dissolve problem but there is another problem.

Here are the images used in the clock code:
Image
The Clock Face (clock_2.png)

Image
Long Clock Hand (clock.png)

Image
Short Clock Hand (clock_1.png)

Here is the updated clock code:

Code: Select all

init python:
    renpy.image("clock", "gui_set/clock.png") # Short Clockhand
    renpy.image("clock_1", "gui_set/clock_1.png") # Long Clockhand
    renpy.image("clock_2", "gui_set/clock_2.png") # Clockface
        
    def Clocks():
        if clock: # if False - clock is hide
            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.add("clock_2")
            # xalign and yalign can be replaced by xpos and ypos - position where the center of the clock should be
            # this segment is the one responsible for the clockface
            
            ui.at(RotoZoom((minutes*6), (minutes*6), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False))
            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.add("clock")
            # this segment is the one responsible for the short clock hand. 

            ui.at(RotoZoom ((minutes*0.5), (minutes*0.5), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False))
            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.add("clock_1")
            # this segment is the one responsible for the long clock hand.

    config.overlay_functions.append(Clocks)
So it works like this:
The clock face will be shown on screen at position xpos=150, ypos=140 with center anchor followed by the clock hands, PNG's with transparencies that are the same size as the clockface.

Code: Select all

$ clock = False
with dissolve
When set to "True" Clock will appear in the screen with "dissolve"
When set to "False" Clock will disappear with "dissolve"

Code: Select all

$ minutes = 720
This will set the time of the clock. By default, clock will start at 0 which means 12:00MN.

To add time you use code like this

Code: Select all

$ minutes += 1
The code above adds 1 minute to the time and will rotate the minute hand by about 6 degrees clockwise and at the same time will make the our clock move by about 0.5 degrees.

So if your clock count is...

Code: Select all

$ minutes = 0
It is 12:00MN

And you add something like this

Code: Select all

$ minutes += 60
The minute hand will rotate 360 degrees and the hour hand will now point at 1... just like a real analog clock...

So it's like this...

Code: Select all

# Clock Guide    
# 12:00 MN - 0
# 1:00  AM - 60
# 2:00  AM - 120
# 3:00  AM - 180
# 4:00  AM - 240
# 5:00  AM - 300
# 6:00  AM - 360
# 7:00  AM - 420
# 8:00  AM - 480
# 9:00  AM - 540
# 10:00 AM - 600
# 11:00 AM - 660
# 12:00 NN - 720 
# 1:00  PM - 780
# 2:00  PM - 840
# 3:00  PM - 900
# 4:00  PM - 960
# 5:00  PM - 1020
# 6:00  PM - 1080
# 7:00  PM - 1140
# 8:00  PM - 1200
# 9:00  PM - 1260
# 10:00 PM - 1320
# 11:00 PM - 1380
Now it is working as intended... it rotates like a clock it behaves like a clock except I now lost the ability to precisely position the clock hands in the screen... I tried adjusting the obvious parts that will dictate their positions in the screen... the clock-face can and does behave as it should have been but the same can't be said of the hands... they're just stuck there. They rotate and behave like a clock except they're not in the right place...

Image

All I needed now is to position the clock hands precisely at the center of the clockface. I tried everything in my limited capabilities but I've exhausted every once of my processing power.

Please help me... this poor old battered man...
Last edited by mugenjohncel on Sun Jan 17, 2010 4:15 am, edited 1 time in total.

User avatar
denzil
Veteran
Posts: 293
Joined: Wed Apr 20, 2005 4:01 pm
Contact:

Re: Desperate help needed on positioning images.

#2 Post by denzil » Sun Jan 17, 2010 3:59 am

I swapped those two ui.at lines, and it seems to work:

Code: Select all

init python:
    renpy.image("clock", "gui_set/clock.png") # Short Clockhand
    renpy.image("clock_1", "gui_set/clock_1.png") # Long Clockhand
    renpy.image("clock_2", "gui_set/clock_2.png") # Clockface

    def Clocks():
        if clock: # if False - clock is hide
            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.add("clock_2")
            # xalign and yalign can be replaced by xpos and ypos - position where the center of the clock should be
            # this segment is the one responsible for the clockface
           
            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.at(RotoZoom((minutes*6), (minutes*6), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False), )
            ui.add("clock")
            # this segment is the one responsible for the short clock hand.

            ui.at(Position(xpos=150, ypos=140, xanchor="center", yanchor="center"))
            ui.at(RotoZoom ((minutes*0.5), (minutes*0.5), 5.0, 1, 1, 1, rot_bounce= False, rot_anim_timebase=False, opaque=False))
            ui.add("clock_1")
            # this segment is the one responsible for the long clock hand.

    config.overlay_functions.append(Clocks)
Practice makes purrrfect.
Finished projects: Broken sky .:. colorless day .:. and few more...

User avatar
mugenjohncel
Hentai Poofter
Posts: 2117
Joined: Sat Feb 04, 2006 11:13 pm
Organization: Studio Mugenjohncel
Location: Philippines
Contact:

Re: Desperate help needed on positioning images.

#3 Post by mugenjohncel » Sun Jan 17, 2010 4:14 am

Image
Yes it is working now... Thank you... really, thank you!!! :D

I've been trying to figure it for two days now... I make sure you're properly credited...

"POOF" (Can I hug you?)

Post Reply

Who is online

Users browsing this forum: _ticlock_