Skip to content

Control (制御)

Control.stopThisScript (このスレッドを止める)


Sprite/Stage

typescript

const hoge = new Ts.Sprite( 'hoge' );
hoge.Event.flagPresser().func = async function* ( this : Sprite ) {

    for( const _idx of Ts.Loop.Iterator( 100 ) ) {
        if(_idx == 50) {
            // このスクリプトを止める
            this.Control.stopThisScript();
        }
        yield;
    }
}

Control.stopOtherScripts (スプライトの他のスレッドを止める)


Sprite/Stage

typescript

const hoge = new Ts.Sprite( 'hoge' );

const fuga = new Ts.Sprite( 'fuga' );

// 旗が押されたときのスレッド(hoge): スレッド01
hoge.Event.flagPresser().func = async function* ( this : Sprite ) {
    // 『5秒間』待つ
    await this.Control.wait( 5 );
    // スクリプトの他のスクリプトを停止する 
    // → hogeの他のスクリプトを停止する
    this.Control.stopOtherScripts();
}

// 旗が押されたときのスレッド(hoge) : スレッド02
hoge.Event.flagPresser().func = async function* ( this : Sprite ) {
    // ずっと繰り返す
    for( ;; ) {
        this.Motion.move.steps( 10 ); // 進む
        yield;
    }
}
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
// ◆◆ 5秒後にスレッド02が終わる
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

// 旗が押されたときのスレッド(hoge): スレッド03
hoge.Event.flagPresser().func = async function* ( this : Sprite ) {
    // ずっと繰り返す
    for( ;; ) {
        this.Motion.direction.degree += 5; // 回転する
        yield;
    }
}
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
// ◆◆ 5秒後にスレッド03が終わる
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

// 旗が押されたときのスレッド(fuga): スレッド04
fuga.Event.flagPresser().func = async function* ( this : Sprite ) {
    // ずっと繰り返す
    for( ;; ) {
        this.Motion.position.y += 5; // Y座標を +5 ずつ増やす
        yield;
    }
}
// ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇
// スレッド04は『hoge』のスレッドではない
// よってスレッド04は終わらない
// ◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇◇

Control.stopAll (すべてのスクリプトを止める)


Sprite/Stage

typescript
import { Typescratcher as Ts } from "@tscratch3/typescratcher";
import type { Sprite } from "@tscratch3/typescratcher";

const hoge = new Ts.Sprite( 'hoge' );

const fuga = new Ts.Sprite( 'fuga' );

// 旗が押されたときのスレッド(hoge): スレッド01
hoge.Event.flagPresser().func = async function* ( this : Sprite ) {
    // 『5秒間』待つ
    await this.Control.wait( 5 );
    // 全てのスクリプトを停止する 
    this.Control.stopAll();
}

// 旗が押されたときのスレッド(hoge) : スレッド02
hoge.Event.flagPresser().func = async function* ( this : Sprite ) {
    // ずっと繰り返す
    for( ;; ) {
        this.Motion.move.steps( 10 ); // 進む
        yield;
    }
}
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
// ◆◆ 5秒後にスレッド02が終わる
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆

// 旗が押されたときのスレッド(fuga): スレッド03
fuga.Event.flagPresser().func = async function* ( this : Sprite ) {
    // ずっと繰り返す
    for( ;; ) {
        this.Motion.position.y += 5; // Y座標を +5 ずつ増やす
        yield;
    }
}
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆
// ◆◆ 5秒後にスレッド03が終わる
// ◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆