Possible to rotate images without changing anchor values?

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
Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Possible to rotate images without changing anchor values?

#1 Post by Graph »

Asking this because I've been using custom anchor points for each sprite to figure out where the center of mass is (for example the torso of a body, so not necessarily "0.5, 0.5"). It's used for projectile and weapon targeting. For example:

Code: Select all

image fairy par neutral:
        "fairy_par_neutral.png"
        anchor (239/569.0, 243/424.0)
So, whenever I try to rotate one of these, like with

Code: Select all

rotate -30.0
It jerks a little bit up and left because the anchor resets to (0.5, 0.5). Is there a way to prevent that? (Other than padding all the images with more empty space, because that'll make the load times intolerable in many cases)

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Possible to rotate images without changing anchor values

#2 Post by Levrex »

rotate_pad True
(add it before rotating)
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#3 Post by Graph »

Hmm, I don't seem to see much of a difference whether or not I use the rotate_pad. I tried these:

Code: Select all

transform enemy1_fall:
        easeout 3.5 pos (1000, 900) rotate_pad True rotate -30

Code: Select all

transform enemy1_fall:
        easeout 3.5 pos (1000, 900) rotate_pad False rotate -30

Code: Select all

transform enemy1_fall:
        easeout 3.5 pos (1000, 900) rotate -30 rotate_pad True

Code: Select all

transform enemy1_fall:
        easeout 3.5 pos (1000, 900) rotate -30 rotate_pad False
I still see the sprite jump up a little before it starts to rotate. I'd also be fine with being able to rotate around the custom anchor point if that's an option (one that's not (0.5, 0.5)).

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Possible to rotate images without changing anchor values

#4 Post by Levrex »

Yeah, i get your point now...
Well, i tried pretty much everything, including RotoZoom and etcetera, but none seems to fix nor the "jerking" neither "anchor" part.
Search shows there were some posts about this problem, which are left unanswered.

But, if you're interested, the test sprite was jumping in one of the many directions with each change - when i'd set "xanchor" together with "rotate" part. Maybe you would figure out how to make the "jump" non-visible by setting instant xpos before rotating the sprite or whatever. I tried that, had no effect whatsoever.

I wonder, when the next chapter of Touhou Mecha is out...
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#5 Post by Graph »

Levrex wrote:But, if you're interested, the test sprite was jumping in one of the many directions with each change - when i'd set "xanchor" together with "rotate" part. Maybe you would figure out how to make the "jump" non-visible by setting instant xpos before rotating the sprite or whatever.
It should be possible, but it's more trouble than I'd like since the pos adjustment will be different for each sprite. I should be able to get something that looks good without it though, so that's fine.

I'm curious now though. Is there a way to adjust the value of pos relative to the current value? Like say you want to move something horizontally 200 pixels:

Code: Select all

linear (current_xpos + 200)

User avatar
Alex
Lemma-Class Veteran
Posts: 3094
Joined: Fri Dec 11, 2009 5:25 pm
Contact:

Re: Possible to rotate images without changing anchor values

#6 Post by Alex »

Graph wrote:I'm curious now though. Is there a way to adjust the value of pos relative to the current value? Like say you want to move something horizontally 200 pixels:

Code: Select all

linear (current_xpos + 200)
You need xoffset(http://www.renpy.org/doc/html/style.htm ... properties)

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#7 Post by Graph »

So fast! Thank you both for your replies.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Possible to rotate images without changing anchor values

#8 Post by PyTom »

I'll also note xaround and yaround, which define the point rotation occurs around.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Possible to rotate images without changing anchor values

#9 Post by Levrex »

^ I actually tried setting them, but with no effect...
I.e. it still rotates the sprite around its center, and still changes the position of the sprite.
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#10 Post by Graph »

Also tried xaround and yaround. I didn't notice a change, but interestingly there was no error message when I launched my project either.

I didn't see it in the documentation. Does it go like this?

Code: Select all

show something at somewhere:
        rotate 0
        linear 5 rotate 360 xaround 0.25 yaround 0.25

Levrex
Veteran
Posts: 280
Joined: Mon Jun 18, 2012 12:16 pm
Contact:

Re: Possible to rotate images without changing anchor values

#11 Post by Levrex »

Yeah, like so.
It's the same as "around", but divided by axis, so no need for brackets.
If your question is solved, please add [Solved] to theme's name by editing its first post, so that the helpful guys out there wouldn't mistakenly think the problem is still unanswered and waste their time.

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#12 Post by Graph »

So 9 months later, I noticed that Ren'py 6.15 has added something called transform_anchor, which seems to be for the very purpose I've described here. Looks nice, but I'm not sure when and where to set the value? I tried setting it in the image definition, but I get an error when I try to display it:

Code: Select all

image lowerleft anchored line:
        "line.png"
        anchor (0.01, 1.0) transform_anchor 1

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Possible to rotate images without changing anchor values

#13 Post by PyTom »

What's the error?
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#14 Post by Graph »

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/story/Chapter-2-6.rpy", line 93, in script
AttributeError: 'ATLTransform' object has no attribute 'child_size'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\execution.py", line 288, in run
    node.execute()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\ast.py", line 963, in execute
    show_imspec(self.imspec, atl=getattr(self, "atl", None))
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\ast.py", line 937, in show_imspec
    atl=atl)
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\exports.py", line 325, in show
    sls.add(layer, img, key, zorder, behind, at_list=at_list, name=name, atl=atl, default_transform=renpy.config.default_transform, transient=transient)
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\core.py", line 725, in add
    thing._show()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\motion.py", line 846, in _show
    super(ATLTransform, self)._show()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\motion.py", line 833, in _show
    self.update_state()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\motion.py", line 710, in update_state
    pos = child.get_placement()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\image.py", line 171, in get_placement
    return self.target.get_placement()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\motion.py", line 775, in get_placement
    self.update_state()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\motion.py", line 710, in update_state
    pos = child.get_placement()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\image.py", line 171, in get_placement
    return self.target.get_placement()
  File "C:\Users\Danny\Documents\Dan's Art\renpy-6.14.1-sdk\renpy\display\motion.py", line 793, in get_placement
    cw, ch = self.child_size
AttributeError: 'ATLTransform' object has no attribute 'child_size'

Windows-7-6.1.7601-SP1
Ren'Py 6.15.5.354
Touhou Mecha 1.5
(The folder name is 6.14, but you can see at the bottom that the version is up to date.)

I used the image in an animation like this:

Code: Select all

image antiair fire long:
        block:
            "lowerleft anchored line"
            pause 0.1
            "lowerleft anchored line2"
            pause 0.1
            repeat 20

Code: Select all

show antiair fire long as aa1:
        pos(0.0, 1.0)

Graph
Veteran
Posts: 230
Joined: Sat Jul 03, 2010 7:22 pm
Completed: Touhou Mecha Chap. 1
Projects: Touhou Mecha, Eastern Starlight Romance
Organization: Dai-Sukima Dan
Contact:

Re: Possible to rotate images without changing anchor values

#15 Post by Graph »

Most likely, I just have no idea how to properly use the bool value. I've tried putting

Code: Select all

$transform_anchor = True
Both in main.rpy under an init block, and also in the script right before the ATL I posted previously. But in both cases there's no change, and rotation happens around the center of the image as usual. Did I miss something?

Post Reply

Who is online

Users browsing this forum: Google [Bot]