How to make animation change after each click on a sprite

Hello, so I would like to know how I could make a sprite change to its next animation when left clicked on it every time. How would I go about doing this? I only got it to where when I left click the sprite it changes the animation and then I try to click it again and the animation doesn’t change. I also would like to be able to have a button that resets the animation back to the first animation frame. As well as the left click each time click to the sprite and it changing to the next frame.

I really don’t know how I could do all of this. Maybe some variables, and the animation action as well?

One other thing, could I make it so each time the sprite is clicked and when its animation changes it can add 10 points or something to a score?

All help is appreciated, thank you for taking the time to read this. :slight_smile:

What I wold do is to store animation frames in separated animations and use an object variable to store animation number, and every time I click on the object, add +1 to object variable and change object animation using the variable.

For example

To change animation

at the beginning of the scene : Do =0 to object.Variable(animation)
if mouse is over object and left mouse button is pressed : change object animation to object.Variable(animation) and Do +1 to object.Variable(animation)

To reset animation do something like this

if mouse is over reset button and left mouse button is pressed : Do =0 to object.Variable(animation) and change object animation to object.Variable(animation)

To add score, simply use a variable to store score and add +10 or any number to score variable every time you click on an object, like so

at the beginning of the scene : Do =0 to Variable(score)
if mouse is over object and left mouse button is pressed : Do +10 to Variable(score)

Just made an example for you, you can download it from here:
drive.google.com/file/d/0B1sXiY … sp=sharing

Thank you! This is exactly what I was wanting. :slight_smile:

It also really does help when you make a project file for it, I’m sure it also helps out others as well who may want to do something like this.

One other thing, is it possible to make a sprite with a transparent background and have it be clicked and work as the animation change project you sent me? I seemed to not be able to get it to work, but this would be awesome if there was a way to do this.

I am also trying to figure out how to make a inventory/selection menu where you can choose from different options. Each option has its own set of animations that change when you click the first just like the animation change project you sent me. The thing is that I want to be able to click with the default/first button/animation changer and have the others add their sprites over it and possibly showing both clearly. This is why I want to make them have transparent background so I can click in that area and then it changes the animation. So how would I go about doing something like this? I’m not sure, and I’m rather new to Game Develop, I hope it’s possible.

Again, thanks for the help. :slight_smile:

Ok, well the score seems to not be working, I tried doing as you said. But it seemed to not work for me, could you please help me out and add it into the example you sent me?

I am also trying to display the score as a text, I called it ScoreText, just like in the Platformer Tutorial I believe.

To make a score, just create a variable to store score, and add +10 to score variable on every mouse click. To write score on the
screen, create a text object, drop it on the screen, and modify the text of the text object with the actual value of the score variable like so:

"Score: "+ToString(Variable(score))

If it doesn’t work for you, maybe there is a misspelling in the object or variable name or something missing, maybe a bracket…

I have updated my example, you have also a score now, that updates with +10 on every mouse click.

To make a sprite or animation transparent or to make a transparent background the best way in my opinion is to use a Photo editing software to make it transparent and use that in GD.
For example Gimp is perfect for the job and free:
gimp.org/

To make an inventory or selection menu visual part, there are several ways to do it. You already should know how to change animations of sprite objects, so you can play with that if it what you need.
If you want to change position of actual sprite object inside the menu, inventory, you can do so easily.
To change position of sprite object, you can find the necessary events under : All objects\Position category.
You can also drag 'n drop objects, the easiest way is to use Draggable object automatism
You can also move sprite objects if you want. To move sprites, you can find the necessary events under All objects\Displacement category
To create sprite object in the scene in a specified position, you can do so by using the All objects\Objects\Create an object event To specify the position, you can use the actual X,Y position of any object like so: object.X(), object.Y() or you can simply enter numbers if you know the exact position in pixels.
You can also choose the objects are in front of or behind an other object by changing it Z order using All objects\Z order\Change Z order of an object event. If you want an object to be in front of an other, change it Z order higher.

Thank you for the information, I got my score working now by what you said, and thank you for making the change to your example. :slight_smile:

Also, would you like me to credit you in my game in the credits section because you have helped me out quite a bit?

No it is not necessary.
I’m glad If It helps. I help with anything I can :slight_smile:

1 Like

Oh ok, I have another question.

Can a hidden sprite with a transparent background be clicked anywhere on the sprite including the transparent (no pixels) part and then the sprite be shown when clicking on it? I want it to look like there is just the pixel part and to not have to have a background for the sprite but still being able to click it and making it pop up. Will this work? Because I have tried it and it hasn’t really worked for me.

The condition “The cursor is on Object” has an option “Precise test (yes by default)”:
Set Precise test = no, then the entire rectangle over the sprite will be tested in the condition :slight_smile:

Thank you! You have saved me so much time, and I’ve been trying to figure it out for quite some time now. :slight_smile:

So, I have another question, it is about particles.

How could I have some dark gray particles appear and fall from a sprite that I click?

I can help you, but only a bit.

You need a Particles Object (I don’t know if this feature is available for web platform games).
Then, when you click on the object A, you should create the Particles Object over the object A, wait some time and delete the Particles.

The problem is that you have to set the particles properly, It has a lot of options and take a lot of parameters (time between particles, life time 1, life time 2, initial color, final color, angle, force, dispersion, etc., etc., etc.) :neutral_face: