ngCore 工程建立步驟

來源:互聯網
上載者:User

參見文檔:

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/

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.