Open memePushpendu opened 7 years ago
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;
if(Ninja != undefined){
world.removeBody(ninja);
}
same output
Can i use pixi renderer in here?