32
© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential. Flashを使った PC、Android、iOS 向けに GPU アクセラレーション対応の 2Dゲーム開発 Andy Hall Adobe Japan

CEDEC2012 Starling開発

Embed Size (px)

DESCRIPTION

Flashを使ったPC、Android、iOS向けにハードウェアアクセラレーション対応の2Dゲーム開発

Citation preview

Page 1: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Flashを使った PC、Android、iOS 向けに

GPU アクセラレーション対応の 2Dゲーム開発

Andy Hall Adobe Japan

Page 2: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Andy Hall Game Evangelist

Adobe Japan

アンディ ホール ゲームエバンジェリスト アドビ システムズ 株式会社 @fenomas

Page 3: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Agenda

1. Flash、ゲームの背景的な話 2. Stage3D、AGALについて 3. Starlingについて 4. 開発に飛び込もう

Page 4: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Flash and Games

Page 5: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why Flash?

• パフォーマンス • ツール • リーチ

Page 6: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why Flash?

• パフォーマンス • ツール • リーチ

サイレント 自動アップデート

ユーザ数: 4億人 (!!!)

Page 7: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why Flash?

• パフォーマンス • ツール • リーチ

Wii 95.56M

PS3 63.9M

Xbox 360 67.2M

400M

sales numbers as of April-June 2012. Source: Wikipedia

サイレント 自動アップデート

ユーザ数: 4億人 (!!!)

Page 8: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

採用状況

9 of 10 top Facebook games

Angry Birds Friends (Rovio)

Ruby Blast (Zynga)

Page 9: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

About Flash

• Flash is: • 柔軟で応用が利く • クロスプラットフォーム • モバイルに最適(Android、iOS 他)

• Flash isn’t:

• 「ドラッグ・ドロップでゲーム!」 • 完全ネイティブパフォーマンス

Page 10: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Why the GPU?

Tablets, mobiles, retina displays. Pushing pixels through software isn’t an option.

Page 11: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Stage3D

Display List

3D Video

Vector

Page 12: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Stage3D

GPU

OpenGL or DirectX

Stage3D (AGAL)

Flash コンテンツ (ActionScript)

シェーダー パイプライン

Page 13: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

AGALとは

m44 op, va0, vc0 dp4 op.x, va0, vc0 dp4 op.y, va0, vc1 dp4 op.z, va0, vc2 dp4 op.w, va0, vc3 m44 op, va0, vc0 mov v0, va1

(ヒトリデハキケンジャ!)

Page 14: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

import starling.display.Sprite; var hero:Sprite = new Sprite(); hero.x = 200; hero.y = 200; addChild(hero);

(コレヲ サズケヨウ! )

Starlingの場合

Page 15: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Stage3D ライブラリー • オフィシャルライブラリー (free, open source):

• Starling (2D)

• Away3D

• ニーズによって他にも様々…

N2D2 Genome2D

Page 16: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Starling

Flash Player Display List API

(AS3)

Starling (AS3)

Sparrow フレームワーク (ObjC)

Page 17: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Starling + Stage3D

GPU

OpenGL or DirectX

Stage3D (AGAL)

Flash コンテンツ (ActionScript)

Starling

Page 18: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Starlingが送ること

• Starling gives you: • 生産性 • 親しみのある習得の早いAPI • 拡張性 • 活発的なコミュニティー

• Starling doesn’t give you: • GPUは何ぞよ、と気にしなくて良いほど

の安全性 • GPUには優しく!

Page 19: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

コードを見せろってば!

Page 20: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

starling.display.*

Starling core API

starling.events.EventDispatcher

DisplayObject

DisplayObjectContainer Quad

Image

MovieClip

Button

Sprite

Stage

TextField

Page 21: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

starling.display.*

Starling core API

starling.events.EventDispatcher

DisplayObject

DisplayObjectContainer Quad

Image

MovieClip

Button

Sprite

Stage

TextField

Page 22: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Quad • Just vertices with a color but no texture • Color interpolated on the GPU • Simple primitive

Example :

q = new Quad(200, 200); q.setVertexColor(0, 0x000000); q.setVertexColor(1, 0xAA0000); q.setVertexColor(2, 0x00FF00); q.setVertexColor(3, 0x0000FF); addChild (q);

Solid color : q.color = 0x00FF00;

Page 23: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Image • Image is textured quad (extends Quad) • Textures should be uploaded and pooled,

rather than created when needed • State tracking (setTexture – expensive) • Compressed textures Example : // create a texture, then an image var myBitmap:Bitmap = new MyBitmapClass(); var texture:Texture = Texture.fromBitmap(myBitmap); var image:Image = new Image ( texture ); addChild ( image ); Tint : image.color = 0xFF0000;

Page 24: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Sprite • The lightest container available (just like with standard Flash display list)

• Can be flattened, to display a complex tree quickly

• However, all children’s textures need to be in the same texture (or atlas) to see really great performance

Example : // freeze the children container.flatten(); // assign changes to a child

container.child.scaleX = .5; // refresh

container.flatten(); // or unflatten();

Page 25: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

MovieClip • Sprite, with a timeline • A different texture on each frame • Is not a container. • Does not support scripts on frames. • Completely controllable (custom fps,

addFrame, etc).

Example : // retrieve frames from a Flash MC

var frames:Vector.<Texture> = sTextureAtlas.getTextures("running_");

// creates a MovieClip playing at 40fps

mMovie = new MovieClip(frames, 40);

Page 26: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

TextureAtlas

• Packaged sets of sprite sheets • To optimize, make sure GPU calls each use one Atlas

Example : // get all textures with a common prefix

myTextureAtlas.getTextures(“fly_”);

Page 27: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

ではコードを書いてみよう。

Page 28: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

拡張の例

Particle Editor http://onebyonedesign.com/flash/particleeditor/

Page 29: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

Starlingの最適化

• Flatten containers if their contents won’t change: container.flatten();

• Prevent unnecessary touch event handling: container.touchable = false;

• Use object pools: s = pool.getSprite(); pool.returnSprite(s);

Page 30: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

今後のトピック

Adobe Texture Format (ATF) • A compressed texture format created specially

for Stage3D • The player understand ATF

natively, which brings performance benefits

Tools and libraries are coming.

Page 31: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.

[email protected] @fenomas

ご清聴ありがとうございました。

Page 32: CEDEC2012 Starling開発

© 2012 Adobe Systems Incorporated. All Rights Reserved. Adobe Confidential.