Представление SpriteKit в nativescript - PullRequest
0 голосов
/ 03 мая 2019

Можно ли показать экран с Nativescript Я искал в Интернете очень мало информации. Нашел код.

const GameViewController = (UIViewController as any).extend(
{
    get willPopCb() { return this._willPopCb; },
    set willPopCb(x) { this._willPopCb = x; },
    viewDidLoad: function(){
        UIViewController.prototype.viewDidLoad.apply(this, arguments);

        this.view = SKView.alloc().initWithFrame(this.view.bounds);
        if(this.view instanceof SKView){
            const scene = BattlefieldScene.alloc().initWithSize(
                this.view.bounds.size
            );
            scene.view.backgroundColor = UIColor.alloc().initWithRedGreenBlueAlpha(0,1,0,1);

            scene.scaleMode = SKSceneScaleMode.AspectFill;

            this.view.presentScene(scene);
            this.view.showsPhysics = false;
            this.view.ignoresSiblingOrder = true;
            this.view.showsFPS = true;
            this.view.showsNodeCount = true;
        }
    },
    willMoveToParentViewController: function(parent: UIViewController|null){
        if(parent === null){
            if(this.willPopCb){
                this.willPopCb();
            }
        }
    }
},
{
    name: "GameViewController",
    protocols: [],
    exposedMethods: {}
}

);

Теперь не могу понять, как отобразить этот контроллер

Заранее спасибо

1 Ответ

1 голос
/ 03 мая 2019

Попробуйте,

import * as utils from "tns-core-modules/utils/utils";

const gameViewController = GameViewController.alloc().init();
const app = utils.ios.getter(UIApplication, UIApplication.sharedApplication);
app.keyWindow.rootViewController.presentViewControllerAnimatedCompletion(gameViewController, true, null);
...