Hi team,
We are really stuck on how to animate a bunny sprite coming out of a hole - like whack a mole but the bunny is animated. I will upload the code we have already here.
Thanks so much in advance from a newbie.
Sarah
WhackAMole.aia (1.7 MB)
This should get you started, but there is more work to do in sizing the other images
WhackABunny.aia (244.0 KB)
First, let's look at some problems in the code.
Global holelist is supposed to be a list of hole component blocks.
Instead, it is a list of pieces of text.

Components can be found at the end of the block pallette for that component. They are usually green, not red.
Procedure MoveRabbit sets a local variable to a random item from global holelist.
But then it ignores that, and instead uses a number (global hole) where it should be using a Sprite component.

The app is using global animation as a counter

in the animation timer clock.
But a number alone is not a picture

Here's a rewrite with generic blocks, a dictionary of hole sprites, and lists of Picture animations to be applied to holes under different circumstances.
Unfortunately, the picture files are different pixel sizes, so the hammer looks tiny compared to the rabbits and holes.
I leave that to you to fix.

I built the blocks on top of the @TIMAI2 aia, with his corrections to your hole list.
WhackABunny (1).aia (242.7 KB)
By using the holes as the center of all animation, I was able to ignore the bunny sprite altogether.
The dictionary of sprite animation sequences allowed me to up the number of animated bunnies on the Canvas, as is appropriate for bunnies.
Extracting the assets folder of the exported aia, I see
The dimensions of the holes and other frames don't match.
Time to call in an image editor program.
Using IrfanView, I cropped and resized the hammer-related images to the same pixel sizes as the other images, 149 x 151.

I didn't take into account the effect of the hammer on total image size, so the hole shrunk when the hammer appeared. But like the musicians say, it's good enough for jazz.
WhackABunny2.aia (137.4 KB)
Here's an explanation of how the app works, for future reference.
Important data structures:
This dictionary is going to hold the animations for the six holes. It starts out empty.
This will hold a list of the hole sprite components. It could have been prefilled. (shrug)
This event runs at app startup.
It fills in the hole list, and starts Clock1.
The work in the Clock1 Timer event needs a moment after startup for the Canvas to display and receive its Height and Width values from Screen1. Without that Clock Timer, the Canvas would look distorted.
The Clock1 Timer event:
This runs only once, so it disables itself immediately.
It lays out all the hole sprites in their proper locations, relative to the size of the Canvas.
(credits to @TimAI2 for the layout code)
Then it starts the other Clock, AnimClock, which controls animations.
AnimClock runs faster, and repeats indefinitely.
Animation sequences:
Popping up a rabbit:
Smashing a popped up rabbit with a hammer:
Missing a rabbit, and hitting an empty hole:
Hammer action:
This is a generic event, so it applies to all Sprites, unless told otherwise (not Already Handled.)
The Picture of the touched hole sprite guides us in how to react. If it one of the two rabbit popup picture files, then we load that Sprite's animation in the animation dictionary from a copy of the animations list of the rabbit being smashed by a hammer.
Otherwise, we load up that hole's animation list with a picture of the hammer hitting an empty hole.
Notice how each of the three animation lists ends in an image of an empty hole. No bloody guts or dead bodies are left behind. (We have a good crime scene cleanup squad.)
The Animation Clock Timer:
This Clock Timer works off the dictionary in global variable hole_animations_dictionary.
I added the variable type (dictionary) in the variable name to remind me every time I use the variable that it's a dictionary, and I should only use dark blue dictionary blocks on it.
The tags (keys) of the dictionary are my hole Sprite components. The matching values are dynamic lists of pictures remaining to be shown for that sprite.
We loop through all the tags (components) and values (picture lists) of the dictionary.
If a list of animations is empty, it should be removed along with its parent Sprite from the dictionary.
Otherwise, we take the first picture in the animation list and load it into the Sprite, then remove it from the list. These lists are temporary copies of the master lists of animations, otherwise we would be struck with immediate amnesia.
After removing the first picture from the component's animation list, we replace the picture list back into the animation dictionary under that component, for the next time the Timer triggers.
After all the animations have run in the animations dictionary, it's time to replenish our supply of rabbits. The animation dictionary's list of keys gets shorter and shorter as each animated sprite runs out of animations and gets removed from the dictionary. So we use the count (length of list of the dictionary keys) as our cue to pick a hole and get it started with a rabbit popup.
After picking a random hole sprite, we test if its picture is an empty hole. If true, it's fair game, and we load it up with a rabbit popup sequence. Otherwise, we abandon our rabbit replenishment for this clock timer cycle, leaving time for our rabbits to do their business underground.
Thank you so much everyone, we are unpacking all of your wonderful responses now. It is much appreciated.










