Random Animations - Avoiding Repeated Sprites

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
crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Random Animations - Avoiding Repeated Sprites

#1 Post by crimsonnight » Thu May 12, 2016 10:50 pm

Hey guys,

I currently have a standard randomised animation set up as such:

Code: Select all

image CaveWallLeft:
    choice:
        "images/Cave_left1.png"
    choice:
        "images/Cave_left2.png"
    choice:
        "images/Cave_left3.png"
    pause 1.0 # Time interval
    repeat
How can I avoid it choosing the same sprite twice in a row?

I also have a second, related question. How can I combine multiple random animations into a single 'image' label?

Thanks!
alwaysthesamebluesky.com

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#2 Post by xela » Fri May 13, 2016 1:55 am

crimsonnight wrote:How can I avoid it choosing the same sprite twice in a row?
Not sure that you can do it this way. Best I can remember each of the choice statements is evaluated once and then Ren'Py just runs with it for the lifetime of the transform instance, I could be wrong about this one thought.
crimsonnight wrote:I also have a second, related question. How can I combine multiple random animations into a single 'image' label?
contains ATL statement might be what you're looking for.
Like what we're doing? Support us at:
Image

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#3 Post by Onishion » Fri May 13, 2016 11:24 pm

Not sure that you can do it this way. Best I can remember each of the choice statements is evaluated once and then Ren'Py just runs with it for the lifetime of the transform instance, I could be wrong about this one thought.
Actually, in the code written above, it would pick a different one each time it repeats, but it could go like 1,2,3,2,2,2,3,1,1, etc., odds are there would be repetitions, and I'm not sure there's any way to prevent that.

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#4 Post by crimsonnight » Fri May 13, 2016 11:33 pm

Damn, it's important I get this sorted, is there no more advanced branches of the 'choice' command? I suppose if not I could just show the images in a set order, but it would be a shame to loose the random aspect of it.
alwaysthesamebluesky.com

Onishion
Veteran
Posts: 295
Joined: Mon Apr 20, 2015 10:36 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#5 Post by Onishion » Sat May 14, 2016 3:27 am

Well, if you think about it, if you're only using three options, the combinations that would not result in duplication are relatively few anyway. If making absolutely sure that there are no duplications is the priority, then just having a set pattern would be the way to go.

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#6 Post by crimsonnight » Sat May 14, 2016 3:33 am

I don't want any of the parts of the image to display twice in a row as I'm trying to create the illusion of movement. You're probably right though - do you have a link to an article about setting up ATL-block long animations?
alwaysthesamebluesky.com

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#7 Post by xela » Sat May 14, 2016 4:54 am

Onishion wrote:Actually, in the code written above, it would pick a different one each time it repeats, but it could go like 1,2,3,2,2,2,3,1,1, etc., odds are there would be repetitions, and I'm not sure there's any way to prevent that.
There sure as hell a way to prevent that in general, ATL at it's present state doesn't come to mind as a first choice, at least to mind :D
Like what we're doing? Support us at:
Image

User avatar
xela
Lemma-Class Veteran
Posts: 2481
Joined: Sun Sep 18, 2011 10:13 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#8 Post by xela » Sat May 14, 2016 5:03 am

crimsonnight wrote:I don't want any of the parts of the image to display twice in a row as I'm trying to create the illusion of movement. You're probably right though - do you have a link to an article about setting up ATL-block long animations?
First thing that pops to mind is a DD... simpler than UDD (kind of a "wrapper" to simplify the class). Seems like a perfect job for it... you should be able to get your randomization and timings straight almost effortlessly (look into Python's random module and play around with DD a bit).
Like what we're doing? Support us at:
Image

crimsonnight
Veteran
Posts: 298
Joined: Fri Apr 20, 2012 4:44 am
Contact:

Re: Random Animations - Avoiding Repeated Sprites

#9 Post by crimsonnight » Fri Jun 10, 2016 5:39 am

Biomass on the IRC found a solution which seems to be working well:

Code: Select all

define e = Character('Eileen', color="#c8ffc8")
 
image image0 = "image0.jpg"
image image1 = "image1.png"
image image2 = "image0.jpg"
 
init python:
    image_list = ["image0", "image1", "image2"]
    prev_image = None
    def show_stuff(st, at):
        global prev_image
        global counter        
        next_image = prev_image
        # keep selecting image until it isn't a duplicate
        while next_image == prev_image:
            next_image = renpy.random.choice(image_list)
        prev_image = next_image
        return (next_image, 0.2)
       
image my_dyn_displayable = DynamicDisplayable(show_stuff)
 
label start:    
    show my_dyn_displayable
    e "hi"
    jump start
    return
alwaysthesamebluesky.com

Post Reply

Who is online

Users browsing this forum: Alex, Google [Bot], nyeowmi