[Confirmed BUG] imagebutton with animated image(atl) behaves strangely

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
tornsoul
Regular
Posts: 29
Joined: Sat Jun 19, 2021 7:32 pm
Contact:

[Confirmed BUG] imagebutton with animated image(atl) behaves strangely

#1 Post by tornsoul »

I want to achieve that on left-clicking an imagebutton an animation is played (think minesweeper: an explosion on clicking a hidden bomb - and then showing the bomb after)
Likewise you should be able to right-click to change the imagebutton image to a different image (think minesweeper: marking a tile with a flag)

In this example code the animation is simply changing the image to a white box - to keep it simple.

I have the following code (which intuitively ought to work? but...):

Code: Select all

image picr = Fixed(Solid("F00", xysize=(60, 60)), xysize=(64,64))
image picg = Fixed(Solid("0F0", xysize=(60, 60)), xysize=(64,64))
image picb = Fixed(Solid("00F", xysize=(60, 60)), xysize=(64,64))
image picw = Fixed(Solid("FFF", xysize=(60, 60)), xysize=(64,64))

image pic_animate:
    "picr"
    1.0
    "picw"

image pic_animate_wrapper: #pic_animate won't work if used directly for some reason...???
    "pic_animate"

init python:
    pics = ['picr', 'picg', 'picb', 'picw', 'pic_animate_wrapper']
    piclist = [
        [4,1],
        [1,1]
    ]
    dim = [len(piclist[0]), len(piclist)]

    def update_pics(x,y, button):
        global piclist
        if (button == "left"): #left click
            #asd = 1/0 #uncomment to verify that we actaully do get here (game will crash)
            newValue = 4 #the actual value will depend on gamestate - but hardcoded for this example
        else: #right click
            newValue = 2 #the actual value will depend on gamestate - but hardcoded for this example
        piclist[y][x] = newValue

screen test_grid():
    grid dim[0] dim[1]:
        for y, row in enumerate(piclist):
            for x, tile_index in enumerate(row):
                imagebutton:
                    idle pics[tile_index]
                    action Function(update_pics, x, y, "left")
                    alternate Function(update_pics, x, y, "right")

label test_it:
    "Ready to test"
    show screen test_grid
    "Grid should be visible now"
    return
It's a simple 2x2 grid - values determined by a variable (array/list)
First position is set to show the animation on load - rest are neutral.

The initial animation runs just fine.
Right clicking also always works.
1st time left-clicking any "neutral" tiles also always works - ie. the animation will play. (but see 4)

But there's a whole slew of weird things going on elsewise, that I hope someone could explain (and hopefully suggest a solution for)

Weird behaviors observed:

1: Hover the mouse over the first imagebutton and the animation plays again - why???
2: Try to left-click the first imagebutton to active the animation again - Nothing happens - why???
- and this although the code for running the animation (ie switching the image) *is* being run - uncomment the "asd = 1/0" and the game will crash.
3: Right click the first imagebutton (it correctly changes to blue) - So right click works.
Then left-click: *Now* the animation runs fine (image changes to white) - Why didn't left click activate the animation before???
Left-click again - and again the animation does not run.
4: Leftclick one of the neutral/green imagebuttons - The animation plays fine.
If you move the mouse away from the imagebutton before the animation is done playing - it will only play once.
But if you "hover" until the end and then move the mouse away from the image button ("unhover") - the animation plays *again* - Why???
5: Why does one need the "wrapper" for the image animation in the first place for it to run at all???

With so many weird/unexpected things going on, I'm at a loss on how to make this work.

Very much open for suggestions.
Last edited by tornsoul on Tue Jul 13, 2021 1:22 pm, edited 1 time in total.


Post Reply

Who is online

Users browsing this forum: apocolocyntose, DewyNebula