An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

33
An Introducton to Game Programming with Flash 1. An Introducton to Flash and Acton Script 3

description

 

Transcript of An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Page 1: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

An Introducton to Game Programming with Flash

1. An Introducton to Flash and Acton Script 3

Page 2: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Resources

● GitHub (https://github.com/krzysztof-o/epi-wdpg)

● Slideshare (http://www.slideshare.net/krzysztofopalka/)

● Recommended books● Moock C., Essental ActonScript 3.0, O'Reilly Media, 2007● Sanders W., Cumaranatunge Ch., ActonScript 3.0 Design Patterns, O'Reilly Media, 2007● Imbert T., Introducing Starling, O'Reilly Media, 2012

● Recommended websites● http://gaming.adobe.com/● http://www.adobe.com/devnet/games.html● http://help.adobe.com/en_US/FlashPlatform/reference/actonscript/3/index.html● http://www.bytearray.org/

Page 3: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Why browser games?

● Low entry barriers

● Easy distributon

● Integraton with social networks

● Real tme analytcs

● Contnuous Deployment is possible

● Big Players do browser games

Page 4: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3
Page 5: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Choosing technology

VS.

Page 6: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

WebGL

Canvas CSS3

Audio

Video

Local Storage Sockets

Open Web

Page 7: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Open Web

● Cross-platform

● Dynamic growth

● Do not rely on mobile app stores

● Client and Server code in JavaScript

● Always bet on JavaScript

● Atwood's Law

Pros Cons

● Lack of tools

● Differences in implementaton

● JavaScript – The World's Most Misunderstood Language

Page 8: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Flex SDK

Adobe AIR Stage3D

Flash Builder

Flash PRO

Flex Framework

Flash Platform

Page 9: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Flash Platform

● Mature technology

● Great tools

● Consistency betweenplatforms

● ActonScript 3

● Mobile apps usingAdobe AIR

Pros Cons

● Doesn't work in mobile browsers

● Bad PR

● Unknown future

Page 10: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3
Page 11: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Memory Game

Page 12: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

git clone git://github.com/krzysztof-o/epi-wdpg.git

Memory Game

Page 13: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Variables and constants

var myString:String = "Hello World!"; var myNumber:Number = 589.25; var myInt:int = -5; var myUint:uint = 5; var isClicked:Boolean = true; const MARGIN:Number = 10;

Page 14: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Embeding assetsgit checkout v1.2

[Embed(source="assets.swf", symbol="card")] private const BACKGROUND:Class;

var background:Sprite = new BACKGROUND();

Page 15: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

AssetsSprite ”background”

980px

580px

Page 16: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

AssetsMovieClip ”card”

1. frame 2. frame 4. frame 3.frame 5. frame

Page 17: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Sprite vs. MovieClip

Page 18: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Display List

addChild(background); addChildAt(background, 0); getChildAt(0); //background getChildIndex(background); //0 removeChild(background);

Page 19: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Display List

Page 20: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Coordinates system(0,0) x

y stage

Page 21: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Coordinates system(0,0) x

y stage

Page 22: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Coordinates system(0,0) x

y

stage

(x=50,y=50)child

Page 23: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Coordinates system(0,0) x

y

stage

(x=0,y=0)child

(x=50,y=50)container

Page 24: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Loops

for (var i:uint = 0; i < 10; i++) {

trace(i); } var j:uint = 0; while(j < 10) {

trace(j); j++;

}

Page 25: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Events

card.addEventListener(MouseEvent.CLICK, onClick);

private function onClick(event:MouseEvent):void { trace("clicked!"); }

dispatchEvent(new Event("makeSomeNoise"));

Page 26: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Event bubbling

Page 27: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Observer pattern

Page 28: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Observer pattern

Page 29: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Arrays, Vectors, Dictonaries

var myArray:Array = [1, "2nd element"]; myArray.push(10); myArray.push("Hello World"); myArray.push({name: "Jan", age: 37}); myArray[3]; //"Hello World" var myVector:Vector.<int> = new Vector.<int>(); myVector.push(5); myVector.push(10); myVector[2]; //10 var myDictionary:Dictionary = new Dictionary(); myDictionary["someKey"] = myVector; myDictionary["someKey"][2]; //10

Page 30: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Array sortng

myArray.sort(); myArray.sort(Array.DESCENDING | Array.CASEINSENSITIVE); myArray.sortOn("depth"); myArray.sort(randomSort);

private function randomSort(a:*, b:*):Number {

if (Math.random() < 0.5) return -1; else return 1; }

Page 31: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Conditonal statements

if(delta < 0) {

trace("no roots") } else if(delta == 0) { trace("one root") } else {

trace("two roots") }

var absolute:Number = value >= 0 ? value : -value;

Page 32: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

TweenMax

TweenMax.to(card,.5, {

scaleX: 1.2, scaleY: 1.2, delay: 1, ease: Elastic.easeIn, onComplete: completeFunction

});

Page 33: An Introduction to Game Programming with Flash: An Introduction to Flash and Action Script 3

Tasks

● Blocking card choice during tmeout

● Blocking picking up the same card twice

● Enlarging card after mouse over

● Disappearing animaton of correctly chosen cards

● 3D Card rotaton (hint: TweenMax, rotationY, onUpdate)