Discuss Scratch

inoking
Scratcher
1000+ posts

意外と知られていないテクニック集

ie_523 wrote:

<(#000000)色に触れた>
よりも
<(すぷらいと v)に触れた>
のほうが検知が早い。
プラットフォーマーとかで使える。
根拠(検証プロジェクトなど)をお願いします。
ie_523
Scratcher
100+ posts

意外と知られていないテクニック集

#4482
検証用プロジェクト
作ってみました。
yuito2013
Scratcher
100+ posts

意外と知られていないテクニック集

検証用
https://scratch.mit.edu/projects/1194664366
変わりませんね、、何故か旗連打すると同じ分増えますね、、、
gyakuhonyakusss2
Scratcher
100+ posts

意外と知られていないテクニック集

作ってみました。何が言えるかはわかりませんが。。

Last edited by gyakuhonyakusss2 (July 4, 2025 10:54:31)

Yu14916
Scratcher
6 posts

意外と知られていないテクニック集

こんなものを作ってみました。

これから考えると、
・〈(色)に触れた〉はなにか色のあるエリアに触れた時大幅に遅延する
・〈(スプライト)に触れた〉はスプライトに触れた時には少ししか遅延しない
ということが分かると思います。

(どちらも並列に動かしている、かつ判定は再描画なしです。なので、片方が遅延するともう片方も遅延します。)

Last edited by Yu14916 (July 5, 2025 01:12:38)

yuito2013
Scratcher
100+ posts

意外と知られていないテクニック集

wait until <>
...
の代用法。
repeat until <>//何も入れない。

end
...
inoking
Scratcher
1000+ posts

意外と知られていないテクニック集

ちょっとこのトピックの対象を超えますが
スプライトに触れた、色に触れた のソースコードを確認しました。
ざっと見た感じ、スプライトに触れた は対象のスプライト座標枠内に限定してチェックしており(まあ当たり前)
このために 色に触れた より速くなっているようです。

https://github.com/scratchfoundation/scratch-vm/blob/develop/src/blocks/scratch3_sensing.js#L175
    touchingObject (args, util) {
        return util.target.isTouchingObject(args.TOUCHINGOBJECTMENU);
    }
    touchingColor (args, util) {
        const color = Cast.toRgbColorList(args.COLOR);
        return util.target.isTouchingColor(color);
    }
の2つからたどって、
https://github.com/scratchfoundation/scratch-vm/blob/develop/src/sprites/rendered-target.js#L743
    isTouchingObject (requestedObject) {
        if (requestedObject === '_mouse_') {
            if (!this.runtime.ioDevices.mouse) return false;
            const mouseX = this.runtime.ioDevices.mouse.getClientX();
            const mouseY = this.runtime.ioDevices.mouse.getClientY();
            return this.isTouchingPoint(mouseX, mouseY);
        } else if (requestedObject === '_edge_') {
            return this.isTouchingEdge();
        }
        return this.isTouchingSprite(requestedObject);
    }

    isTouchingSprite (spriteName) {
        spriteName = Cast.toString(spriteName);
        const firstClone = this.runtime.getSpriteTargetByName(spriteName);
        if (!firstClone || !this.renderer) {
            return false;
        }
        // Filter out dragging targets. This means a sprite that is being dragged
        // can detect other sprites using touching <sprite>, but cannot be detected
        // by other sprites while it is being dragged. This matches Scratch 2.0 behavior.
        const drawableCandidates = firstClone.sprite.clones.filter(clone => !clone.dragging)
            .map(clone => clone.drawableID);
        return this.renderer.isTouchingDrawables(
            this.drawableID, drawableCandidates);
    }

https://github.com/scratchfoundation/scratch-vm/blob/develop/src/sprites/rendered-target.js#L812
    isTouchingColor (rgb) {
        if (this.renderer) {
            return this.renderer.isTouchingColor(this.drawableID, rgb);
        }
        return false;
    }
その先は
https://github.com/scratchfoundation/scratch-render/blob/develop/src/RenderWebGL.js#L967
    /**
     * Check if a particular Drawable is touching any in a set of Drawables.
     * @param {int} drawableID The ID of the Drawable to check.
     * @param {?Array<int>} candidateIDs The Drawable IDs to check, otherwise all visible drawables in the renderer
     * @returns {boolean} True if the Drawable is touching one of candidateIDs.
     */
    isTouchingDrawables (drawableID, candidateIDs = this._drawList) {
https://github.com/scratchfoundation/scratch-render/blob/develop/src/RenderWebGL.js#L775
    /**
     * Check if a particular Drawable is touching a particular color.
     * Unlike touching drawable, if the "tester" is invisble, we will still test.
     * @param {int} drawableID The ID of the Drawable to check.
     * @param {Array<int>} color3b Test if the Drawable is touching this color.
     * @param {Array<int>} [mask3b] Optionally mask the check to this part of Drawable.
     * @returns {boolean} True iff the Drawable is touching the color.
     */
    isTouchingColor (drawableID, color3b, mask3b) {

Last edited by inoking (July 6, 2025 07:37:14)

inoking
Scratcher
1000+ posts

意外と知られていないテクニック集

inoking wrote:

ちょっとこのトピックの対象を超えますが
スプライトに触れた、色に触れた のソースコードを確認しました。
ざっと見た感じ、スプライトに触れた は対象のスプライト座標枠内に限定してチェックしており(まあ当たり前)
このために 色に触れた より速くなっているようです。
すみません、
よく考えたらその理由はちょっと違う気がしてきました。
もう少し調べます。
yuito2013
Scratcher
100+ posts

意外と知られていないテクニック集

((背景の [番号 v]::looks)
はなぜか、周りに赤い枠があり、
[scratchblocks](/ \は追加であり、/ \の中のカッコが余分である
((背景の [番号 v]::looks/)\
[/scratchblocks]
であり、
(背景の [番号 v]::looks
こうするためには、
[scratchblocks]
(背景の [番号 v]::looks
[/scratchblocks]
にする。
mochimochiyuu
Scratcher
32 posts

意外と知られていないテクニック集

#4489
そりゃそうでしょ。
最初の分では
((背景の [番号 v]::looks/)
括弧がついてしまってる。
()を取らないと周りに赤いやつがつくのは当たり前。
だって、それって定義ブロックの丸いやつということだから、丸いやつに
(背景の [番号 v])
が入るのは当たり前。
U-Y-Scratch
Scratcher
500+ posts

意外と知られていないテクニック集

強調するためにわざと赤色をつけるのもありです
finalbacon
Scratcher
100+ posts

意外と知られていないテクニック集

#4490
ちなみに、投稿を入力するところの、上のボタンからこのブロックを入力しようとすると、
((backdrop [number v]::looks)
こうなってしまいます。それの直し方と考えれば、有用なテクニックでしょう。
(#4489ではそれを言いたかったのかもしれません。)
r_1000
Scratcher
32 posts

意外と知られていないテクニック集

左右上下に動かしたいときに
if <key [d v] pressed?> then
change x by (10)
end
ではなくて
change x by ((<key [d v] pressed?> + (<key [a v] pressed?> * (-1))) * (10))
みたいにするとブロックがまとまる
U-Y-Scratch
Scratcher
500+ posts

意外と知られていないテクニック集

r_1000 wrote:

左右上下に動かしたいときに
if <key [d v] pressed?> then
change x by (10)
end
ではなくて
change x by ((<key [d v] pressed?> + (<key [a v] pressed?> * (-1))) * (10))
みたいにするとブロックがまとまる
(<key [A v] pressed?> * (-1))
なんて知らないと思い付かないですよね
ioqj
Scratcher
500+ posts

意外と知られていないテクニック集

r_1000 wrote:

change x by ((<key [d v] pressed?> + (<key [a v] pressed?> * (-1))) * (10))
みたいにするとブロックがまとまる
正直どうでもいい話ですが
それだとブロックが少し余計に多いです。
change x by ((<key [d v] pressed?> - <key [a v] pressed?>) * (10))
この方がブロック数が少ないです。
maikurakun_828
Scratcher
100+ posts

意外と知られていないテクニック集

プロフィールのコメント欄にコメントされたときに、「あなたのプロフィール」を押した。だけど、コメントが読み込まれない!

↓こんなときは

ナビゲーションバー(画面上部のバー)の自分のScratch名を押して「プロフィール」を押そう。そうすると、他のコメントも出てくるけど、早く読み込んでくれる!

(消えてる場合は再読み込みをしよう)
U-Y-Scratch
Scratcher
500+ posts

意外と知られていないテクニック集

無駄すぎるテクニック(自分で考えました)
<条件>

<<条件> = [true]>
で代用できる。

Last edited by U-Y-Scratch (July 12, 2025 08:47:44)

suto-risihutokya
Scratcher
1 post

意外と知られていないテクニック集

どうやったら非共有の作品を注目のプロジェクトにできますか?
mochimochiyuu
Scratcher
32 posts

意外と知られていないテクニック集

suto-risihutokya wrote:

どうやったら非共有の作品を注目のプロジェクトにできますか?
やり方ならあるとは思うけど…
な ぜ や ろ う と し て い る
ほんとに教えて
mochimochiyuu
Scratcher
32 posts

意外と知られていないテクニック集

U-Y-Scratch wrote:

無駄すぎるテクニック(自分で考えました)
<条件>

<<条件> = [true]>
で代用できる。
いやまあ…使えますけど…
<[] = []>

<条件>
が入るとわかるなら…まあ、有意義…?

Powered by DjangoBB