Rotating image from previous point

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
Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Rotating image from previous point

#1 Post by Exiscoming »

So I'd like to run something like this:

Code: Select all

"I'm going to rotate this circle."
show circle:
	xalign 0.7 yalign 0.6
call turnCircle
	
label turnCircle:
	show circle:
		xalign 0.7 yalign 0.6
		linear 0.15 rotate -= 60
	return
This will rotate the circle counter-clockwise by 60.
Now I wish to repeat this, so that instead of -60 it goes to -120, all the way until it has made a full circle.
How would I do that?

M-77
Regular
Posts: 56
Joined: Tue Sep 04, 2018 7:58 am
Contact:

Re: Rotating image from previous point

#2 Post by M-77 »

Hello Exiscoming, what is your circle? A pic or something that Renpy can draw?
I put it this way to rotate a pic (warp001, quadratic, not screen size resolution, and I made the edges black and use a black bg so the outer borders are not to see when it is spinning) of a whirl in clockwise direction. It took me quite a time to find out:

Code: Select all

show warp001 at center:
    zoom 2.0
    xalign 0.5
    yalign 0.5
    xanchor 0.5 yanchor 0.5
    rotate 0
    linear 4.0 rotate 360
    repeat

Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: Rotating image from previous point

#3 Post by Exiscoming »

Hey M-77 thank you for your reply! So I'll give you a bit more detail on what I'm working on.
The turning image is suppose to be the chamber of a revolver.
Image

Everytime I click, I need it to rotate -60 degrees, which means it has to remember what rotation it's on currently and subtract another -60 from that.
Like turning the rotation number into a variable. Something like this:

Code: Select all

default rotationVariable = 0
show uiRevolverChamber:
   xalign 0.976 yalign 1.041
   linear 0.15 rotationVariable - 60
Of course I get an error message when I do it my way. Though perhaps someone could give me some advice.

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Rotating image from previous point

#4 Post by Matalla »

I don't know if that code works, I have very limited experience managing that kind of things and perhaps someone could help you with that... But I see a problem: you declare the variable but never update it, so it will allways be -60.

You'll have to add somethink like this

Code: Select all

default rotationVariable = 0
label rotating_chamber:
	$ rotationVariable -= 60 # this updates the variable
	show uiRevolverChamber:
		xalign 0.976 yalign 1.041
		linear 0.15 rotationVariable

	pause
	jump rotating_chamber

That is, of course, if the show statement is correct, whick I don't know
Comunidad Ren'Py en español (Discord)
Honest Critique

Exiscoming
Regular
Posts: 132
Joined: Tue Apr 29, 2014 5:37 pm
Contact:

Re: Rotating image from previous point

#5 Post by Exiscoming »

Hey Matalla,

Thank you for your reply. That was my original idea aswell, but this gives an error message.

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

Re: Rotating image from previous point

#6 Post by philat »

Code: Select all

default degree = 0

screen test():
    vbox:
        hbox:
            textbutton "<" action SetVariable("degree", degree-60)
            textbutton ">" action SetVariable("degree", degree+60)
        add Solid("#FFF", xysize=(50,50)) at rot(degree)

transform rot(d):
    linear 0.5 rotate d

User avatar
Matalla
Veteran
Posts: 202
Joined: Wed Mar 06, 2019 6:22 pm
Completed: Max Power and the Egyptian Beetle Case, The Candidate, The Last Hope, El cajón del viejo escritorio, Clementina y la luna roja, Caught in Orbit, Dirty Business Ep 0, Medianoche de nuevo, The Lost Smile
itch: matalla-interactive
Location: Spain
Contact:

Re: Rotating image from previous point

#7 Post by Matalla »

Exiscoming wrote: Fri Mar 15, 2019 5:01 am Hey Matalla,

Thank you for your reply. That was my original idea aswell, but this gives an error message.
I think the error could be that the code doesn't tell what to do with the variable, judging by M-77 and philat's example the variable with the value should be preceded by rotate.

Code: Select all

default rotationVariable = 0
label rotating_chamber:
	$ rotationVariable -= 60 # this updates the variable
	show uiRevolverChamber:
		xalign 0.976 yalign 1.041
		linear 0.15 rotate rotationVariable

	pause
	jump rotating_chamber

Anyway, philat's code looks better and should work
Comunidad Ren'Py en español (Discord)
Honest Critique

M-77
Regular
Posts: 56
Joined: Tue Sep 04, 2018 7:58 am
Contact:

Re: Rotating image from previous point

#8 Post by M-77 »

I found something similar while searching for something other, but Phyton, here:
https://www.python-forum.de/viewtopic.php?f=4&t=30420

Code: Select all

#! /python26/python.exe
#! coding: utf-8

"""
Simple demonstration on rotating an Image!
"""

import pygame
from pygame.locals import *

pygame.init()

SCREENSIZE = (640, 640)

screen = pygame.display.set_mode(SCREENSIZE, 0, 32)
pygame.display.set_caption("Angle: 0°")

scrcenter = screen.get_rect().center
print scrcenter
print type(scrcenter)

# Prepare Background and Arrow:
bg = pygame.Surface(SCREENSIZE)
bg.fill((120,120,120))

arrow = pygame.Surface((120,120), SRCALPHA)
pygame.draw.rect(arrow, (255, 0, 0), (0, 0, 120, 120))
# We need an image to rotate:
rotarrow = arrow.copy()
angle = 0

# We define centerpoints for the images/sprites.
CENTER = screen.get_rect().center
ACENTER = arrow.get_rect().center
ABS_CENTER = (CENTER[0] - ACENTER[0], CENTER[1] - ACENTER[1])

# 
keepGoing = True
clock = pygame.time.Clock()

while keepGoing:
    clock.tick(30)
    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            keepGoing = False
            
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                keepGoing = False
            elif event.key == pygame.K_RIGHT:
                angle -=  5
                rotarrow = pygame.transform.rotate(arrow, angle)
                
            elif event.key == pygame.K_LEFT:
                angle += 5
                rotarrow = pygame.transform.rotate(arrow, angle)
    
    # Get centerpoint of current rect
    ROTCENTER = rotarrow.get_rect().center
    ABS_CENTER = (CENTER[0] - ROTCENTER[0], CENTER[1]-ROTCENTER[1])
    
    # display current angle for info:
    pygame.display.set_caption("Angle: " + str(angle) + "°")
    
    screen.blit(bg, (0,0))
    screen.blit(rotarrow, ABS_CENTER)
    pygame.display.flip()
    
Maybe you can ape after this method. Or implement it in Renpy. This rotate a arrow on a clock at %5 + or - angle when the left or right mouse button is hit.

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], MisterPinetree