Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
gdevelop5:events:draft-optimization [2020/03/18 00:27] bouh |
gdevelop5:events:draft-optimization [2020/11/04 15:45] bouh [Decativate unused behaviors] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | <note important> | + | <note important> |
- | <note warning> | + | <note warning> |
- | Game optimization is an important concept of making a game. Good optimization will allow the game to work faster, making it more fluid. | + | Game optimization is an important concept of game development. Good optimization will allow the game to work faster, making it more fluid. |
- | GDevelop 5 gives you total freedom in events. While this can be awesome, it can also be very costly if you don't have the reflex of build a good structure in your events, the processor | + | GDevelop 5 gives you total freedom in events. While this can be awesome, it can also be very costly if you don't have the reflex of writing optimized |
- | It is important to [[gdevelop5: | + | It is important to [[gdevelop5: |
- | < | + | < |
====== Optimization already in the engine ====== | ====== Optimization already in the engine ====== | ||
- | The GDevelop | + | GDevelop |
This doesn' | This doesn' | ||
+ | For example, when a sprite is off screen all the animations are paused. | ||
- | < | + | < |
+ | ====== Optimizations you can perform ====== | ||
- | ====== Trigger once ====== | + | ===== Trigger once ===== |
- | The **Tigger | + | The **Trigger |
- | Let's take an example | + | For example, if you want to create an object every time a click is done, this is what you should // |
{{: | {{: | ||
- | * What should | + | * What is expected to happen: When the left mouse button is pressed, an object is created called **MyObject**. |
- | * What actually happens : When the mouse left button is pressed, | + | * What actually happens : As long as the mouse left button is pressed, **MyObject** |
- | This occurs | + | This is problematic |
- | For fix that we need add the condition | + | To fix that we can use the **Trigger once** condition: |
{{: | {{: | ||
+ | Now, the condition will trigger only once while it is true. That means that the event will fire only once every time it's condition goes from unfulfilled to fulfilled. It resolves the problem above as the condition will fire only the first frame of the click, and will wait for the click to end before letting the click event fire again. | ||
+ | ===== Decativate unused behaviors ===== | ||
- | ====== | + | Behaviors |
- | There is multiple behaviors, // | + | Let's take as example the following situation: I want 100 enemies to move to a position close to them every 2 seconds, and to take into account |
- | ==== Delete | + | This would be an intuitive but wrong way to do it: |
+ | {{: | ||
+ | If you do this, all objects will move, including | ||
- | Let's take the example where I have a gun and I create one bullet when i do fire. | + | <note tip>Why calculate movement that the player won' |
- | This bullet have a force toward a direction. | + | |
- | If you shot very often bullets will increase in number on scene and each have a physic. | + | |
- | If you didn' | + | |
- | The good solution is to delete the bullets if there is off screen. | + | |
- | An behavior | + | Instead, you can limit the movement to visible objects. This can be done the following way: disable the Pathfinding |
- | All bullets moving offscreen will be deleted. | + | |
- | ==== Disable | + | <note tip> |
- | Behaviors can be disable. | + | ===== Delete unused objects ===== |
- | This is perfect when you didn't need to affect the instance out of the screen. | + | |
- | Let's take the example | + | Let's take as example |
- | + | I have a gun and I create one bullet object instance when I press the key to fire. | |
- | Bad way is to move the enemies like this : | + | This bullet has a force toward a direction. |
- | {{: | + | If the player shoots many bullets, their amount will increase on the scene and each one requires calculations of the force applied |
- | If you do only this all objects will move, but maybe you don' | + | If you don' |
- | + | The best solution | |
- | <note tip>Why calculate something what we didn't see?</ | + | |
- | + | ||
- | Instead you can move only the object visible (in viewport), there is a simple way: | + | |
- | + | ||
- | - Disable | + | |
- | - And do the invert event, when the objects | + | |
+ | The behavior **" | ||
<note important> | <note important> | ||
- | |||
- | - no more 248px on image | ||
- | - optimize sprite animation, reduce image almost similar is the animation. | ||
</ | </ | ||
- | + | - The smaller the images the smaller gets the rendering time. | |
- | + | - Images bigger than 2000px may not work well especially on mobile devices where they may not load at all. | |
- | + | - Reduce the number of frames of a sprite animation as much as possible, get rid of frames too similar to the one before and next. | |
- | + | - Use the profiler in GD5 for see which events are taking the most of the performance to try and optimize it | |
- | + | - Reduce number of conditions as object selection is a heavy process. | |
- | + | ||