Animation changing for only 1 instance?

Hi, I decided I wanted to create a city-building game. Whenever the user places down a building it should choose between 3 random animations and change only the last placed building.

However, every time I place a new building, the animation for all currently placed buildings change. I have the animation changing action placed right after the create building Action.

any ideas on why this is happening and how to fix it?

Hey!

You could create a subevent to that event, and have some code like this:

The important thing here to note is Pick the nearest _____ object. This makes sure only the house currently being spawned is affected.

Also quick point, since your house animation values start at zero, you do not need to use RandomInRange and can just use Random like in my example (where I only have 3 animations, hence the 2 instead of your 3). :slight_smile:

Please try this first before using my original solution!

You should have a trigger once like I do in my example (don’t worry about the mouse button event saying released). That might also be the reason it’s not working.

Why might trigger once fix this issue?

Basically, when you press down the mouse button, you are actually doing it for multiple frames, even if you think you are pressing it REALLY fast. So it might be changing the animation of one house, but then since it is still pressed the next frame, it changes the remaining houses. The trigger once only runs the actions once, until the conditions are true once again.

Hi, thanks for the reply.

I tried doing this since I’m using an isometric cursor that snaps to the grid.


And it seems to work. I was just perplexed as to why the initial method did not work. I always changed individual sprite animations in that manner and it always worked fine (since Gdevelop focuses on the sprite in the event and not all of them. [ hence the “Pick all” condition is exists for that reason])

I did not even notice that mistake, LOL. Thank you.