From b3223d1a680dae9dd41f510c189060e5a61d04d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 01:35:18 +0100 Subject: [PATCH 1/3] [Top-down grid movement] Use the animator extension --- .../top-down-grid-movement.json | 1187 +++++++++++------ 1 file changed, 801 insertions(+), 386 deletions(-) diff --git a/examples/top-down-grid-movement/top-down-grid-movement.json b/examples/top-down-grid-movement/top-down-grid-movement.json index 7e7918bb1..da4cd9608 100644 --- a/examples/top-down-grid-movement/top-down-grid-movement.json +++ b/examples/top-down-grid-movement/top-down-grid-movement.json @@ -682,6 +682,16 @@ "movementAngleOffset": 0, "viewpoint": "TopDown" }, + { + "name": "TopDownMovementAnimator", + "type": "TopDownMovementAnimator::TopDownMovementAnimator", + "TopDownMovement": "TopDownMovement", + "IsScalingAnimation": true, + "AnimationName": "Walk", + "DirectionCount": 4, + "AngleOffset": 0, + "AnimationDirection": 0 + }, { "name": "YSort", "type": "YSort::YSort" @@ -689,16 +699,16 @@ ], "animations": [ { - "name": "Down", + "name": "Walk0", "useMultipleDirections": false, "directions": [ { "looping": true, - "timeBetweenFrames": 0.16670000553131104, + "timeBetweenFrames": 0.0833, "sprites": [ { "hasCustomCollisionMask": false, - "image": "Bard 4_Down_1.png", + "image": "Bard 4_Right_1.png", "points": [], "originPoint": { "name": "origine", @@ -715,7 +725,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 4_Down_2.png", + "image": "Bard 4_Right_2.png", "points": [], "originPoint": { "name": "origine", @@ -732,7 +742,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 4_Down_3.png", + "image": "Bard 4_Right_3.png", "points": [], "originPoint": { "name": "origine", @@ -752,16 +762,16 @@ ] }, { - "name": "Left", + "name": "Walk1", "useMultipleDirections": false, "directions": [ { "looping": true, - "timeBetweenFrames": 0.16670000553131104, + "timeBetweenFrames": 0.0833, "sprites": [ { "hasCustomCollisionMask": false, - "image": "Bard 4_Left_1.png", + "image": "Bard 4_Down_1.png", "points": [], "originPoint": { "name": "origine", @@ -778,7 +788,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 4_Left_2.png", + "image": "Bard 4_Down_2.png", "points": [], "originPoint": { "name": "origine", @@ -795,7 +805,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 4_Left_3.png", + "image": "Bard 4_Down_3.png", "points": [], "originPoint": { "name": "origine", @@ -815,16 +825,16 @@ ] }, { - "name": "Right", + "name": "Walk2", "useMultipleDirections": false, "directions": [ { "looping": true, - "timeBetweenFrames": 0.16670000553131104, + "timeBetweenFrames": 0.0833, "sprites": [ { "hasCustomCollisionMask": false, - "image": "Bard 4_Right_1.png", + "image": "Bard 4_Left_1.png", "points": [], "originPoint": { "name": "origine", @@ -841,7 +851,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 4_Right_2.png", + "image": "Bard 4_Left_2.png", "points": [], "originPoint": { "name": "origine", @@ -858,7 +868,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 4_Right_3.png", + "image": "Bard 4_Left_3.png", "points": [], "originPoint": { "name": "origine", @@ -878,12 +888,12 @@ ] }, { - "name": "Up", + "name": "Walk3", "useMultipleDirections": false, "directions": [ { "looping": true, - "timeBetweenFrames": 0.16670000553131104, + "timeBetweenFrames": 0.0833, "sprites": [ { "hasCustomCollisionMask": false, @@ -990,6 +1000,16 @@ "rotateObject": false, "viewpoint": "TopDown" }, + { + "name": "TopDownMovementAnimator", + "type": "TopDownMovementAnimator::TopDownMovementAnimator", + "TopDownMovement": "TopDownMovement", + "IsScalingAnimation": true, + "AnimationName": "Walk", + "DirectionCount": 4, + "AngleOffset": 0, + "AnimationDirection": 0 + }, { "name": "YSort", "type": "YSort::YSort" @@ -997,7 +1017,7 @@ ], "animations": [ { - "name": "Down", + "name": "Walk0", "useMultipleDirections": false, "directions": [ { @@ -1006,7 +1026,7 @@ "sprites": [ { "hasCustomCollisionMask": false, - "image": "Bard 6_Down_1.png", + "image": "Bard 6_Right_1.png", "points": [], "originPoint": { "name": "origine", @@ -1023,7 +1043,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 6_Down_2.png", + "image": "Bard 6_Right_2.png", "points": [], "originPoint": { "name": "origine", @@ -1040,7 +1060,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 6_Down_3.png", + "image": "Bard 6_Right_3.png", "points": [], "originPoint": { "name": "origine", @@ -1060,7 +1080,7 @@ ] }, { - "name": "Left", + "name": "Walk1", "useMultipleDirections": false, "directions": [ { @@ -1069,7 +1089,7 @@ "sprites": [ { "hasCustomCollisionMask": false, - "image": "Bard 6_Left_1.png", + "image": "Bard 6_Down_1.png", "points": [], "originPoint": { "name": "origine", @@ -1086,7 +1106,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 6_Left_2.png", + "image": "Bard 6_Down_2.png", "points": [], "originPoint": { "name": "origine", @@ -1103,7 +1123,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 6_Left_3.png", + "image": "Bard 6_Down_3.png", "points": [], "originPoint": { "name": "origine", @@ -1123,7 +1143,7 @@ ] }, { - "name": "Right", + "name": "Walk2", "useMultipleDirections": false, "directions": [ { @@ -1132,7 +1152,7 @@ "sprites": [ { "hasCustomCollisionMask": false, - "image": "Bard 6_Right_1.png", + "image": "Bard 6_Left_1.png", "points": [], "originPoint": { "name": "origine", @@ -1149,7 +1169,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 6_Right_2.png", + "image": "Bard 6_Left_2.png", "points": [], "originPoint": { "name": "origine", @@ -1166,7 +1186,7 @@ }, { "hasCustomCollisionMask": false, - "image": "Bard 6_Right_3.png", + "image": "Bard 6_Left_3.png", "points": [], "originPoint": { "name": "origine", @@ -1186,7 +1206,7 @@ ] }, { - "name": "Up", + "name": "Walk3", "useMultipleDirections": false, "directions": [ { @@ -1427,7 +1447,7 @@ "colorG": 176, "colorR": 74, "creationTime": 0, - "name": "Character animation", + "name": "PNJ movement", "source": "", "type": "BuiltinCommonInstructions::Group", "events": [ @@ -1439,139 +1459,7 @@ "value": "TopDownMovementBehavior::XVelocity" }, "parameters": [ - "Bard4", - "TopDownMovement", - "<", - "0" - ] - }, - { - "type": { - "value": "BuiltinCommonInstructions::Once" - }, - "parameters": [] - } - ], - "actions": [ - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard4", - "\"Left\"" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "value": "TopDownMovementBehavior::XVelocity" - }, - "parameters": [ - "Bard4", - "TopDownMovement", - ">", - "0" - ] - }, - { - "type": { - "value": "BuiltinCommonInstructions::Once" - }, - "parameters": [] - } - ], - "actions": [ - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard4", - "\"Right\"" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "value": "TopDownMovementBehavior::YVelocity" - }, - "parameters": [ - "Bard4", - "TopDownMovement", - "<", - "0" - ] - }, - { - "type": { - "value": "BuiltinCommonInstructions::Once" - }, - "parameters": [] - } - ], - "actions": [ - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard4", - "\"Up\"" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "value": "TopDownMovementBehavior::YVelocity" - }, - "parameters": [ - "Bard4", - "TopDownMovement", - ">", - "0" - ] - }, - { - "type": { - "value": "BuiltinCommonInstructions::Once" - }, - "parameters": [] - } - ], - "actions": [ - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard4", - "\"Down\"" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "value": "TopDownMovementBehavior::XVelocity" - }, - "parameters": [ - "Bard4", + "Bard6", "TopDownMovement", "=", "0" @@ -1582,224 +1470,76 @@ "value": "TopDownMovementBehavior::YVelocity" }, "parameters": [ - "Bard4", + "Bard6", "TopDownMovement", "=", "0" ] } ], - "actions": [ + "actions": [], + "events": [ { - "type": { - "value": "PauseAnimation" + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 }, - "parameters": [ - "Bard4" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ + "comment": "Wait a bit.", + "comment2": "" + }, { - "type": { - "value": "BuiltinCommonInstructions::Or" - }, - "parameters": [], - "subInstructions": [ - { - "type": { - "value": "TopDownMovementBehavior::XVelocity" - }, - "parameters": [ - "Bard4", - "TopDownMovement", - "!=", - "0" - ] - }, + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ { "type": { - "value": "TopDownMovementBehavior::YVelocity" + "inverted": true, + "value": "CompareObjectTimer" }, "parameters": [ - "Bard4", - "TopDownMovement", - "!=", + "Bard6", + "\"Wait\"", + ">", "0" ] } - ] - } - ], - "actions": [ - { - "type": { - "value": "PlayAnimation" - }, - "parameters": [ - "Bard4" - ] - } - ] - } - ], - "parameters": [] - }, - { - "colorB": 228, - "colorG": 176, - "colorR": 74, - "creationTime": 0, - "name": "PNJ animation and movement", - "source": "", - "type": "BuiltinCommonInstructions::Group", - "events": [ - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "value": "BuiltinCommonInstructions::Or" - }, - "parameters": [], - "subInstructions": [ + ], + "actions": [ { "type": { - "value": "TopDownMovementBehavior::XVelocity" + "value": "ResetObjectTimer" }, "parameters": [ "Bard6", - "TopDownMovement", - "!=", - "0" + "\"Wait\"" ] }, { "type": { - "value": "TopDownMovementBehavior::YVelocity" + "value": "ModVarObjet" }, "parameters": [ "Bard6", - "TopDownMovement", - "!=", - "0" + "WaitDuration", + "=", + "RandomFloatInRange(1.5, 2.5)" ] } ] - } - ], - "actions": [ + }, { - "type": { - "value": "PlayAnimation" - }, - "parameters": [ - "Bard6" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "value": "TopDownMovementBehavior::XVelocity" - }, - "parameters": [ - "Bard6", - "TopDownMovement", - "=", - "0" - ] - }, - { - "type": { - "value": "TopDownMovementBehavior::YVelocity" - }, - "parameters": [ - "Bard6", - "TopDownMovement", - "=", - "0" - ] - } - ], - "actions": [ - { - "type": { - "value": "PauseAnimation" - }, - "parameters": [ - "Bard6" - ] - } - ], - "events": [ - { - "type": "BuiltinCommonInstructions::Comment", - "color": { - "b": 109, - "g": 230, - "r": 255, - "textB": 0, - "textG": 0, - "textR": 0 - }, - "comment": "Wait a bit.", - "comment2": "" - }, - { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "inverted": true, - "value": "CompareObjectTimer" - }, - "parameters": [ - "Bard6", - "\"Wait\"", - ">", - "0" - ] - } - ], - "actions": [ - { - "type": { - "value": "ResetObjectTimer" - }, - "parameters": [ - "Bard6", - "\"Wait\"" - ] - }, - { - "type": { - "value": "ModVarObjet" - }, - "parameters": [ - "Bard6", - "WaitDuration", - "=", - "RandomFloatInRange(1.5, 2.5)" - ] - } - ] - }, - { - "type": "BuiltinCommonInstructions::Comment", - "color": { - "b": 109, - "g": 230, - "r": 255, - "textB": 0, - "textG": 0, - "textR": 0 + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 }, "comment": "Choose a random direction.", "comment2": "" @@ -1877,15 +1617,6 @@ "Bard6", "TopDownMovement" ] - }, - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard6", - "\"Left\"" - ] } ] }, @@ -1912,15 +1643,6 @@ "Bard6", "TopDownMovement" ] - }, - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard6", - "\"Right\"" - ] } ] }, @@ -1947,15 +1669,6 @@ "Bard6", "TopDownMovement" ] - }, - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard6", - "\"Up\"" - ] } ] }, @@ -1982,15 +1695,6 @@ "Bard6", "TopDownMovement" ] - }, - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Bard6", - "\"Down\"" - ] } ] } @@ -2035,6 +1739,12 @@ "name": "TopDownMovement", "type": "TopDownMovementBehavior::TopDownMovementBehavior" }, + { + "name": "TopDownMovementAnimator", + "type": "TopDownMovementAnimator::TopDownMovementAnimator", + "NewAnimationDirection": 0, + "AnimationFrame": 0 + }, { "name": "YSort", "type": "YSort::YSort" @@ -2044,6 +1754,711 @@ ], "externalEvents": [], "eventsFunctionsExtensions": [ + { + "author": "", + "category": "Movement", + "extensionNamespace": "", + "fullName": "Top-down movement animator", + "helpPath": "", + "iconUrl": "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjwhLS0gR2VuZXJhdG9yOiBBZG9iZSBJbGx1c3RyYXRvciAyMy4wLjMsIFNWRyBFeHBvcnQgUGx1Zy1JbiAuIFNWRyBWZXJzaW9uOiA2LjAwIEJ1aWxkIDApICAtLT4NCjxzdmcgdmVyc2lvbj0iMS4xIiBpZD0iSWNvbnMiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgeG1sbnM6eGxpbms9Imh0dHA6Ly93d3cudzMub3JnLzE5OTkveGxpbmsiIHg9IjBweCIgeT0iMHB4Ig0KCSB2aWV3Qm94PSIwIDAgMzIgMzIiIHN0eWxlPSJlbmFibGUtYmFja2dyb3VuZDpuZXcgMCAwIDMyIDMyOyIgeG1sOnNwYWNlPSJwcmVzZXJ2ZSI+DQo8Zz4NCgk8cGF0aCBkPSJNNiwyMS4xYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNsLTQtNC4xYy0wLjQtMC40LTAuNC0xLDAtMS40bDQtNC4xYzAuNC0wLjQsMS0wLjQsMS40LDBzMC40LDEsMCwxLjRMMy40LDE2bDMuMywzLjMNCgkJYzAuNCwwLjQsMC40LDEsMCwxLjRDNi42LDIxLDYuMywyMS4xLDYsMjEuMXoiLz4NCjwvZz4NCjxnPg0KCTxwYXRoIGQ9Ik0yNiwyMS4xYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNjLTAuNC0wLjQtMC40LTEsMC0xLjRsMy4zLTMuM2wtMy4zLTMuM2MtMC40LTAuNC0wLjQtMSwwLTEuNHMxLTAuNCwxLjQsMGw0LjEsNC4xDQoJCWMwLjIsMC4yLDAuMywwLjQsMC4zLDAuN3MtMC4xLDAuNS0wLjMsMC43bC00LjEsNC4xQzI2LjYsMjEsMjYuMywyMS4xLDI2LDIxLjF6Ii8+DQo8L2c+DQo8Zz4NCgk8cGF0aCBkPSJNMTYsMzEuMUwxNiwzMS4xYy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNsLTQtNC4xYy0wLjQtMC40LTAuNC0xLDAtMS40czEtMC40LDEuNCwwbDMuMywzLjNsMy4zLTMuM2MwLjQtMC40LDEtMC40LDEuNCwwDQoJCXMwLjQsMSwwLDEuNGwtNC4xLDQuMUMxNi42LDMwLjksMTYuMywzMS4xLDE2LDMxLjF6Ii8+DQo8L2c+DQo8Zz4NCgk8cGF0aCBkPSJNMjAuMSw3Yy0wLjMsMC0wLjUtMC4xLTAuNy0wLjNMMTYsMy40bC0zLjMsMy4zYy0wLjQsMC40LTEsMC40LTEuNCwwcy0wLjQtMSwwLTEuNGw0LTQuMWMwLjQtMC40LDEtMC40LDEuNCwwbDQuMSw0LjENCgkJYzAuNCwwLjQsMC40LDEsMCwxLjRDMjAuNiw2LjksMjAuNCw3LDIwLjEsN3oiLz4NCjwvZz4NCjxnPg0KCTxwYXRoIGQ9Ik0xNiwzMGMtMC42LDAtMS0wLjQtMS0xVjNjMC0wLjYsMC40LTEsMS0xczEsMC40LDEsMXYyNkMxNywyOS42LDE2LjYsMzAsMTYsMzB6Ii8+DQo8L2c+DQo8Zz4NCgk8cGF0aCBkPSJNMjksMTdIMmMtMC42LDAtMS0wLjQtMS0xczAuNC0xLDEtMWgyN2MwLjYsMCwxLDAuNCwxLDFTMjkuNiwxNywyOSwxN3oiLz4NCjwvZz4NCjwvc3ZnPg0K", + "name": "TopDownMovementAnimator", + "previewIconUrl": "https://asset-resources.gdevelop.io/public-resources/Icons/Glyphster Pack/Master/SVG/Arrows/a6026156355ae5f03613b03971e4ddb50d0c95b8901e7a21edc57f33f0032e42_Arrows_thin_arrows_all_directions_cross.svg", + "shortDescription": "Change the animation according to the movement direction.", + "version": "0.1.0", + "description": "Change the animation according to the movement direction.", + "tags": [ + "animation", + "direction" + ], + "authorIds": [ + "IWykYNRvhCZBN3vEgKEbBPOR3Oc2" + ], + "dependencies": [], + "eventsFunctions": [], + "eventsBasedBehaviors": [ + { + "description": "Change the animation according to the movement direction.", + "fullName": "Top-down movement animator", + "name": "TopDownMovementAnimator", + "objectType": "Sprite", + "eventsFunctions": [ + { + "fullName": "", + "functionType": "Action", + "name": "onCreated", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "0" + ] + } + ], + "actions": [], + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::DiagonalsAllowed" + }, + "parameters": [ + "Object", + "TopDownMovement" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "8" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "TopDownMovementBehavior::DiagonalsAllowed" + }, + "parameters": [ + "Object", + "TopDownMovement" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyDirectionCount" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "4" + ] + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "Action", + "name": "doStepPostEvents", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::Speed" + }, + "parameters": [ + "Object", + "TopDownMovement", + "=", + "0" + ] + } + ], + "actions": [ + { + "type": { + "value": "PauseAnimation" + }, + "parameters": [ + "Object" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementBehavior::Speed" + }, + "parameters": [ + "Object", + "TopDownMovement", + ">", + "0" + ] + } + ], + "actions": [ + { + "type": { + "value": "PlayAnimation" + }, + "parameters": [ + "Object" + ] + } + ], + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationSpeedScale" + }, + "parameters": [ + "Object", + "Behavior", + "" + ] + } + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetSharedPropertyNewAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "mod((Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + ] + } + ], + "events": [ + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Change the animation but keep the current frame number.\nA small margin is used to avoid to flicker between 2 directions.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "BuiltinCommonInstructions::CompareNumbers" + }, + "parameters": [ + "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + ">", + "0.5 + 0.0625" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "round(Object.Behavior::SharedPropertyNewAnimationDirection())" + ] + }, + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetSharedPropertyAnimationFrame" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "Object.Sprite()" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + }, + { + "type": { + "value": "ChangeSprite" + }, + "parameters": [ + "Object", + "=", + "Object.Behavior::SharedPropertyAnimationFrame()" + ] + } + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "the animation name of the object.", + "fullName": "Animation name", + "functionType": "ExpressionAndCondition", + "name": "AnimationName", + "sentence": "the animation name", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnString" + }, + "parameters": [ + "Object.Behavior::PropertyAnimationName()" + ] + } + ] + } + ], + "expressionType": { + "type": "string" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "fullName": "", + "functionType": "ActionWithOperator", + "getterName": "AnimationName", + "name": "SetAnimationName", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyAnimationName" + }, + "parameters": [ + "Object", + "Behavior", + "!=", + "GetArgumentAsString(\"Value\")" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyAnimationName" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "GetArgumentAsString(\"Value\")" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Check if the animation is scaled according to speed.", + "fullName": "Scale animation according to speed", + "functionType": "Condition", + "name": "IsScalingAnimation", + "sentence": "_PARAM0_ animation is scaled according to speed", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::PropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior" + ] + } + ], + "actions": [ + { + "type": { + "value": "SetReturnBoolean" + }, + "parameters": [ + "True" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Change whether the animation is scaled according to speed or not.", + "fullName": "Scale animation according to speed", + "functionType": "Action", + "name": "SetIsScalingAnimation", + "sentence": "Scale the animation of _PARAM0_ according to speed: _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "inverted": true, + "value": "GetArgumentAsBoolean" + }, + "parameters": [ + "\"Value\"" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior", + "no" + ] + }, + { + "type": { + "value": "ChangeAnimationSpeedScale" + }, + "parameters": [ + "Object", + "=", + "1" + ] + } + ] + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ + { + "type": { + "value": "GetArgumentAsBoolean" + }, + "parameters": [ + "\"Value\"" + ] + } + ], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyIsScalingAnimation" + }, + "parameters": [ + "Object", + "Behavior", + "yes" + ] + }, + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationSpeedScale" + }, + "parameters": [ + "Object", + "Behavior", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + }, + { + "defaultValue": "yes", + "description": "IsScalingAnimation", + "name": "Value", + "optional": true, + "type": "yesorno" + } + ], + "objectGroups": [] + }, + { + "description": "Change the animation speed scale according to the object speed.", + "fullName": "Animation speed scale", + "functionType": "Action", + "name": "SetAnimationSpeedScale", + "sentence": "Change the animation speed scale according to _PARAM0_ speed", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "ChangeAnimationSpeedScale" + }, + "parameters": [ + "Object", + "=", + "Object.TopDownMovement::Speed() / Object.TopDownMovement::MaxSpeed()" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + } + ], + "propertyDescriptors": [ + { + "value": "", + "type": "Behavior", + "label": "Top-down movement", + "description": "", + "group": "", + "extraInformation": [ + "TopDownMovementBehavior::TopDownMovementBehavior" + ], + "hidden": false, + "name": "TopDownMovement" + }, + { + "value": "true", + "type": "Boolean", + "label": "Scale animation according to speed", + "description": "", + "group": "Animation", + "extraInformation": [], + "hidden": false, + "name": "IsScalingAnimation" + }, + { + "value": "Walk", + "type": "String", + "label": "Animation name", + "description": "Animations must be called \"Walk0\", \"Walk1\"... for left, down...", + "group": "Animation", + "extraInformation": [], + "hidden": false, + "name": "AnimationName" + }, + { + "value": "0", + "type": "Number", + "unit": "Dimensionless", + "label": "Number of directions", + "description": "Leave to 0 to automatically use 8 when diagonals are allowed and 4 otherwise.", + "group": "Direction", + "extraInformation": [], + "hidden": false, + "name": "DirectionCount" + }, + { + "value": "0", + "type": "Number", + "unit": "DegreeAngle", + "label": "Angle offset", + "description": "Setted to 90°, \"Walk0\" becomes the animation for down.", + "group": "Direction", + "extraInformation": [], + "hidden": false, + "name": "AngleOffset" + }, + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "AnimationDirection" + } + ], + "sharedPropertyDescriptors": [ + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "NewAnimationDirection" + }, + { + "value": "0", + "type": "Number", + "label": "", + "description": "", + "group": "", + "extraInformation": [], + "hidden": true, + "name": "AnimationFrame" + } + ] + } + ], + "eventsBasedObjects": [] + }, { "author": "Gustavo Marciano", "category": "", From 6721f297be191dd2b386e57c0cc67f6ba1e534fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 02:29:57 +0100 Subject: [PATCH 2/3] Update animator. --- .../top-down-grid-movement.json | 281 +++++++++++++----- 1 file changed, 211 insertions(+), 70 deletions(-) diff --git a/examples/top-down-grid-movement/top-down-grid-movement.json b/examples/top-down-grid-movement/top-down-grid-movement.json index da4cd9608..5bc87916e 100644 --- a/examples/top-down-grid-movement/top-down-grid-movement.json +++ b/examples/top-down-grid-movement/top-down-grid-movement.json @@ -1879,6 +1879,46 @@ ], "objectGroups": [] }, + { + "fullName": "", + "functionType": "Action", + "name": "onActivate", + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "Object.Behavior::Direction()", + "" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, { "fullName": "", "functionType": "Action", @@ -1977,81 +2017,49 @@ "Object", "Behavior", "=", - "mod((Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + "Object.Behavior::Direction()" ] } - ], - "events": [ + ] + }, + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Use a small margin is used to avoid to flicker between 2 directions.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [ { - "type": "BuiltinCommonInstructions::Comment", - "color": { - "b": 109, - "g": 230, - "r": 255, - "textB": 0, - "textG": 0, - "textR": 0 + "type": { + "inverted": true, + "value": "BuiltinCommonInstructions::CompareNumbers" }, - "comment": "Change the animation but keep the current frame number.\nA small margin is used to avoid to flicker between 2 directions.", - "comment2": "" - }, + "parameters": [ + "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + ">", + "0.5 + 0.0625" + ] + } + ], + "actions": [ { - "type": "BuiltinCommonInstructions::Standard", - "conditions": [ - { - "type": { - "inverted": true, - "value": "BuiltinCommonInstructions::CompareNumbers" - }, - "parameters": [ - "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", - ">", - "0.5 + 0.0625" - ] - } - ], - "actions": [ - { - "type": { - "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyAnimationDirection" - }, - "parameters": [ - "Object", - "Behavior", - "=", - "round(Object.Behavior::SharedPropertyNewAnimationDirection())" - ] - }, - { - "type": { - "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetSharedPropertyAnimationFrame" - }, - "parameters": [ - "Object", - "Behavior", - "=", - "Object.Sprite()" - ] - }, - { - "type": { - "value": "SetAnimationName" - }, - "parameters": [ - "Object", - "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" - ] - }, - { - "type": { - "value": "ChangeSprite" - }, - "parameters": [ - "Object", - "=", - "Object.Behavior::SharedPropertyAnimationFrame()" - ] - } + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "Object.Behavior::SharedPropertyNewAnimationDirection()", + "" ] } ] @@ -2331,6 +2339,7 @@ "fullName": "Animation speed scale", "functionType": "Action", "name": "SetAnimationSpeedScale", + "private": true, "sentence": "Change the animation speed scale according to _PARAM0_ speed", "events": [ { @@ -2365,6 +2374,138 @@ } ], "objectGroups": [] + }, + { + "description": "Return the object movement direction.", + "fullName": "Direction", + "functionType": "Expression", + "name": "Direction", + "private": true, + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnNumber" + }, + "parameters": [ + "mod((Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + ] + } + ] + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + } + ], + "objectGroups": [] + }, + { + "description": "Change the animation direction of the object.", + "fullName": "Animation direction", + "functionType": "Action", + "name": "SetAnimationDirection", + "private": true, + "sentence": "Change the animation direction of _PARAM0_ to _PARAM2_", + "events": [ + { + "type": "BuiltinCommonInstructions::Comment", + "color": { + "b": 109, + "g": 230, + "r": 255, + "textB": 0, + "textG": 0, + "textR": 0 + }, + "comment": "Change the animation but keep the current frame number.", + "comment2": "" + }, + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetPropertyAnimationDirection" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "round(GetArgumentAsNumber(\"Value\"))" + ] + }, + { + "type": { + "value": "TopDownMovementAnimator::TopDownMovementAnimator::SetSharedPropertyAnimationFrame" + }, + "parameters": [ + "Object", + "Behavior", + "=", + "Object.Sprite()" + ] + }, + { + "type": { + "value": "SetAnimationName" + }, + "parameters": [ + "Object", + "Object. Behavior::PropertyAnimationName() + ToString(Object.Behavior::PropertyAnimationDirection())" + ] + }, + { + "type": { + "value": "ChangeSprite" + }, + "parameters": [ + "Object", + "=", + "Object.Behavior::SharedPropertyAnimationFrame()" + ] + } + ] + } + ], + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + }, + { + "description": "Value", + "name": "Value", + "type": "expression" + } + ], + "objectGroups": [] } ], "propertyDescriptors": [ From 15ad2730a8f264112820944e48559c0168eb6b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Davy=20H=C3=A9lard?= Date: Sun, 12 Mar 2023 19:09:40 +0100 Subject: [PATCH 3/3] Upgrade the animator. --- .../top-down-grid-movement.json | 60 +++++++++++++++++-- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/examples/top-down-grid-movement/top-down-grid-movement.json b/examples/top-down-grid-movement/top-down-grid-movement.json index 5bc87916e..7dcae01cf 100644 --- a/examples/top-down-grid-movement/top-down-grid-movement.json +++ b/examples/top-down-grid-movement/top-down-grid-movement.json @@ -2044,9 +2044,9 @@ "value": "BuiltinCommonInstructions::CompareNumbers" }, "parameters": [ - "abs(mod(Object.Behavior::SharedPropertyNewAnimationDirection() - Object.Behavior::PropertyAnimationDirection(), Object.Behavior::PropertyDirectionCount()))", + "abs(Object.Behavior:: DirectionDifference(Object.Behavior::SharedPropertyNewAnimationDirection(), Object.Behavior::PropertyAnimationDirection()))", ">", - "0.5 + 0.0625" + "0.5 + 0.03125" ] } ], @@ -2392,7 +2392,7 @@ "value": "SetReturnNumber" }, "parameters": [ - "mod((Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360, Object.Behavior::PropertyDirectionCount())" + "(Object.TopDownMovement::Angle() + Object.Behavior::PropertyAngleOffset()) * Object.Behavior::PropertyDirectionCount() / 360" ] } ] @@ -2417,6 +2417,58 @@ ], "objectGroups": [] }, + { + "description": "Return the difference between 2 directions.", + "fullName": "Direction dirrerence", + "functionType": "Expression", + "name": "DirectionDifference", + "private": true, + "sentence": "", + "events": [ + { + "type": "BuiltinCommonInstructions::Standard", + "conditions": [], + "actions": [ + { + "type": { + "value": "SetReturnNumber" + }, + "parameters": [ + "mod(mod(GetArgumentAsNumber(\"Direction\") - GetArgumentAsNumber(\"OtherDirection\"), Object.Behavior::PropertyDirectionCount()) + Object.Behavior::PropertyDirectionCount() / 2, Object.Behavior::PropertyDirectionCount()) - Object.Behavior::PropertyDirectionCount() / 2" + ] + } + ] + } + ], + "expressionType": { + "type": "expression" + }, + "parameters": [ + { + "description": "Object", + "name": "Object", + "supplementaryInformation": "Sprite", + "type": "object" + }, + { + "description": "Behavior", + "name": "Behavior", + "supplementaryInformation": "TopDownMovementAnimator::TopDownMovementAnimator", + "type": "behavior" + }, + { + "description": "Direction", + "name": "Direction", + "type": "expression" + }, + { + "description": "Other direction", + "name": "OtherDirection", + "type": "expression" + } + ], + "objectGroups": [] + }, { "description": "Change the animation direction of the object.", "fullName": "Animation direction", @@ -2450,7 +2502,7 @@ "Object", "Behavior", "=", - "round(GetArgumentAsNumber(\"Value\"))" + "mod(mod(round(GetArgumentAsNumber(\"Value\")), Object.Behavior::PropertyDirectionCount()) + Object.Behavior::PropertyDirectionCount(), Object.Behavior::PropertyDirectionCount())" ] }, {