I am creating a CDD that displays multiple projectiles flying towards the screen in sequence. Each projectile should spin and grow larger over time to imitate a first-person perspective of having something thrown at you. I've provided the code I've written so far at the bottom of this post.
However, I have an issue where instead of the projectiles zooming and rotating in place, they all fly off towards the bottom-right corner of the screen. I assume this is due to the anchor point of the children being set to (0, 0) rather than (0.5, 0.5). I attempted to change this in the Transform properties with no result.
There is also an issue where newly drawn projectiles will be drawn on top of older projectiles, which doesn't make sense visually as newer projectiles should be further away from the player, hidden behind closer incoming projectiles.
My questions are:
1. How can I set the anchor points of the CDD's children? Will this anchor point be affected by the actively changing zoom and rotation transformations?
2. How can I make it so that the oldest child displayed will always be the drawn closest to the player?
Any other feedback is also welcome.
Thank you for your help in advance.
Code: Select all
init python:
fireball = renpy.image("fireball", "fireball.png")
init python:
class Projectile(object):
def __init__(self, projectileImage, projectileAppearanceTime, projectileZoom, projectileRotation, projectileXpos, projectileYpos):
self.projectileImage = projectileImage
self.projectileAppearanceTime = projectileAppearanceTime
self.projectileZoom = projectileZoom
self.projectileRotation = projectileRotation
self.projectileXpos = projectileXpos
self.projectileYpos = projectileYpos
class MagicBattle(renpy.Displayable):
def __init__(self, fullProjectileList, **kwargs):
super(MagicBattle, self).__init__(**kwargs)
# List of projectile objects that will be used to control projectile appearance
self.fullProjectileList = fullProjectileList
# Processes active projectiles and draws the screen
def render(self, width, height, st, at):
# The main render object that will be drawn into
renderWindow = renpy.Render(width, height)
# Loop that will be handling drawing of multiple projectiles at once by looking through the projectile list
for projectile in self.fullProjectileList:
if projectile.projectileAppearanceTime <= st:
# Creating the zoom and rotate transform to be applied to the projectile image
projectileTransform = Transform(child=projectile.projectileImage, anchor=(0.5, 0.5), zoom=projectile.projectileZoom, rotate=projectile.projectileRotation)
# Create a render of the projectile image using the transform above
projectileRender = renpy.render(projectileTransform, width, height, st, at)
# Draw the render above into the main render window
renderWindow.blit(projectileRender, (projectile.projectileXpos, projectile.projectileYpos))
# Change rotation and zoom of the projectile for the next render frame to emulate an incoming projectile
projectile.projectileRotation -= 30
projectile.projectileZoom += 0.05
renpy.redraw(self, 0)
return renderWindow
# Create a list of projectiles to pass into the MagicBattle class for testing
testProjectileList = [
Projectile("fireball", 1.0, 0.2, 0, 0, 0),
Projectile("fireball", 1.2, 0.2, 0, 0, 0),
Projectile("fireball", 1.4, 0.2, 0, 200, 0),
Projectile("fireball", 1.8, 0.2, 0, 400, 0),
Projectile("fireball", 2.0, 0.2, 0, 600, 0),
Projectile("fireball", 2.2, 0.2, 0, 800, 0)
]
screen battle():
default battle = MagicBattle(testProjectileList)
add battle
label start:
"The magic battle test is starting."
window hide
$ quick_menu = False
call screen battle