rames44a wrote: ↑Thu Feb 09, 2023 12:19 am
you're going round and round on things that I've already covered. I understand that you're trying to help, but so far all you've done is use different terminology than mine ("current properties" or "trans.xpos" instead of "starting position") and explain stuff that I said that I already understand.
Let me boil this down to a very, VERY simple question, as follows:
At any given time, how do I go about obtaining the current transform on the Ren'py camera? The current "xpos" value, to use your example above.
That's it. That's all I need. Everything else I know how to do, as I've tried to explain. That one question is the part I DON'T understand. If you can't answer that question, then, with respect, you're not helping me.
Possibly, I misunderstand you. In my previous post, by "starting position" - I meant properties at timebase
st = 0, while "current properties" are properties at current timebase st.
I asked for an example to get an idea of what would be a better approach for the task.
Here are some ideas that can be useful in your case (not polished examples):
1) Use transform with arguments and ignore the current position:
Code: Select all
transform t_t(duration = 1.0, x_pos = 0, y_pos = 0):
linear duration xpos x_pos ypos y_pos
Based on user input or other things you can apply some new position
Code: Select all
renpy.show_layer_at([t_t(5.0, 500, 500)], reset=False, camera=True)
cons: the moving speed depends on "current position" which can be a problem
2) Use transform with function:
Code: Select all
transform dyn_t:
function dynamic_transform
(or pass this function to Transform)
Code: Select all
default t_xpos = 500
default t_ypos = 500
default t_speed = 100.0
default t_old_st = 0
init python:
def dynamic_transform(trans, st, at):
global t_xpos, t_ypos, t_old_st, t_speed
xpos, ypos = trans.pos
if xpos == None:
xpos = 0
if ypos == None:
ypos = 0
if xpos != t_xpos or ypos != t_ypos:
if st > t_old_st:
dt = st - t_old_st
else:
t_old_st = st
# Using dt, t_xpos, t_ypos, t_speed you can calculate new pos
...
trans.pos = absolute(xpos), absolute(ypos)
return 0
Based on user input or other things you can apply some new position
Code: Select all
def new_position(xpos, ypos):
global t_xpos, t_ypos
t_xpos, t_ypos = xpos, ypos
cons: You need to manually do the transform function
3) Workaround using transform with function to track current properties
Code: Select all
default transform_properties = {"xpos": 0, "ypos": 0, "duration": 1.0}
transform t_properties:
function get_transform_properties
init python:
def get_transform_properties(trans, st, at):
global transform_properties
xpos, ypos = trans.pos
if xpos == None:
xpos = 0
if ypos == None:
ypos = 0
transform_properties["xpos"] = xpos
transform_properties["ypos"] = ypos
return 0.1
Code: Select all
init python:
def new_transform_properties(xpos = 0, ypos = 0):
global transform_properties
old_xpos = transform_properties["xpos"]
old_ypos = transform_properties["ypos"]
if xpos != old_xpos or ypos != old_ypos:
distance = math.hypot(old_xpos - xpos, old_ypos - ypos)
transform_properties["duration"] = distance/t_speed
transform_properties["xpos"] = xpos
transform_properties["ypos"] = ypos
def adjust_transform(xpos = 0, ypos = 0):
new_transform_properties(xpos, ypos)
renpy.show_layer_at([t_properties, t_t(transform_properties["duration"],
transform_properties["xpos"], transform_properties["ypos"])
], reset=False, camera=True)
You need initially to apply transform `t_properties` to track current properties
then you can use adjust_transform to apply new position knowing current properties.
cons: you need to apply additional transform `t_properties` to track current properties.