How to create my own behavior?

Since events are scene specific, to achieve object-oriented game programming I need to create my own behaviors. How can I achieve that?

What do you mean? :confused: Can you give an example?

Maybe I couldn’t express myself because of lack of experience with Gdevelop and because of my English.

For example there is a behavior for running and jumping, it is easy to implement it to any actor. Say I have run,jump shoot and do backflip behavior. How can I create a behavior for it like the default ones and implement it from add behavior menu?

Edit: It is actually all about that I see events are only for scenes. It true that you can control the character through the scene but for multiple level games, I want events scene independent and attached only to character which is way the behaviors works. This way it will be easy to create new scenes and scene behaviors will be less complicated.

Behaviors are coded in C++ for native games and JS in HTML5 games : they are not intented to be coded by GDevelop’s users in fact.
However, you can use objects’ groups so that you can apply your events to multiple objects. For example, a “Backflippable” group containing actors that can do a backflip with events using the group to make the backflip work.

this is a great question and I’m actually in the same situation. If the work out procedure could be provided in a step by step process, that would be very much appreciated . I have the sprites set up in the Player’s object in the animation #3 Left mouse button was released Do =3 to the number of current animation of Player https://image.ibb.co/hOKHLQ/GD.png
[imghttps://image.ibb.co/hOKHLQ/GD.png[/img]
but when i run the preview noting happened , Am I missing something? of should I do it another way? :open_mouth: :confused:

I think this may be a case of the animation being changed to a different one before you have chance to see it. Remember that with the game loop going around 60 times per second, events 5,6 and 7 will be processed 1/60th of a second after you release the mouse button and if any of their conditions are true then you’ll never see animation 3.

You could check if this is what is happening by temporarily adding an extra condition to events 5,6,7 - something like:

The number of the current animation of Player <3

You could get the same effect by putting events 5,6,7 as sub-events of a new event that does this check.

Do you want animation 3 to be a permanent change in appearance of the object, or just last for a few seconds?

Well animation 3 would be for when the character is firing, and when I used your code what happened is that it only played the first frame of the animation

OK, so not a permanent change of appearance.

Do you want the player to be able to shoot when jumping, falling and running or just when standing still? If you want them to be able to shoot in all those conditions, you’ll need to add more animations so that jump+shoot, fall+shoot and run+shoot to look different to the normal ones.

However many shooting animations you want, you are always going to need to add in a delay manually, because “player is shooting” is not one of the built-in states.

I’ve had a play and this works:


All it does is start a timer when the shooting animation is selected and add extra conditions to the normal movement states so that they only change back to the normal sprite if 1 second has passed.
You will need to add animations 3,4 and 5 to the player object, where 3 is the same as 0 (but shooting), 4 is the same as 1 (but shooting) and 5 is the same as 2 (but shooting). By having every shooting animation be 3 bigger than the non-shooting version, the correct one can be picked automatically.

1 Like