ngCore 工程创建步骤

参见文档:

https://developer.mobage.com/en/resources/getting_started


创建工程的步骤在以上链接中有详细步骤,现总结下:

1. 建议在ngcore的根目录创建工程目录products,里面放置工程。

2. 在products下创建工程HelloWorldAllen,工程目录如下




其中Code存放代码,这个简单示例只有一个Main.js

Content下存放资源文件,如图片,字体文件等

NGCore是库文件,可以在NGCore 的sdk跟目录copy过来。

manifest.json是清单文件,指定了程序所要用到的资源。

configuration.json为配置文件,我这里直接从ngcore sdk的示例中copy过来。

以上主要需要编辑的文件代码清单如下:

Main.js

var Color = require('../NGCore/Client/Core/Color').Color;
var GLView = require('../NGCore/Client/UI/GLView').GLView;
var LayoutEmitter = require('../NGCore/Client/Device/LayoutEmitter').LayoutEmitter;
var Point = require('../NGCore/Client/Core/Point').Point;
var Root = require('../NGCore/Client/GL2/Root').Root;
var Size = require('../NGCore/Client/Core/Size').Size;
var Sprite = require('../NGCore/Client/GL2/Sprite').Sprite;
var Text = require('../NGCore/Client/GL2/Text').Text;
//var Bank = require('../NGCore/Client/Bank').Bank;
//var Social = require('../NGCore/Client/Social').Social;


function addBackgroundImage(){
var size = new Size(LayoutEmitter.getWidth(),
   LayoutEmitter.getHeight());
var position = new Point(size.getWidth() / 2,
   size.getHeight() / 2);
var background = new Sprite().setImage('Textures/background.png', size).setPosition(position);
Root.addChild(background);
}


function addText() {
 var size = new Size(LayoutEmitter.getWidth(),
   LayoutEmitter.getHeight());


 var color = new Color(0, 0.29, 0.64);  // dark blue
 var fontSize = Math.round(size.getWidth() / 10);
 var position = new Point(size.getWidth() / 2,
   size.getHeight() / 2);


 var helloWorld = new Text().
   setText('Hello World').
   setColor(color).
   setFontSize(fontSize).
   setPosition(position);


 Root.addChild(helloWorld);
}


function main(){
 var glView = new GLView();
 glView.setFrame(0, 0, LayoutEmitter.getWidth(),
   LayoutEmitter.getHeight());

function onLoad() {
   addBackgroundImage();
   addText();
   console.log('Finished displaying "Hello World"!');
 }


glView.setOnLoad(onLoad);
glView.setActive(true);
}

manifest.json

{
"code": [
"./NGCore/Client/Legacy.js",
"./Code/Main.js"
],

"textures": [
"./Content/*.png"
],
    
    "other": [
        "./Content/Fonts/*.ttf",
        "./Content/Fonts/*.otf"
    ]
}


3.cd到ngcore sdk根目录,运行 make server,然后在浏览器中输入示例的路径就可以预览示例程序,如本例在chrome中输入(我程序的目录路径):

http://localhost:8002/Samples/HelloWorldAllen/



你可能感兴趣的:(ngCore 工程创建步骤)