From 921836e302a90b465240983b18754fa09140d144 Mon Sep 17 00:00:00 2001 From: arc360 Date: Tue, 20 Jan 2026 22:11:44 -0600 Subject: [PATCH] Add a new tween block --- src/blocks/tween.js | 83 +++++++++++++++++++++++++++++++++++++++++++ src/scripts/editor.js | 17 +++++++++ 2 files changed, 100 insertions(+) diff --git a/src/blocks/tween.js b/src/blocks/tween.js index 5ac98ba..59b907c 100644 --- a/src/blocks/tween.js +++ b/src/blocks/tween.js @@ -289,3 +289,86 @@ BlocklyJS.javascriptGenerator.forBlock["tween_sprite_property"] = function ( return code; }; + +Blockly.Blocks["tween_sprite_to_xy"] = { + init: function () { + this.appendValueInput("X") + .setCheck("Number") + .appendField("tween to x:"); + this.appendValueInput("Y") + .setCheck("Number") + .appendField("y:"); + this.appendValueInput("DURATION") + .setCheck("Number") + .appendField("in"); + this.appendDummyInput() + .appendField("seconds using") + .appendField( + new Blockly.FieldDropdown([ + ["linear", "Linear"], + ["sine", "Sine"], + ["quadratic", "Quad"], + ["cubic", "Cubic"], + ["quartic", "Quart"], + ["quintic", "Quint"], + ["expo", "Expo"], + ["circ", "Circ"], + ["back", "Back"], + ["elastic", "Elastic"], + ["bounce", "Bounce"], + ]), + "EASING_TYPE" + ) + .appendField( + new Blockly.FieldDropdown([ + ["in", "In"], + ["out", "Out"], + ["in-out", "InOut"], + ]), + "EASING_MODE" + ); + this.setInputsInline(true); + this.setPreviousStatement(true, "default"); + this.setNextStatement(true, "default"); + this.setColour("#32a2c0"); + this.setTooltip( + "Tween sprite to a specific x and y position over time using easing" + ); + }, +}; + +BlocklyJS.javascriptGenerator.forBlock["tween_sprite_to_xy"] = function ( + block, + generator +) { + const x = + generator.valueToCode(block, "X", BlocklyJS.Order.ATOMIC) || "0"; + const y = + generator.valueToCode(block, "Y", BlocklyJS.Order.ATOMIC) || "0"; + const duration = + generator.valueToCode(block, "DURATION", BlocklyJS.Order.ATOMIC) || + "1"; + const easingType = block.getFieldValue("EASING_TYPE"); + const easingMode = block.getFieldValue("EASING_MODE"); + const code = `await Promise.all([ + startTween({ + from: sprite.x, + to: ${x}, + duration: ${duration}, + easing: "${easingMode + easingType}", + onUpdate: async (tweenValue) => { + sprite.x = tweenValue; + } + }), + startTween({ + from: sprite.y, + to: -(${y}), + duration: ${duration}, + easing: "${easingMode + easingType}", + onUpdate: async (tweenValue) => { + sprite.y = tweenValue; + } + }) + ]);\n`; + return code; +}; \ No newline at end of file diff --git a/src/scripts/editor.js b/src/scripts/editor.js index dd97dcb..4462dda 100644 --- a/src/scripts/editor.js +++ b/src/scripts/editor.js @@ -2191,6 +2191,23 @@ const extensions = [ + + + + 0 + + + + + 0 + + + + + 1 + + +