@@ -47,6 +47,7 @@ void MotionBlocks::registerBlocks(IEngine *engine)
4747 engine->addCompileFunction (this , " motion_goto" , &compileGoTo);
4848 engine->addCompileFunction (this , " motion_glidesecstoxy" , &compileGlideSecsToXY);
4949 engine->addCompileFunction (this , " motion_glideto" , &compileGlideTo);
50+ engine->addCompileFunction (this , " motion_changexby" , &compileChangeXBy);
5051}
5152
5253CompilerValue *MotionBlocks::compileMoveSteps (Compiler *compiler)
@@ -246,6 +247,16 @@ CompilerValue *MotionBlocks::compileGlideTo(Compiler *compiler)
246247 return nullptr ;
247248}
248249
250+ CompilerValue *MotionBlocks::compileChangeXBy (Compiler *compiler)
251+ {
252+ if (!compiler->target ()->isStage ()) {
253+ CompilerValue *dx = compiler->addInput (" DX" );
254+ compiler->addTargetFunctionCall (" motion_changexby" , Compiler::StaticType::Void, { Compiler::StaticType::Number }, { dx });
255+ }
256+
257+ return nullptr ;
258+ }
259+
249260extern " C" void motion_movesteps (Sprite *sprite, double steps)
250261{
251262 double dir = sprite->direction ();
@@ -510,6 +521,11 @@ extern "C" bool motion_is_target_valid(ExecutionContext *ctx, const StringPtr *n
510521 }
511522}
512523
524+ extern " C" void motion_changexby (Sprite *sprite, double dx)
525+ {
526+ sprite->setX (sprite->x () + dx);
527+ }
528+
513529extern " C" double motion_xposition (Sprite *sprite)
514530{
515531 return sprite->x ();
0 commit comments