Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load sprites images and create a movement like run or jump #4

Open
memePushpendu opened this issue Aug 19, 2017 · 3 comments

Comments

@memePushpendu
Copy link

memePushpendu commented Aug 19, 2017

Can i use pixi renderer in here?

@memePushpendu
Copy link
Author

MY CODE

var Physics = require("nativescript-physics-js");
var platform = require("platform");

var ninja;
/** basic image sources **/
var runSprites = [
    '~/images/sprites/ninja/Run__000.png',
    '~/images/sprites/ninja/Run__001.png',
    '~/images/sprites/ninja/Run__002.png',
    '~/images/sprites/ninja/Run__003.png',
    '~/images/sprites/ninja/Run__004.png',
    '~/images/sprites/ninja/Run__005.png',
    '~/images/sprites/ninja/Run__006.png',
    '~/images/sprites/ninja/Run__007.png',
    '~/images/sprites/ninja/Run__008.png',
    '~/images/sprites/ninja/Run__009.png'
];

var init = false;

var count;

var container;
var metaText;

var world;

function doFullscreen() {
    require('application').android.startActivity.getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
}

function pageLoaded(args) {
    // Prevent double initialization
    if (init) {
        return;
    }

    count = 0;

    doFullscreen();

    var screenHeight = platform.screen.mainScreen.heightPixels;
    var screenWidth = platform.screen.mainScreen.widthPixels;

    // Get references to container and meta-info views
    var page = args.object;
    container = page.getViewById("container");
    metaText = page.getViewById("meta");

    container.height = 360;
    container.width = 640;


    world = Physics();
    var renderer = Physics.renderer('ns', {
        container: container,
        metaText: metaText,
        meta: true
    });

    world.add(renderer);

    // Add bodies

    // Start ticking...
    world.on('step', function () {
        console.log(count);

        addNinja(runSprites[count])
            .then(function (success) {
                world.render();
                count++;
                if (count == 10) {
                    count = 0;
                }
            });
    });

    setInterval(function () { world.step(Date.now()); }, 1000);  // refreshing world
}
exports.pageLoaded = pageLoaded;

function addNinja(image) {
    return new Promise(function (resolve, reject) {

        if(ninja != undefined){
           world.removeBody(ninja);
        }

        ninja = Physics.body('circle', {
            x: 70,
            y: 280,
            radius: 35,
            styles: { image: image }
        });

        world.add(ninja);
        Ninja = ninja;
        resolve(ninja);
    });
}


function triggerGame(args) {
    switch (args.direction) {
        case 1:
            console.log("right");
            break;
        case 2:
            console.log("left");
            break;
        case 4:
            console.log("up");
            break;
        case 8:
            console.log("down");
            break;
        default:
            console.log("default swipe");
    }
}

exports.triggerGame = triggerGame;

@memePushpendu
Copy link
Author

memePushpendu commented Aug 19, 2017

@memePushpendu
Copy link
Author

 if(Ninja != undefined){
       world.removeBody(ninja);
    }

same output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants