Weitere ähnliche Inhalte Ähnlich wie Cocos2d-x(JS) ハンズオン #08「様々な画像描画方法」 (20) Mehr von Tomoaki Shimizu (10) Kürzlich hochgeladen (11) Cocos2d-x(JS) ハンズオン #08「様々な画像描画方法」7. resource.js
var res = {
HelloWorld_png : "res/HelloWorld.png",
Apple_png : "res/apple.png",
Bug_png : "res/bug.png",
Frame_png : "res/frame.png",
Apple_And_Bug_plist : "res/AppleAndBug.plist"
};
11. 画像描画
this._super();
//画面サイズ取得
var size = cc.winSize;
//リンゴの表示
var apple = new cc.Sprite(res.Apple_png);
apple.setPosition(size.width / 3, size.height / 2);
this.addChild(apple);
//虫の表示
var bug = new cc.Sprite(res.Bug_png);
bug.setPosition(size.width * 2 / 3, size.height / 2);
this.addChild(bug);
return true;
15. 同一画像による複数スプライト
this._super();
//画面サイズ取得
var size = cc.winSize;
//50個のリンゴを表示
for (var i = 0; i < 50; i++) {
var x = cc.random0To1() * 960;
var y = cc.random0To1() * 640;
var apple = new cc.Sprite(res.Apple_png);
apple.setPosition(x, y);
this.addChild(apple);
}
return true;
17. 複数スプライト描画
GL calls: 1
異なる画像を表示するとコール数が増えるが、
同一画像の場合は、コール数は増えない
Cocos2d-x v3.xよりバッチノードが自動で適
用されるようになったため
20. テクスチャに使用する画像
画像を画面に表示するとき、画像はビデオメモリ上
(VRAM)に展開される
GPUメモリ上に展開される画像のサイズ
2のべき乗
1, 2, 4, 8, 16, 32, 64, 128,
256, 512, 1024, 2048, 4096, …
例:
画像 960px * 640px
VRAM上 1024px * 1024px
25. テクスチャアトラスによる描画
this._super();
//画面サイズ取得
var size = cc.winSize;
//テクスチャアトラスの読み込み
cc.spriteFrameCache.addSpriteFrames(res.AppleAndBug_plist);
//リンゴの表示
var apple = new cc.Sprite();
apple.initWithSpriteFrameName("apple.png");
apple.setPosition(size.width / 3, size.height / 2);
this.addChild(apple);
//虫の表示
var bug = new cc.Sprite();
bug.initWithSpriteFrameName("bug.png");
bug.setPosition(size.width * 2 / 3, size.height / 2);
this.addChild(bug);
return true;
31. 画像拡大
this._super();
//画面サイズ取得
var size = cc.winSize;
//フレームの表示
var frame = new cc.Sprite(res.Frame_png);
frame.setPosition(size.width / 2, size.height / 2);
frame.setScale(40, 10);
this.addChild(frame);
return true;
38. Sprite Polygonクラス
this._super();
//画面サイズ取得
var size = cc.winSize;
//リンゴの表示
var pinfo1 = jsb.AutoPolygon.generatePolygon(res.Apple_png);
var apple = new cc.Sprite(pinfo1);
apple.setPosition(size.width / 3, size.height / 2);
this.addChild(apple);
//虫の表示
var pinfo2 = jsb.AutoPolygon.generatePolygon(res.Bug_png);
var bug = new cc.Sprite(pinfo2);
bug.setPosition(size.width * 2 / 3, size.height / 2);
this.addChild(bug);
return true;