※この翻訳ドキュメントはスクリプトによって出力・同期されています。内容が怪しそうな場合はGitHubにissueを追加したり英語の原文の確認をお願いします。

remove_children インターフェイス

このページではコンテナの各クラスのremove_childrenメソッドのインターフェイスについて説明します。

インターフェイス概要

remove_childrenメソッドはコンテナのインスタンスから全ての子のインスタンスを取り除きます。

基本的な使い方

remove_childrenメソッドは引数の指定を必要としません。

以下の例では、いずれかの四角をクリックした場合remove_childrenメソッドが呼ばれ全ての子が取り除かれます:

import apysc as ap


def on_click(e: ap.MouseEvent[ap.Sprite], options: dict) -> None:
    """
    The click event handler.

    Parameters
    ----------
    e : ap.MouseEvent[ap.Sprite]
        Event instance.
    options : dict
        Optional arguments dictionary.
    """
    sprite: ap.Sprite = e.this
    sprite.remove_children()


ap.Stage(
    stage_width=250, stage_height=150, background_color="#333", stage_elem_id="stage"
)
sprite: ap.Sprite = ap.Sprite()
sprite.graphics.begin_fill(color="#0af")
sprite.graphics.draw_rect(x=50, y=50, width=50, height=50)
sprite.graphics.draw_rect(x=150, y=50, width=50, height=50)
sprite.click(on_click)

ap.save_overall_html(dest_dir_path="remove_children_basic_usage/")