Performance issue with CDD particles

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
TheMarmosetKing
Newbie
Posts: 4
Joined: Thu Dec 20, 2018 1:06 am
Contact:

Performance issue with CDD particles

#1 Post by TheMarmosetKing »

I am working on a rhythm-based minigame. I am trying to add a starburst/fireworks effect on hit. I have poked around and found quite a few examples to use for reference. Some used pygame, some used creator defined displayables, some used other approaches.

Many of the forum elders promoted using creator defined displayables with ATL, so that is what I have tried to do. After much wailing and gnashing of teeth, I have created a decent looking particle burst.

However, when I put it into the minigame it introduces a delay every time it is generated. I'm sure that there are a whole host of reasons why this might be, but I'd like to start by getting some feedback on the displayable and transform that I'm using, because I'm certain that I still don't really understand creator defined displayables.

Code: Select all

transform particleTransform(d, speed, endX, endY):
    d
    subpixel True
    parallel:
        linear speed xpos endX ypos endY
    parallel:
        linear speed alpha 0

init python:
    import math
    import random

    class particle(renpy.Displayable):
        def __init__(self, xPos, yPos, **kwargs):
            renpy.Displayable.__init__(self, **kwargs)
            self.xPos = xPos
            self.yPos = yPos
            self.speed = random.random()
            self.endX = random.randint(-200, 200)
            self.endY = random.randint(-200, 200)
            randomValueForColor = lambda: random.randint(0,255)
            self.color = '#%02X%02X%02X' % (randomValueForColor(),randomValueForColor(),randomValueForColor())

        def render(self, width, height, st, at):
            render = renpy.Render(width, height)
            canvas = render.canvas()
            canvas.circle(self.color, (self.xPos, self.yPos), 2)
            return render

    class particleBurst(renpy.Displayable):
        def __init__(self, xPos, yPos, **kwargs):
            renpy.Displayable.__init__(self, **kwargs)
            self.particles = []
            self.xPos = xPos
            self.yPos = yPos
            for i in range(0, 50):
                thing = particle(self.xPos, self.yPos)
                self.particles.append(particleTransform(thing, thing.speed, thing.endX, thing.endY))

        def render(self, width, height, st, at):
            renderForReturn = renpy.Render(width, height) 
            for thing in self.particles:
                renderForReturn.place(thing)
            return renderForReturn

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: Performance issue with CDD particles

#2 Post by PyTom »

Consider using SpriteManager, which speeds thigns up when you have tons and tons of particles. I'd also avoid ATL here, since SpriteManager should be able to do all of the same things.
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

TheMarmosetKing
Newbie
Posts: 4
Joined: Thu Dec 20, 2018 1:06 am
Contact:

Re: Performance issue with CDD particles

#3 Post by TheMarmosetKing »

Thank you for the advice. I will give SpriteManager another shot. But can you perhaps clarify one more thing? I've seen other posts where a person was using SpriteManager, but the suggested solution was to use CDD/ATL. Is there a set of high level rules or considerations that would help a person pick the right approach?

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: Performance issue with CDD particles

#4 Post by PyTom »

SpriteManager is used for something where you have tons of basically identical particles. ATL is for everything else.
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

TheMarmosetKing
Newbie
Posts: 4
Joined: Thu Dec 20, 2018 1:06 am
Contact:

Re: Performance issue with CDD particles

#5 Post by TheMarmosetKing »

That makes sense. Thanks again!

TheMarmosetKing
Newbie
Posts: 4
Joined: Thu Dec 20, 2018 1:06 am
Contact:

Re: Performance issue with CDD particles

#6 Post by TheMarmosetKing »

Holidays, amiright? Anyway, thanks for your guidance. I was able to create a pretty nice looking starburst. :)

Post Reply

Who is online

Users browsing this forum: Google [Bot]