Rotating using Transform()

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
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Rotating using Transform()

#1 Post by ChroniclerOfLegends »

Hello, I am trying to rotate an image on screen that is part of a creator defined displayable.
I just want a very simple rotation, for a fairly square shaped image to rotate about it's center.

How I have it set up so far is that the displayable has a function for rotating:

Code: Select all

def rotate(self, deg):
                #Transform the image
                xcenter = (self.dimensions[0]/2)
                ycenter = (self.dimensions[1]/2)
                self.image = Transform(child=self.image, anchor=(xcenter,ycenter), rotate=deg, subpixel=False)
This should take the displayables current image, rotate it by an amount and set it as the new image.

This is called during the displayables update().

When I run the test, the displayable is definitely rotating, but it seems to be rotating around some arbitrary point off screen.
I only see it for a moment before it very quickly moves in a curved path off of the screen.
I have tried changing the anchor, and defining it in relationship to the top left of the displayable, and to the top left of the game screen, neither work.
I also tried setting the 'around' property, but it still gives me the same result.

Also to note, In case it affects things. The image that I want to rotate is in constant motion on the screen so its x,y position is changing.
I am trying to create the effect that an object is moving in a straight line and spinning.
I am using a creator defined displayable and not ATL or the sprite manager because the displayable actually does quite a bit more. (collision detection, etc.)

User avatar
trooper6
Lemma-Class Veteran
Posts: 3712
Joined: Sat Jul 09, 2011 10:33 pm
Projects: A Close Shave
Location: Medford, MA
Contact:

Re: Rotating using Transform()

#2 Post by trooper6 »

You may want to look at my Clock Code in the cookbook. There is a link to it in my signature.
A Close Shave:
*Last Thing Done (Aug 17): Finished coding emotions and camera for 4/10 main labels.
*Currently Doing: Coding of emotions and camera for the labels--On 5/10
*First Next thing to do: Code in all CG and special animation stuff
*Next Next thing to do: Set up film animation
*Other Thing to Do: Do SFX and Score (maybe think about eye blinks?)
Check out My Clock Cookbook Recipe: http://lemmasoft.renai.us/forums/viewto ... 51&t=21978

User avatar
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Re: Rotating using Transform()

#3 Post by ChroniclerOfLegends »

That is actually where I got the idea of where to do it from.

Relevent section (in render()):

Code: Select all

# Create transform to rotate the second hand
                tM = Transform(child=self.minute_hand_image, rotate=self.seconds*0.1, 
                    subpixel=True)
                tH = Transform(child=self.hour_hand_image, rotate=self.seconds*0.008333, 
                    subpixel=True)

                # Create a render for the children.
                base_render = renpy.render(self.base_image, width, height, st, at)
                minute_render = renpy.render(tM, width, height, st, at)
                hour_render = renpy.render(tH, width, height, st, at)
But how did you get it to rotate around a fixed point correctly?

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: Rotating using Transform()

#4 Post by Saltome »

You are misunderstanding the rotation property. To create movement you need to apply the rotation continuously.

Code: Select all

init python:
    class test_displayable(renpy.Displayable):
        def __init__(self, child):
            super(test_displayable, self).__init__()
            self.child = renpy.displayable(child)
        def render(self, w, h, st, at):
            t = Transform(renpy.displayable(self.child), rotate = 30*at)
            r = renpy.render(t, w, h, st, at)
            renpy.redraw(self,0)
            return r
screen test_screen:
    add test_displayable("image.png")
label start:
    "start"
    show screen test_screen
    "end"
    
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

User avatar
ChroniclerOfLegends
Regular
Posts: 53
Joined: Thu Feb 16, 2017 5:57 pm
Projects: Scifi Non-Linear Visual Novel/Arcade/Adventure game. (No name yet)
Contact:

Re: Rotating using Transform()

#5 Post by ChroniclerOfLegends »

Thank you very much, this last bit helped me out a lot.

Post Reply

Who is online

Users browsing this forum: No registered users