autojsスマートボール、画面が壊れています

ゴールデン ストーン プロジェクトの最初のチャレンジにサインアップしました - 賞金プール 100,000 を共有します。これは私の 8 回目の記事です。クリックしてイベントの詳細を表示します

Uncle Tooth チュートリアルはシンプルでわかりやすい

効果

アイデア

スマート アイランドはフローティング ウィンドウです。特定の機能は実行せず、表面処理のみを行います。

したがって、フローティング ウィンドウを作成するだけです。

フローティング ウィンドウはユーザーの操作を妨げることができないため、ボールを描画するときは別のフローティング ウィンドウを使用する必要があります。

フローティング ウィンドウはクリック イベントに応答せず、描画するだけです。

したがって、合計で 2 つのフローティング ウィンドウがあります。

  • 通知バー
  • フルスクリーンワン

スマートアイランドフローティングウィンドウ

xml コード

this.window = floaty.rawWindow(
    <card id="root" cardCornerRadius="{{cardCornerRadius}}px" gravity="center" w="{{ windowWidth }}px" h="{{ windowHeight }}px" cardBackgroundColor="#000000">
        <text id="count" w="*" gravity="center" textColor="#ff000f" textSize="{{textSize}}px">
            0
        </text>
    </card>
);
复制代码

各中解像度で一貫した外観を実現するために、幅と高さが最初に計算され、次に UI が表示されます。

this.config = {
    width: {
        ratio: 0.2,
    },
    height: {
        ratio: 1,
    },
};
this.config.width = parseInt(device.width * this.config.width.ratio);
this.config.height = parseInt(STATUS_BAR_HEIGHT * this.config.height.ratio);
复制代码

UI スレッドで変数の値を取得するには、変数をバインドする必要があります。

runtime.ui.bindingContext.windowWidth = windowWidth;
复制代码

覚えるのに長すぎる場合は、vscode にコード スニペットを追加できます。

"runtime.ui.bindingContext.windowWidth=windowWidth": {
    "scope": "javascript,typescript",
    "prefix": "bindui",
    "body": ["runtime.ui.bindingContext.windowWidth=windowWidth;"],
    "description": "runtime.ui.bindingContext.windowWidth=windowWidth"
  },
复制代码

入力後、bindui と入力すると、このコード行をすばやく入力できます

runtime.ui.bindingContext.windowWidth = windowWidth;
复制代码

前のチュートリアルでカプセル化されたコードを使用して、フローティング ウィンドウを任意に移動できます。

makeWindowMoveable
复制代码

最後のチュートリアルは次のとおりです: 単語を翻訳するための autojs フローティング ウィンドウ

www.yuque.com/yashujs/bfu…

スマートアイランドが完成したので、スマートボールを描きましょう

スマートボール

スマート アイランドをクリックすると、スマート ボールが表示され、フルスクリーンのフローティング ウィンドウにスマート ボールが描画されます

全画面フローティング ウィンドウ

これは以前のフルスクリーン方式です

function fullScreen(window) {
    let LayoutParams = android.view.WindowManager.LayoutParams;
    let mWindow = getClassField(window, "mWindow");
    log(mWindow); // com.stardust.autojs.core.floaty.RawWindow@26b1509
    let params = mWindow.getWindowLayoutParams();
    //设置全屏悬浮窗
    params.flags |= LayoutParams.FLAG_FULLSCREEN | LayoutParams.FLAG_LAYOUT_IN_SCREEN | LayoutParams.FLAG_LAYOUT_NO_LIMITS;
    ui.run(function () {
        mWindow.updateWindowLayoutParams(params);
        window.setSize(device.width, device.height);
    });
}
复制代码

今すぐフルスクリーン

window.setSize(-1, -1);
复制代码

\

スマートボールがゆっくり出現

スマートアイランドをクリックするとスマートボールがゆっくり出現

ボールを描くには、canvas の drawCircle を使用します

canvas.drawCircle(ballData.centerX, ballData.centerY, ballData.radius, this.paint);
复制代码

ボールが下に移動します。ValueAnimator を使用してモニターを設定し、ボールの中心の高さを変更できます。

this.valueAnimator = ValueAnimator.ofFloat(beginValue, endValue);
this.valueAnimator.setDuration(1000);
this.valueAnimator.addUpdateListener({
    onAnimationUpdate: function (animation) {
        let value = animation.getAnimatedValue();
        ballData.centerY = value;
    },
});
复制代码

行を追加

canvas.drawLine(islandWindowRect.centerX, islandWindowRect.centerY, ballData.centerX, ballData.centerY, this.paint);
复制代码

\

ボールはどこへ行く

ここでは、2 つの ValueAnimators を追加して、ボールの動きの XY を制御しています。

this.valueAnimatorX = ValueAnimator.ofFloat(beginValueX, endValueX, beginValueX);
this.valueAnimatorY = ValueAnimator.ofFloat(beginValueY, endValueY, beginValueY);
复制代码

同時に実行するアニメーション

this.animatorSet = new AnimatorSet();
this.animatorSet.playTogether(this.valueAnimatorX, this.valueAnimatorY);
this.animatorSet.setDuration(300);
复制代码

指を押し上げた後にアニメーションをトリガーする

switch (event.getAction()) {
    case event.ACTION_DOWN:
        return true;
    case event.ACTION_MOVE:
        return true;
    case event.ACTION_UP:
        let touchPoint = {
            x: event.getRawX(),
            y: event.getRawY(),
        };
        that.updateTouchValueAnimator(touchPoint);
        that.animatorSet.start();
        return true;
}
复制代码

\

壊れた画面効果

ps を使用して割れたガラスの絵を作成するか、ランダムに選択した絵をいくつか作成して描画します

for (var i = 0; i < len; i++) {
    let glass = this.glasses[i];
    canvas.drawBitmap(this.glassBitmap, glass.x - this.glassBitmapHalfWidth, glass.y - this.glassBitmapHalfHeight, this.paint);
}
复制代码

テキストチュートリアル、音が聞こえない場合は効果音を追加しません

周囲

デバイス: Mi 11pro
Android バージョン: 12
Thunderbolt エミュレーター: 9.0.17
Android バージョン: 9
Autojs バージョン: 9.2.13

有名な名言

アイデアは最も重要で、その他の Baidu、bing、stackoverflow、github、Android のドキュメント、autojs のドキュメント、そして最後に質問するグループ --- Uncle Tooth Tutorial

声明

コンテンツの一部はインターネットから提供されています. このチュートリアルは学習のみを目的としており、他の目的で使用することは禁止されています.

WeChat パブリック アカウント歯のおじさんのチュートリアル

おすすめ

転載: juejin.im/post/7148025147738292237