mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 06:30:38 +00:00
Farewell TypeScript, see you on the other side.
This commit is contained in:
parent
0e55e644a9
commit
09def364c3
995 changed files with 68669 additions and 16019 deletions
|
@ -1,8 +0,0 @@
|
|||
<component name="ProjectDictionaryState">
|
||||
<dictionary name="rich">
|
||||
<words>
|
||||
<w>aabb</w>
|
||||
<w>preload</w>
|
||||
</words>
|
||||
</dictionary>
|
||||
</component>
|
8
Phaser.sublime-project
Normal file
8
Phaser.sublime-project
Normal file
|
@ -0,0 +1,8 @@
|
|||
{
|
||||
"folders":
|
||||
[
|
||||
{
|
||||
"path": "/D/wamp/www/phaser"
|
||||
}
|
||||
]
|
||||
}
|
944
Phaser.sublime-workspace
Normal file
944
Phaser.sublime-workspace
Normal file
|
@ -0,0 +1,944 @@
|
|||
{
|
||||
"auto_complete":
|
||||
{
|
||||
"selected_items":
|
||||
[
|
||||
[
|
||||
"the",
|
||||
"the_terms"
|
||||
],
|
||||
[
|
||||
"load",
|
||||
"loadPuzzleRatings"
|
||||
],
|
||||
[
|
||||
"tr",
|
||||
"true"
|
||||
],
|
||||
[
|
||||
"font-",
|
||||
"font-family"
|
||||
],
|
||||
[
|
||||
"sca",
|
||||
"scaling"
|
||||
],
|
||||
[
|
||||
"Pos",
|
||||
"Position"
|
||||
],
|
||||
[
|
||||
"Po",
|
||||
"Position"
|
||||
],
|
||||
[
|
||||
"to",
|
||||
"toString"
|
||||
],
|
||||
[
|
||||
"phas",
|
||||
"phaserSpace"
|
||||
],
|
||||
[
|
||||
"cen",
|
||||
"centroid2"
|
||||
],
|
||||
[
|
||||
"set",
|
||||
"setPosition"
|
||||
],
|
||||
[
|
||||
"space",
|
||||
"Space"
|
||||
],
|
||||
[
|
||||
"iter",
|
||||
"iteration"
|
||||
],
|
||||
[
|
||||
"mar",
|
||||
"margin-bottom"
|
||||
],
|
||||
[
|
||||
"font",
|
||||
"font-size"
|
||||
],
|
||||
[
|
||||
"puzzle",
|
||||
"puzzle_id"
|
||||
],
|
||||
[
|
||||
"cre",
|
||||
"createSprite"
|
||||
],
|
||||
[
|
||||
"displ",
|
||||
"displaySummary"
|
||||
],
|
||||
[
|
||||
"strr",
|
||||
"strrpos"
|
||||
],
|
||||
[
|
||||
"file",
|
||||
"filename"
|
||||
],
|
||||
[
|
||||
"save",
|
||||
"save_result"
|
||||
],
|
||||
[
|
||||
"proces",
|
||||
"processFile"
|
||||
],
|
||||
[
|
||||
"single",
|
||||
"single_file"
|
||||
],
|
||||
[
|
||||
"all",
|
||||
"all_files"
|
||||
],
|
||||
[
|
||||
"sing",
|
||||
"single_file"
|
||||
],
|
||||
[
|
||||
"bac",
|
||||
"background-color"
|
||||
],
|
||||
[
|
||||
"text",
|
||||
"text-decoration"
|
||||
],
|
||||
[
|
||||
"va",
|
||||
"vars"
|
||||
],
|
||||
[
|
||||
"con",
|
||||
"consts"
|
||||
],
|
||||
[
|
||||
"c",
|
||||
"consts"
|
||||
],
|
||||
[
|
||||
"class",
|
||||
"classname"
|
||||
],
|
||||
[
|
||||
"clas",
|
||||
"classname"
|
||||
],
|
||||
[
|
||||
"output",
|
||||
"output_file"
|
||||
],
|
||||
[
|
||||
"str_re",
|
||||
"str_replace"
|
||||
],
|
||||
[
|
||||
"input",
|
||||
"input_dir"
|
||||
],
|
||||
[
|
||||
"back",
|
||||
"background-size"
|
||||
],
|
||||
[
|
||||
"wait",
|
||||
"waitingHelpscreen"
|
||||
],
|
||||
[
|
||||
"juke",
|
||||
"jukebox"
|
||||
],
|
||||
[
|
||||
"jukeb",
|
||||
"jukeboxPP"
|
||||
],
|
||||
[
|
||||
"start",
|
||||
"startTheEngines"
|
||||
],
|
||||
[
|
||||
"star",
|
||||
"startPause"
|
||||
],
|
||||
[
|
||||
"Beak",
|
||||
"BeakerGameStartGameHook"
|
||||
],
|
||||
[
|
||||
"Bea",
|
||||
"BeakerGameStartGameHook"
|
||||
],
|
||||
[
|
||||
"crea",
|
||||
"createHD"
|
||||
],
|
||||
[
|
||||
"whee",
|
||||
"wheelUp"
|
||||
],
|
||||
[
|
||||
"whe",
|
||||
"wheelSpeed"
|
||||
],
|
||||
[
|
||||
"cr",
|
||||
"currentDelivery"
|
||||
],
|
||||
[
|
||||
"let",
|
||||
"letter1"
|
||||
],
|
||||
[
|
||||
"g",
|
||||
"getLetterData"
|
||||
],
|
||||
[
|
||||
"sc",
|
||||
"scanIt"
|
||||
],
|
||||
[
|
||||
"pro",
|
||||
"progressFill"
|
||||
],
|
||||
[
|
||||
"up",
|
||||
"update"
|
||||
],
|
||||
[
|
||||
"deli",
|
||||
"delivery1"
|
||||
],
|
||||
[
|
||||
"ju",
|
||||
"justPressed"
|
||||
],
|
||||
[
|
||||
"de",
|
||||
"delivery1"
|
||||
],
|
||||
[
|
||||
"del",
|
||||
"delivery"
|
||||
],
|
||||
[
|
||||
"is",
|
||||
"isShowingDelivery"
|
||||
],
|
||||
[
|
||||
"he",
|
||||
"height"
|
||||
],
|
||||
[
|
||||
"fc",
|
||||
"function"
|
||||
],
|
||||
[
|
||||
"roun",
|
||||
"roundTimer"
|
||||
],
|
||||
[
|
||||
"drage",
|
||||
"dragEndTime"
|
||||
],
|
||||
[
|
||||
"drags",
|
||||
"dragStartTime"
|
||||
],
|
||||
[
|
||||
"drag",
|
||||
"dragStartY"
|
||||
],
|
||||
[
|
||||
"_id",
|
||||
"_idCount"
|
||||
],
|
||||
[
|
||||
"_oncom",
|
||||
"_onCompleteCallbackFired"
|
||||
],
|
||||
[
|
||||
"round",
|
||||
"roundComplete"
|
||||
],
|
||||
[
|
||||
"scr",
|
||||
"scrollUp"
|
||||
],
|
||||
[
|
||||
"shad",
|
||||
"shadowFloatY"
|
||||
],
|
||||
[
|
||||
"pau",
|
||||
"pauseScreen"
|
||||
],
|
||||
[
|
||||
"ne",
|
||||
"nextRound"
|
||||
],
|
||||
[
|
||||
"sha",
|
||||
"shadow"
|
||||
],
|
||||
[
|
||||
"flo",
|
||||
"floatOff"
|
||||
],
|
||||
[
|
||||
"st",
|
||||
"startY"
|
||||
],
|
||||
[
|
||||
"pip",
|
||||
"piplin1"
|
||||
],
|
||||
[
|
||||
"tw",
|
||||
"tween"
|
||||
],
|
||||
[
|
||||
"rou",
|
||||
"round"
|
||||
],
|
||||
[
|
||||
"time",
|
||||
"timeToShine"
|
||||
],
|
||||
[
|
||||
"shado",
|
||||
"shadowY"
|
||||
],
|
||||
[
|
||||
"shi",
|
||||
"shine"
|
||||
],
|
||||
[
|
||||
"shin",
|
||||
"shineY"
|
||||
],
|
||||
[
|
||||
"sh",
|
||||
"shineY"
|
||||
],
|
||||
[
|
||||
"pp",
|
||||
"piplin1"
|
||||
],
|
||||
[
|
||||
"setup",
|
||||
"setupRound"
|
||||
],
|
||||
[
|
||||
"leaf",
|
||||
"leafX"
|
||||
],
|
||||
[
|
||||
"rust",
|
||||
"rustleOut"
|
||||
],
|
||||
[
|
||||
"rus",
|
||||
"rustleTimer"
|
||||
],
|
||||
[
|
||||
"lea",
|
||||
"leaves"
|
||||
],
|
||||
[
|
||||
"hit",
|
||||
"hitContext"
|
||||
],
|
||||
[
|
||||
"ol",
|
||||
"oldY"
|
||||
],
|
||||
[
|
||||
"old",
|
||||
"oldX"
|
||||
],
|
||||
[
|
||||
"rot",
|
||||
"rotation"
|
||||
],
|
||||
[
|
||||
"ro",
|
||||
"rotation"
|
||||
],
|
||||
[
|
||||
"l",
|
||||
"leaves"
|
||||
],
|
||||
[
|
||||
"pi",
|
||||
"piplin2"
|
||||
],
|
||||
[
|
||||
"game",
|
||||
"gameButton2"
|
||||
],
|
||||
[
|
||||
"pl",
|
||||
"playGame"
|
||||
],
|
||||
[
|
||||
"mouse",
|
||||
"mouseEnabled"
|
||||
],
|
||||
[
|
||||
"first",
|
||||
"first_time_online"
|
||||
],
|
||||
[
|
||||
"use",
|
||||
"useWebAudio"
|
||||
],
|
||||
[
|
||||
"web",
|
||||
"webAudioSupported"
|
||||
],
|
||||
[
|
||||
"pop",
|
||||
"poppedTotal"
|
||||
],
|
||||
[
|
||||
"fn",
|
||||
"function"
|
||||
],
|
||||
[
|
||||
"bubb",
|
||||
"bubbleSize"
|
||||
],
|
||||
[
|
||||
"bub",
|
||||
"bubbleMaxY"
|
||||
],
|
||||
[
|
||||
"sele",
|
||||
"selectGame"
|
||||
],
|
||||
[
|
||||
"gameb",
|
||||
"gameButton1"
|
||||
],
|
||||
[
|
||||
"selec",
|
||||
"selectScreen"
|
||||
],
|
||||
[
|
||||
"pla",
|
||||
"playButton"
|
||||
],
|
||||
[
|
||||
"titl",
|
||||
"titleScreen"
|
||||
],
|
||||
[
|
||||
"tit",
|
||||
"titleScreen"
|
||||
],
|
||||
[
|
||||
"dr",
|
||||
"drawGridLines"
|
||||
],
|
||||
[
|
||||
"init",
|
||||
"initGame"
|
||||
],
|
||||
[
|
||||
"die",
|
||||
"diveSpeed"
|
||||
],
|
||||
[
|
||||
"wave",
|
||||
"waveY"
|
||||
],
|
||||
[
|
||||
"dive",
|
||||
"diveCanvas"
|
||||
],
|
||||
[
|
||||
"wa",
|
||||
"waveY"
|
||||
],
|
||||
[
|
||||
"di",
|
||||
"diveContext"
|
||||
],
|
||||
[
|
||||
"divec",
|
||||
"diveContext"
|
||||
],
|
||||
[
|
||||
"wavet",
|
||||
"waveTween1"
|
||||
],
|
||||
[
|
||||
"moveb",
|
||||
"moveBoatDown"
|
||||
],
|
||||
[
|
||||
"move",
|
||||
"moveBoatLeft"
|
||||
],
|
||||
[
|
||||
"boat",
|
||||
"boatTween"
|
||||
],
|
||||
[
|
||||
"fish",
|
||||
"fishLeft"
|
||||
],
|
||||
[
|
||||
"get",
|
||||
"getElementById"
|
||||
],
|
||||
[
|
||||
"fill",
|
||||
"fillStyle"
|
||||
],
|
||||
[
|
||||
"ist",
|
||||
"isTablet"
|
||||
],
|
||||
[
|
||||
"image",
|
||||
"imageLoadComplete"
|
||||
],
|
||||
[
|
||||
"gain",
|
||||
"gainNode"
|
||||
]
|
||||
]
|
||||
},
|
||||
"buffers":
|
||||
[
|
||||
],
|
||||
"build_system": "",
|
||||
"command_palette":
|
||||
{
|
||||
"height": 380.0,
|
||||
"selected_items":
|
||||
[
|
||||
[
|
||||
"pack",
|
||||
"Package Control: Install Package"
|
||||
]
|
||||
],
|
||||
"width": 416.0
|
||||
},
|
||||
"console":
|
||||
{
|
||||
"height": 146.0
|
||||
},
|
||||
"distraction_free":
|
||||
{
|
||||
"menu_visible": true,
|
||||
"show_minimap": false,
|
||||
"show_open_files": false,
|
||||
"show_tabs": false,
|
||||
"side_bar_visible": false,
|
||||
"status_bar_visible": false
|
||||
},
|
||||
"file_history":
|
||||
[
|
||||
"/D/wamp/www/bbc-wolfblood/tsc.txt",
|
||||
"/D/wamp/www/bbc-wolfblood/load.php",
|
||||
"/D/wamp/www/bbc-wolfblood/game.js",
|
||||
"/D/wamp/www/phaser/build/phaser-debug.js",
|
||||
"/D/wamp/www/bbc-wolfblood/embed.js",
|
||||
"/D/wamp/www/phaser/README.md",
|
||||
"/D/wamp/www/bbc-wolfblood/mobile.php",
|
||||
"/D/wamp/www/bbc-wolfblood/load-desktop.php",
|
||||
"/D/wamp/www/bbc-wolfblood/Wolfblood/Wolfblood.csproj",
|
||||
"/D/wamp/www/phaser/Phaser/defToXML.php",
|
||||
"/D/wamp/www/bbc-wolfblood/Phaser/Phaser.csproj",
|
||||
"/D/wamp/www/bbc-wolfblood/mobile-wolfblood-min.js",
|
||||
"/D/wamp/www/elmo/README.md",
|
||||
"/C/Users/rich/AppData/Local/Temp/dtemp-6fdf6c055229125-20.dop/mobile-wolfblood-min.js",
|
||||
"/C/Users/rich/AppData/Local/Temp/dtemp-6fafca055212843-20.dop/wolfblood-min.js",
|
||||
"/C/Users/rich/Desktop/embed.js",
|
||||
"/D/wamp/www/bbc-wolfblood/embed (1).js",
|
||||
"/C/Users/rich/Desktop/Q3.qif",
|
||||
"/C/Users/rich/Downloads/Sheet 52.qif",
|
||||
"/C/Users/rich/Downloads/Sheet 49-51.qif",
|
||||
"/C/Users/rich/Downloads/Sheet 48.qif",
|
||||
"/C/Users/rich/Downloads/Sheets 45-47.qif",
|
||||
"/C/Users/rich/Downloads/Sheet 44.qif",
|
||||
"/C/Users/rich/Downloads/Sheet 40 (May).qif",
|
||||
"/D/wamp/www/bbc-wolfblood/Wolfblood/sha1.js",
|
||||
"/D/webroot/phaser.io/index.html",
|
||||
"/D/wamp/www/phaser/Phaser/Stage.js",
|
||||
"/D/wamp/www/phaser/Tests/physics/temp2.ts",
|
||||
"/D/wamp/www/phaser/Tests/physics/aabb vs aabb 1.js",
|
||||
"/D/wamp/www/phaser/Tests/physics/aabb 1.js",
|
||||
"/D/wamp/www/Proton/example/helloworld/emitter/emitter.html",
|
||||
"/D/wamp/www/Proton/src/emitter/Emitter.js",
|
||||
"/D/wamp/www/Proton/src/initialize/InitializeUtil.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Position.js",
|
||||
"/D/wamp/www/Proton/src/render/BaseRender.js",
|
||||
"/D/wamp/www/Proton/src/render/Renderer.js",
|
||||
"/D/wamp/www/Proton/src/render/CanvasRender.js",
|
||||
"/D/wamp/www/Proton/src/zone/Zone.js",
|
||||
"/D/wamp/www/Proton/src/zone/PointZone.js",
|
||||
"/D/wamp/www/Proton/src/plus/ease.js",
|
||||
"/D/wamp/www/Proton/src/behaviour/RandomDrift.js",
|
||||
"/D/wamp/www/Proton/src/math/ColorSpan.js",
|
||||
"/D/wamp/www/Proton/src/math/NumericalIntegration.js",
|
||||
"/D/wamp/www/Proton/src/math/MathUtils.js",
|
||||
"/D/wamp/www/Proton/src/behaviour/Behaviour.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Velocity.js",
|
||||
"/D/wamp/www/Proton/src/math/Polar2D.js",
|
||||
"/D/wamp/www/Proton/src/behaviour/Scale.js",
|
||||
"/D/wamp/www/Proton/src/behaviour/Repulsion.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Rate.js",
|
||||
"/D/wamp/www/Proton/src/core/Proton.js",
|
||||
"/D/wamp/www/Proton/src/core/Particle.js",
|
||||
"/D/wamp/www/Proton/src/core/ParticlePool.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Life.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Radius.js",
|
||||
"/D/wamp/www/Proton/src/utils/Util.js",
|
||||
"/D/wamp/www/Proton/src/math/Span.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Initialize.js",
|
||||
"/D/wamp/www/Proton/src/initialize/Mass.js",
|
||||
"/D/wamp/www/bbc-jigsaw/sarahandduck/frame.html",
|
||||
"/D/wamp/www/phaser/Tests/phaser.css",
|
||||
"/D/wamp/www/phaser/Docs/tags.txt",
|
||||
"/D/wamp/www/phaser/Docs/docs_server.bat",
|
||||
"/D/wamp/www/phaser/Docs/docs_build.bat",
|
||||
"/D/wamp/www/phaser/Phaser/Phaser.csproj",
|
||||
"/D/wamp/www/phaser/Phaser/yuidoc.json",
|
||||
"/D/wamp/www/phaser/Tests/.gitignore",
|
||||
"/D/wamp/www/phaser/Phaser/_definitions.ts",
|
||||
"/D/wamp/www/bbc-wolfblood/Wolfblood/Registry.js",
|
||||
"/D/wamp/www/phaser/license.txt",
|
||||
"/D/wamp/www/phaser/package.json",
|
||||
"/D/wamp/www/phaser/.gitignore",
|
||||
"/D/wamp/www/phaser/Phaser/Game.js",
|
||||
"/D/wamp/www/phaser/Phaser/Phaser.js",
|
||||
"/D/wamp/www/phaser/Phaser/State.js",
|
||||
"/D/wamp/www/phaser/Phaser/Statics.js",
|
||||
"/D/wamp/www/phaser/Phaser/_definitions.js",
|
||||
"/D/amstrad",
|
||||
"/D/wamp/www/pixi.js/src/pixi/textures/RenderTexture.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/renderers/WebGLRenderer.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/renderers/CanvasRenderer.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/Sprite.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/MovieClip.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/renderers/WebGLBatch.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/InteractionManager.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/Polygon.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/Point.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/Rectangle.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/Outro.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/Intro.js",
|
||||
"/D/wamp/www/phaser/build/make-lib.bat",
|
||||
"/D/wamp/www/phaser/Plugins/CameraFX/Shake.js",
|
||||
"/D/wamp/www/phaser/Plugins/CameraFX/Shadow.js",
|
||||
"/D/wamp/www/phaser/jsdoc.conf.json",
|
||||
"/D/wamp/www/phaser/GruntFile.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/text/BitmapText.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/text/Text.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/extras/Spine.js",
|
||||
"/D/wamp/www/pixi.js/src/pixi/DisplayObject.js",
|
||||
"/D/wamp/www/bbc/firsttimeonline/lib/Core.js",
|
||||
"/D/wamp/www/collision-detection-2d/README.md",
|
||||
"/D/wamp/www/collision-detection-2d/util.js",
|
||||
"/D/wamp/www/collision-detection-2d/math.js",
|
||||
"/D/wamp/www/collision-detection-2d/collision.js",
|
||||
"/D/wamp/www/collision-detection-2d/app.js",
|
||||
"/D/wamp/www/bbc-wolfblood/wolfblood.css",
|
||||
"/D/wamp/www/bbc-wolfblood/desktop.html",
|
||||
"/D/wamp/www/bbc-wolfblood/index_embed.html",
|
||||
"/D/wamp/www/bbc-wolfblood/index.php",
|
||||
"/D/wamp/www/bbc-wolfblood/index_frame.html",
|
||||
"/D/wamp/www/phaser/todo/phaser tests/camera fx/scanlines.js",
|
||||
"/D/wamp/www/phaser/Tests/index.php",
|
||||
"/D/wamp/www/bbc-jigsaw/sarahandduck/embed.js",
|
||||
"/D/wamp/www/bbc-jigsaw/sarahandduck/index.html",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2013/archive.php",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2013/single-games.php",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2013/taxonomy.php",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2013/tpl-games.php",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2013/archives.php",
|
||||
"/D/wamp/www/awasenghi/index.html",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2012/header.php",
|
||||
"/D/webroot/photonstorm.com/wp-content/themes/photonstorm2013/header.php",
|
||||
"/D/wamp/www/bbc-jigsaw/woolyandtig/embed.js",
|
||||
"/D/wamp/www/bbc-jigsaw/woolyandtig/assets/1024/ui.json",
|
||||
"/D/wamp/www/bbc-jigsaw/woolyandtig/wooleyandtig.css",
|
||||
"/D/wamp/www/bbc-jigsaw/woolyandtig/index.html",
|
||||
"/D/wamp/www/bbc-jigsaw/woolyandtig/Wooley and Tig/Wooley and Tig.csproj",
|
||||
"/D/wamp/www/ascale/index.html"
|
||||
],
|
||||
"find":
|
||||
{
|
||||
"height": 34.0
|
||||
},
|
||||
"find_in_files":
|
||||
{
|
||||
"height": 0.0,
|
||||
"where_history":
|
||||
[
|
||||
"D:\\wamp\\www\\phaser\\Tests\\tilemap",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\sprites",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\particles",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\mini games",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\misc",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\input",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\groups",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\collision",
|
||||
"D:\\wamp\\www\\phaser\\Tests\\cameras",
|
||||
"<open files>",
|
||||
"D:\\wamp\\www\\bbc\\firsttimeonline\\src",
|
||||
"D:\\wamp\\www\\bbc\\hideandseek\\src",
|
||||
"D:\\wamp\\www\\clients\\bitecp\\lib\\game",
|
||||
"D:\\wamp\\www\\numtums\\swipetum\\src"
|
||||
]
|
||||
},
|
||||
"find_state":
|
||||
{
|
||||
"case_sensitive": false,
|
||||
"find_history":
|
||||
[
|
||||
"Maze",
|
||||
"Include=\"",
|
||||
"=",
|
||||
"Fixed",
|
||||
"wolfblood",
|
||||
"index.php",
|
||||
"unrated",
|
||||
"UNRATED",
|
||||
"setAll",
|
||||
"Game.Sound",
|
||||
"unlock",
|
||||
"pause",
|
||||
".value",
|
||||
".pause",
|
||||
"noteOn",
|
||||
"refreshBuffer",
|
||||
".src",
|
||||
"line",
|
||||
"onAlpha",
|
||||
"bunny",
|
||||
"bunnies",
|
||||
"bunny",
|
||||
"write",
|
||||
"step",
|
||||
"shapes",
|
||||
"].",
|
||||
"hapes",
|
||||
"verts",
|
||||
"transform",
|
||||
"position",
|
||||
"Manager",
|
||||
"position",
|
||||
"solveVelocityConstraints",
|
||||
"false",
|
||||
"position",
|
||||
"p",
|
||||
"ju",
|
||||
"\n ",
|
||||
"position",
|
||||
"staticBody",
|
||||
"stepCount",
|
||||
"stats =",
|
||||
"frameRateHz",
|
||||
"collision",
|
||||
"ready",
|
||||
"runFrame",
|
||||
" Manager.write('findContactSolver. Length: ' + this.contactSolvers.length);\nfindContact",
|
||||
"postSolve",
|
||||
"gravity",
|
||||
"runFrame",
|
||||
"onClickedPlayer",
|
||||
"step",
|
||||
"Manager",
|
||||
"solveVelocity",
|
||||
"velocitySolver",
|
||||
"initSolve",
|
||||
"step",
|
||||
"contactSolverArr",
|
||||
"add",
|
||||
"findContact",
|
||||
"contactSolvers",
|
||||
"add",
|
||||
"norma",
|
||||
"saveSceneToServer",
|
||||
"console",
|
||||
"saveSceneToServer",
|
||||
"drawBox",
|
||||
"drawBodyShape",
|
||||
"scale",
|
||||
"damping",
|
||||
"gravity",
|
||||
"timeDelta",
|
||||
" for (var i = 0; i <= 10; i++) {\n var body = new Body(Body.DYNAMIC, new vec2(-6 + i * 1.2, 8));\n var shape = new ShapeCircle(0, 0, 0.4);\n shape.e = i / 10;\n shape.u = 1.0;\n shape.density = 1;\n body.addShape(shape);\n body.resetMassData();\n space.addBody(body);\n }\n",
|
||||
"step",
|
||||
"velocityIterations",
|
||||
"_circle2Circle",
|
||||
"black",
|
||||
"this.parent",
|
||||
" if (myGame.stage.fullscreen.isLandscape == true)\n {\n pic1.visible = true;\n pic2.visible = false;\n }\n else\n {\n pic2.visible = true;\n pic1.visible = false;\n }\n",
|
||||
"mouseScaleX",
|
||||
"rotateDiv",
|
||||
"vornoiRegion",
|
||||
"D:\\wamp\\www\\phaser",
|
||||
"touchmove",
|
||||
"scrollSpeedX",
|
||||
"<br />",
|
||||
"runningBot",
|
||||
"running bot.swf/",
|
||||
"mouseScaleX",
|
||||
"index.php",
|
||||
"/Kiwi Lite/",
|
||||
"bigCam",
|
||||
"car",
|
||||
"myGame",
|
||||
"MainMenu",
|
||||
"myGame",
|
||||
"car",
|
||||
"drawImage",
|
||||
"_msMin",
|
||||
"setCurrentTime",
|
||||
"webaudio",
|
||||
" extends Kiwi.State",
|
||||
"Kiwi.SignalBinding",
|
||||
"Kiwi.Signal",
|
||||
"/// <reference path=\"../../kiwi/Kiwi.ts\" />",
|
||||
"//",
|
||||
"sections",
|
||||
"PointsDisplay",
|
||||
"this.pointsDisplay",
|
||||
"score",
|
||||
"money",
|
||||
"show me",
|
||||
"touch",
|
||||
"wrap",
|
||||
"this.driveSpeed",
|
||||
"startMusic",
|
||||
"nice",
|
||||
"200",
|
||||
"148",
|
||||
"3000",
|
||||
"this.distance",
|
||||
"distanceLength",
|
||||
"Cubic",
|
||||
"distancePx",
|
||||
"wellDone",
|
||||
"delivery",
|
||||
"createCanvas",
|
||||
"render"
|
||||
],
|
||||
"highlight": true,
|
||||
"in_selection": false,
|
||||
"preserve_case": false,
|
||||
"regex": false,
|
||||
"replace_history":
|
||||
[
|
||||
"launcher.html",
|
||||
"/Phaser/",
|
||||
"",
|
||||
"SignalBinding",
|
||||
"Signal",
|
||||
"/// <reference path=\"../Signal.ts\" />\n/// <reference path=\"../SignalBinding.ts\" />",
|
||||
"Quadratic",
|
||||
"//Playtomic",
|
||||
"hasSwiped",
|
||||
"firsttimeonline/html5",
|
||||
"this.popped",
|
||||
"if (game.useWebAudio === false)",
|
||||
"sd/",
|
||||
"assets/hd/",
|
||||
"runningWellDoneSequence",
|
||||
"html5/media/",
|
||||
"duckButton",
|
||||
"bestfootforward",
|
||||
"duckButton",
|
||||
"",
|
||||
"cardBack",
|
||||
"hideURLBar",
|
||||
"isGameComplete",
|
||||
"sengi",
|
||||
"Sengi",
|
||||
"style.display"
|
||||
],
|
||||
"reverse": false,
|
||||
"show_context": true,
|
||||
"use_buffer2": true,
|
||||
"whole_word": false,
|
||||
"wrap": true
|
||||
},
|
||||
"groups":
|
||||
[
|
||||
{
|
||||
"sheets":
|
||||
[
|
||||
]
|
||||
}
|
||||
],
|
||||
"incremental_find":
|
||||
{
|
||||
"height": 0.0
|
||||
},
|
||||
"input":
|
||||
{
|
||||
"height": 34.0
|
||||
},
|
||||
"layout":
|
||||
{
|
||||
"cells":
|
||||
[
|
||||
[
|
||||
0,
|
||||
0,
|
||||
1,
|
||||
1
|
||||
]
|
||||
],
|
||||
"cols":
|
||||
[
|
||||
0.0,
|
||||
1.0
|
||||
],
|
||||
"rows":
|
||||
[
|
||||
0.0,
|
||||
1.0
|
||||
]
|
||||
},
|
||||
"menu_visible": true,
|
||||
"replace":
|
||||
{
|
||||
"height": 62.0
|
||||
},
|
||||
"save_all_on_build": true,
|
||||
"select_file":
|
||||
{
|
||||
"height": 0.0,
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"select_project":
|
||||
{
|
||||
"height": 0.0,
|
||||
"selected_items":
|
||||
[
|
||||
],
|
||||
"width": 0.0
|
||||
},
|
||||
"show_minimap": true,
|
||||
"show_open_files": false,
|
||||
"show_tabs": true,
|
||||
"side_bar_visible": true,
|
||||
"side_bar_width": 284.0,
|
||||
"status_bar_visible": true
|
||||
}
|
|
@ -1,195 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<ProjectGuid>{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}</ProjectGuid>
|
||||
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
|
||||
<OutputType>Library</OutputType>
|
||||
<OutputPath>bin</OutputPath>
|
||||
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
|
||||
<DebugType>full</DebugType>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<UseIISExpress>true</UseIISExpress>
|
||||
<IISExpressSSLPort />
|
||||
<IISExpressAnonymousAuthentication />
|
||||
<IISExpressWindowsAuthentication />
|
||||
<IISExpressUseClassicPipelineMode />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<TypeScriptCompile Include="_definitions.ts" />
|
||||
<TypeScriptCompile Include="Phaser.ts" />
|
||||
<TypeScriptCompile Include="Statics.ts" />
|
||||
<TypeScriptCompile Include="geom\Point.ts" />
|
||||
<TypeScriptCompile Include="geom\Rectangle.ts" />
|
||||
<TypeScriptCompile Include="geom\Circle.ts" />
|
||||
<TypeScriptCompile Include="geom\Line.ts" />
|
||||
<TypeScriptCompile Include="math\GameMath.ts" />
|
||||
<TypeScriptCompile Include="math\Vec2.ts" />
|
||||
<TypeScriptCompile Include="math\Vec2Utils.ts" />
|
||||
<TypeScriptCompile Include="math\Mat3.ts" />
|
||||
<TypeScriptCompile Include="math\Mat3Utils.ts" />
|
||||
<TypeScriptCompile Include="math\QuadTree.ts" />
|
||||
<TypeScriptCompile Include="math\LinkedList.ts" />
|
||||
<TypeScriptCompile Include="math\RandomDataGenerator.ts" />
|
||||
<TypeScriptCompile Include="core\Plugin.ts" />
|
||||
<TypeScriptCompile Include="core\PluginManager.ts" />
|
||||
<TypeScriptCompile Include="core\Signal.ts" />
|
||||
<TypeScriptCompile Include="core\SignalBinding.ts" />
|
||||
<TypeScriptCompile Include="core\Group.ts" />
|
||||
<TypeScriptCompile Include="cameras\Camera.ts" />
|
||||
<TypeScriptCompile Include="cameras\CameraManager.ts" />
|
||||
<TypeScriptCompile Include="display\CSS3Filters.ts" />
|
||||
<TypeScriptCompile Include="display\DynamicTexture.ts" />
|
||||
<TypeScriptCompile Include="display\Texture.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Back.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Bounce.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Circular.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Cubic.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Elastic.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Exponential.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Linear.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Quadratic.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Quartic.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Quintic.ts" />
|
||||
<TypeScriptCompile Include="tweens\easing\Sinusoidal.ts" />
|
||||
<TypeScriptCompile Include="tweens\Tween.ts" />
|
||||
<TypeScriptCompile Include="tweens\TweenManager.ts" />
|
||||
<TypeScriptCompile Include="time\TimeManager.ts" />
|
||||
<TypeScriptCompile Include="net\Net.ts" />
|
||||
<TypeScriptCompile Include="input\Keyboard.ts" />
|
||||
<TypeScriptCompile Include="input\Mouse.ts" />
|
||||
<TypeScriptCompile Include="input\MSPointer.ts" />
|
||||
<TypeScriptCompile Include="input\Touch.ts" />
|
||||
<TypeScriptCompile Include="input\Pointer.ts" />
|
||||
<TypeScriptCompile Include="input\InputHandler.ts" />
|
||||
<TypeScriptCompile Include="input\InputManager.ts" />
|
||||
<TypeScriptCompile Include="system\Device.ts" />
|
||||
<TypeScriptCompile Include="system\RequestAnimationFrame.ts" />
|
||||
<TypeScriptCompile Include="system\StageScaleMode.ts" />
|
||||
<TypeScriptCompile Include="system\screens\BootScreen.ts" />
|
||||
<TypeScriptCompile Include="system\screens\OrientationScreen.ts" />
|
||||
<TypeScriptCompile Include="system\screens\PauseScreen.ts" />
|
||||
<TypeScriptCompile Include="sound\SoundManager.ts" />
|
||||
<TypeScriptCompile Include="sound\Sound.ts" />
|
||||
<TypeScriptCompile Include="animation\Animation.ts" />
|
||||
<TypeScriptCompile Include="animation\AnimationManager.ts" />
|
||||
<TypeScriptCompile Include="animation\Frame.ts" />
|
||||
<TypeScriptCompile Include="animation\FrameData.ts" />
|
||||
<TypeScriptCompile Include="loader\Cache.ts" />
|
||||
<TypeScriptCompile Include="loader\Loader.ts" />
|
||||
<TypeScriptCompile Include="loader\AnimationLoader.ts" />
|
||||
<TypeScriptCompile Include="tilemap\Tile.ts" />
|
||||
<TypeScriptCompile Include="tilemap\Tilemap.ts" />
|
||||
<TypeScriptCompile Include="tilemap\TilemapLayer.ts" />
|
||||
<TypeScriptCompile Include="physics\PhysicsManager.ts" />
|
||||
<TypeScriptCompile Include="physics\Body.ts" />
|
||||
<TypeScriptCompile Include="physics\AABB.ts" />
|
||||
<TypeScriptCompile Include="physics\Circle.ts" />
|
||||
<TypeScriptCompile Include="physics\TileMapCell.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABB22Deg.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABB45Deg.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABB67Deg.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABBConcave.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABBConvex.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABBFull.ts" />
|
||||
<TypeScriptCompile Include="physics\aabb\ProjAABBHalf.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircle22Deg.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircle45Deg.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircle67Deg.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircleConcave.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircleConvex.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircleFull.ts" />
|
||||
<TypeScriptCompile Include="physics\circle\ProjCircleHalf.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\Events.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\Sprite.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\TransformManager.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\ScrollRegion.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\ScrollZone.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\IGameObject.ts" />
|
||||
<TypeScriptCompile Include="gameobjects\GameObjectFactory.ts" />
|
||||
<TypeScriptCompile Include="ui\Button.ts" />
|
||||
<TypeScriptCompile Include="utils\CanvasUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\CircleUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\ColorUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\PointUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\RectangleUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\SpriteUtils.ts" />
|
||||
<TypeScriptCompile Include="utils\DebugUtils.ts" />
|
||||
<TypeScriptCompile Include="renderers\IRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\HeadlessRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\CameraRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\GeometryRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\GroupRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\ScrollZoneRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\SpriteRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\TilemapRenderer.ts" />
|
||||
<TypeScriptCompile Include="renderers\canvas\CanvasRenderer.ts" />
|
||||
<TypeScriptCompile Include="particles\ParticleManager.ts" />
|
||||
<TypeScriptCompile Include="particles\Particle.ts" />
|
||||
<TypeScriptCompile Include="particles\Emitter.ts" />
|
||||
<TypeScriptCompile Include="particles\ParticlePool.ts" />
|
||||
<TypeScriptCompile Include="particles\ParticleUtils.ts" />
|
||||
<TypeScriptCompile Include="particles\Polar2D.ts" />
|
||||
<TypeScriptCompile Include="particles\Span.ts" />
|
||||
<TypeScriptCompile Include="particles\NumericalIntegration.ts" />
|
||||
<TypeScriptCompile Include="particles\behaviours\Behaviour.ts" />
|
||||
<TypeScriptCompile Include="particles\behaviours\RandomDrift.ts" />
|
||||
<TypeScriptCompile Include="particles\initialize\Initialize.ts" />
|
||||
<TypeScriptCompile Include="particles\initialize\Life.ts" />
|
||||
<TypeScriptCompile Include="particles\initialize\Mass.ts" />
|
||||
<TypeScriptCompile Include="particles\initialize\Position.ts" />
|
||||
<TypeScriptCompile Include="particles\initialize\Rate.ts" />
|
||||
<TypeScriptCompile Include="particles\initialize\Velocity.ts" />
|
||||
<TypeScriptCompile Include="particles\zone\Zone.ts" />
|
||||
<TypeScriptCompile Include="particles\zone\PointZone.ts" />
|
||||
<TypeScriptCompile Include="World.ts" />
|
||||
<TypeScriptCompile Include="Stage.ts" />
|
||||
<TypeScriptCompile Include="State.ts" />
|
||||
<TypeScriptCompile Include="Game.ts" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<PropertyGroup>
|
||||
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
|
||||
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<RootNamespace>Phaser</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" Condition="'$(VSToolsPath)' != ''" />
|
||||
<ProjectExtensions>
|
||||
<VisualStudio>
|
||||
<FlavorProperties GUID="{349c5851-65df-11da-9384-00065b846f21}">
|
||||
<WebProjectProperties>
|
||||
<UseIIS>True</UseIIS>
|
||||
<AutoAssignPort>True</AutoAssignPort>
|
||||
<DevelopmentServerPort>0</DevelopmentServerPort>
|
||||
<DevelopmentServerVPath>/</DevelopmentServerVPath>
|
||||
<IISUrl>http://localhost:51891/</IISUrl>
|
||||
<NTLMAuthentication>False</NTLMAuthentication>
|
||||
<UseCustomServer>False</UseCustomServer>
|
||||
<CustomServerUrl>
|
||||
</CustomServerUrl>
|
||||
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
</VisualStudio>
|
||||
</ProjectExtensions>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
|
||||
<TypeScriptTarget>ES5</TypeScriptTarget>
|
||||
<TypeScriptRemoveComments>false</TypeScriptRemoveComments>
|
||||
<TypeScriptSourceMap>false</TypeScriptSourceMap>
|
||||
<TypeScriptOutFile>../build/phaser-debug.js</TypeScriptOutFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<TypeScriptTarget>ES5</TypeScriptTarget>
|
||||
<TypeScriptRemoveComments>true</TypeScriptRemoveComments>
|
||||
<TypeScriptSourceMap>false</TypeScriptSourceMap>
|
||||
<TypeScriptOutFile>../build/phaser-release.js</TypeScriptOutFile>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VSToolsPath)\TypeScript\Microsoft.TypeScript.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>cd $(ProjectDir)..\build
|
||||
copy phaser-debug.js ..\Tests\</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
</Project>
|
|
@ -1,32 +0,0 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Phaser", "Phaser.csproj", "{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tests", "..\Tests\Tests.csproj", "{DC8A0795-0F9C-4216-A95D-6C3346EA7E26}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Plugins", "..\Plugins\Plugins.csproj", "{1106D1E1-DCE3-4CAF-8096-6C85F765D519}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BB30C59B-5B34-4F7C-B5CC-8D49EA280EDA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{DC8A0795-0F9C-4216-A95D-6C3346EA7E26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{DC8A0795-0F9C-4216-A95D-6C3346EA7E26}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DC8A0795-0F9C-4216-A95D-6C3346EA7E26}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DC8A0795-0F9C-4216-A95D-6C3346EA7E26}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1106D1E1-DCE3-4CAF-8096-6C85F765D519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1106D1E1-DCE3-4CAF-8096-6C85F765D519}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1106D1E1-DCE3-4CAF-8096-6C85F765D519}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1106D1E1-DCE3-4CAF-8096-6C85F765D519}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
|
@ -1,60 +0,0 @@
|
|||
<textarea style="width: 600px; height: 800px">
|
||||
<?php
|
||||
/*
|
||||
Because Visual Studio really likes to screw up its csproj files a LOT
|
||||
let's read in the _definitions.ts file and generate a valid csproj XML block,
|
||||
so we can be 100% sure it's in the order we need and formatted cleanly.
|
||||
|
||||
Note: VS still won't compile to the JS files if we have the output parameter set in
|
||||
the csproj. You have to edit that out to compile to JS, the edit it back in to compile
|
||||
to a single output destination! Ballache for sure. But at least we only do it when
|
||||
generating new docs.
|
||||
*/
|
||||
|
||||
$defs = file('_definitions.ts');
|
||||
|
||||
echo " <ItemGroup>\n";
|
||||
echo " <TypeScriptCompile Include=\"_definitions.ts\" />\n";
|
||||
|
||||
for ($i = 0; $i < count($defs); $i++)
|
||||
{
|
||||
// Format of the line: /// <reference path="Phaser.ts" />
|
||||
|
||||
if (strlen(trim($defs[$i])) > 0)
|
||||
{
|
||||
$ts = substr($defs[$i], 21, -6);
|
||||
$ts = str_replace('/', '\\', $ts);
|
||||
$js = str_replace('.ts', '.js', $ts);
|
||||
|
||||
if (strrpos($ts, '\\') > 0)
|
||||
{
|
||||
$file = substr($ts, strrpos($ts, '\\') + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
$file = substr($ts, strrpos($ts, '\\'));
|
||||
}
|
||||
|
||||
/*
|
||||
<ItemGroup>
|
||||
<TypeScriptCompile Include="physics\arcade\Motion.ts" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="physics\arcade\Motion.js">
|
||||
<DependentUpon>Motion.ts</DependentUpon>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
*/
|
||||
|
||||
echo " <TypeScriptCompile Include=\"$ts\" />\n";
|
||||
//echo " <Content Include=\"$js\">\n";
|
||||
//echo " <DependentUpon>$file</DependentUpon>\n";
|
||||
//echo " </Content>\n";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
echo " </ItemGroup>\n";
|
||||
|
||||
?>
|
||||
</textarea>
|
|
@ -1,423 +0,0 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Physics - AABB
|
||||
*/
|
||||
|
||||
module Phaser.Physics {
|
||||
|
||||
export class AABB {
|
||||
|
||||
constructor(game: Phaser.Game, x: number, y: number, width: number, height: number) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
this.pos = new Phaser.Vec2(x, y);
|
||||
this.oldpos = new Phaser.Vec2(x, y);
|
||||
|
||||
this.width = Math.abs(width);
|
||||
this.height = Math.abs(height);
|
||||
|
||||
this.velocity = new Phaser.Vec2;
|
||||
this.acceleration = new Phaser.Vec2;
|
||||
this.bounce = new Phaser.Vec2(0, 0);
|
||||
|
||||
//this.drag = new Phaser.Vec2(1, 1);
|
||||
//this.gravity = new Phaser.Vec2(0, 0.2);
|
||||
|
||||
this.drag = new Phaser.Vec2(0, 0);
|
||||
this.gravity = new Phaser.Vec2(0, 2);
|
||||
|
||||
this.maxVelocity = new Phaser.Vec2(1000, 1000);
|
||||
|
||||
this.aabbTileProjections = {};
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGs] = Phaser.Physics.Projection.AABB22Deg.CollideS;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_22DEGb] = Phaser.Physics.Projection.AABB22Deg.CollideB;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_45DEG] = Phaser.Physics.Projection.AABB45Deg.Collide;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGs] = Phaser.Physics.Projection.AABB67Deg.CollideS;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_67DEGb] = Phaser.Physics.Projection.AABB67Deg.CollideB;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONCAVE] = Phaser.Physics.Projection.AABBConcave.Collide;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_CONVEX] = Phaser.Physics.Projection.AABBConvex.Collide;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_FULL] = Phaser.Physics.Projection.AABBFull.Collide;
|
||||
this.aabbTileProjections[Phaser.Physics.TileMapCell.CTYPE_HALF] = Phaser.Physics.Projection.AABBHalf.Collide;
|
||||
|
||||
}
|
||||
|
||||
public game: Phaser.Game;
|
||||
|
||||
public velocity: Phaser.Vec2;
|
||||
public acceleration: Phaser.Vec2;
|
||||
public drag: Phaser.Vec2;
|
||||
public gravity: Phaser.Vec2;
|
||||
public bounce: Phaser.Vec2;
|
||||
public maxVelocity: Phaser.Vec2;
|
||||
|
||||
public static COL_NONE = 0;
|
||||
public static COL_AXIS = 1;
|
||||
public static COL_OTHER = 2;
|
||||
|
||||
public type: number = 0;
|
||||
public pos: Phaser.Vec2;
|
||||
public oldpos: Phaser.Vec2;
|
||||
public width: number;
|
||||
public height: number;
|
||||
public oH: number;
|
||||
public oV: number;
|
||||
|
||||
public _vx: number = 0;
|
||||
public _vy: number = 0;
|
||||
public _deltaX: number = 0;
|
||||
public _deltaY: number = 0;
|
||||
|
||||
private aabbTileProjections;
|
||||
|
||||
public update() {
|
||||
|
||||
// Add 'go to sleep' option
|
||||
|
||||
this.oldpos.x = this.pos.x; //get vector values
|
||||
this.oldpos.y = this.pos.y; //p = position
|
||||
|
||||
this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.drag.x, this.maxVelocity.x) - this.velocity.x) / 2;
|
||||
this.velocity.x += this._vx;
|
||||
//this.pos.x += (this.velocity.x * this.game.time.physicsElapsed) + this.gravity.x;
|
||||
//this.pos.x += (this.velocity.x * this.game.time.physicsElapsed);
|
||||
this._deltaX = this.velocity.x * this.game.time.physicsElapsed;
|
||||
//body.aabb.pos.x += this._delta;
|
||||
|
||||
this._vy = (this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
||||
//this._vy = this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.drag.y, this.maxVelocity.y);
|
||||
this.velocity.y += this._vy;
|
||||
//this.pos.y += (this.velocity.y * this.game.time.physicsElapsed) + this.gravity.y;
|
||||
//this.pos.y += (this.velocity.y * this.game.time.physicsElapsed);
|
||||
this._deltaY = this.velocity.y * this.game.time.physicsElapsed;
|
||||
|
||||
this.pos.x += this._deltaX;
|
||||
this.pos.y += this._deltaY;
|
||||
|
||||
//this.integrateVerlet();
|
||||
|
||||
//var ox = this.oldpos.x;
|
||||
//var oy = this.oldpos.y;
|
||||
|
||||
}
|
||||
|
||||
public FFupdate() {
|
||||
|
||||
this.oldpos.x = this.pos.x; //get vector values
|
||||
this.oldpos.y = this.pos.y; //p = position
|
||||
|
||||
if (this.acceleration.x != 0)
|
||||
{
|
||||
this.velocity.x += (this.acceleration.x / 1000 * this.game.time.delta);
|
||||
}
|
||||
|
||||
if (this.acceleration.y != 0)
|
||||
{
|
||||
this.velocity.y += (this.acceleration.y / 1000 * this.game.time.delta);
|
||||
}
|
||||
|
||||
this._vx = ((this.velocity.x / 1000) * this.game.time.delta);
|
||||
this._vy = ((this.velocity.y / 1000) * this.game.time.delta);
|
||||
|
||||
if (this._vx != 0)
|
||||
{
|
||||
if (this.drag.x != 0)
|
||||
{
|
||||
this._vx * this.drag.x;
|
||||
}
|
||||
|
||||
if (this.gravity.x != 0)
|
||||
{
|
||||
this._vx * this.gravity.x;
|
||||
}
|
||||
|
||||
if (this.velocity.x > this.maxVelocity.x)
|
||||
{
|
||||
this.velocity.x = this.maxVelocity.x;
|
||||
}
|
||||
else if (this.velocity.x < -this.maxVelocity.x)
|
||||
{
|
||||
this.velocity.x = -this.maxVelocity.x;
|
||||
}
|
||||
}
|
||||
|
||||
if (this._vy != 0)
|
||||
{
|
||||
if (this.drag.y != 0)
|
||||
{
|
||||
this._vy * this.drag.y;
|
||||
}
|
||||
|
||||
if (this.gravity.y != 0)
|
||||
{
|
||||
this._vy * this.gravity.y;
|
||||
}
|
||||
|
||||
if (this.velocity.y > this.maxVelocity.y)
|
||||
{
|
||||
this.velocity.y = this.maxVelocity.y;
|
||||
}
|
||||
else if (this.velocity.y < -this.maxVelocity.y)
|
||||
{
|
||||
this.velocity.y = -this.maxVelocity.y;
|
||||
}
|
||||
}
|
||||
|
||||
this.pos.x += this._vx;
|
||||
this.pos.y += this._vy;
|
||||
|
||||
//this._vx = (this.game.physics.computeVelocity(this.velocity.x, this.gravity.x, this.acceleration.x, this.fdrag.x, this.maxVelocity.x) - this.velocity.x) / 2;
|
||||
//this.velocity.x += this._vx;
|
||||
//this.pos.x += (this.velocity.x * this.game.time.physicsElapsed) + this.gravity.x;
|
||||
|
||||
//this._vy = (this.game.physics.computeVelocity(this.velocity.y, this.gravity.y, this.acceleration.y, this.fdrag.y, this.maxVelocity.y) - this.velocity.y) / 2;
|
||||
//this.velocity.y += this._vy;
|
||||
//this.pos.y += (this.velocity.y * this.game.time.physicsElapsed) + this.gravity.y;
|
||||
|
||||
//this.integrateVerlet();
|
||||
|
||||
//var ox = this.oldpos.x;
|
||||
//var oy = this.oldpos.y;
|
||||
|
||||
//this.oldpos.x = this.pos.x; //get vector values
|
||||
//this.oldpos.y = this.pos.y; //p = position
|
||||
|
||||
//integrate
|
||||
//this.pos.x += (this.drag.x * this.pos.x) - (this.drag.x * ox) + this.gravity.x;
|
||||
//this.pos.y += (this.drag.y * this.pos.y) - (this.drag.y * oy) + this.gravity.y;
|
||||
|
||||
//this._vx = (this.velocity.x / 1000 * this.game.time.delta);
|
||||
//this._vy = (this.velocity.y / 1000 * this.game.time.delta);
|
||||
//this._vx = 0.2;
|
||||
//this._vy = 0.2;
|
||||
|
||||
//this.pos.x = this.oldpos.x + Math.min(20, Math.max(-20, this.pos.x - this.oldpos.x + this._vx));
|
||||
//this.pos.y = this.oldpos.y + Math.min(20, Math.max(-20, this.pos.y - this.oldpos.y + this._vy));
|
||||
|
||||
//this.integrateVerlet();
|
||||
|
||||
}
|
||||
|
||||
public integrateVerlet() {
|
||||
|
||||
var px = this.pos.x;
|
||||
var py = this.pos.y;
|
||||
|
||||
var ox = this.oldpos.x;
|
||||
var oy = this.oldpos.y;
|
||||
|
||||
this.oldpos.x = this.pos.x; //get vector values
|
||||
this.oldpos.y = this.pos.y; //p = position
|
||||
|
||||
//integrate
|
||||
this.pos.x += (this.drag.x * px) - (this.drag.x * ox) + this.gravity.x;
|
||||
this.pos.y += (this.drag.y * py) - (this.drag.y * oy) + this.gravity.y;
|
||||
|
||||
}
|
||||
|
||||
public reportCollisionVsWorld(px: number, py: number, dx: number, dy: number, obj: TileMapCell = null) {
|
||||
|
||||
//calc velocity (original way)
|
||||
//this._vx = this.pos.x - this.oldpos.x;
|
||||
//this._vy = this.pos.y - this.oldpos.y;
|
||||
//var vx = this.pos.x - this.oldpos.x;
|
||||
//var vy = this.pos.y - this.oldpos.y;
|
||||
|
||||
//find component of velocity parallel to collision normal
|
||||
//var dp = (vx * dx + vy * dy);
|
||||
//var nx = dp * dx;//project velocity onto collision normal
|
||||
//var ny = dp * dy;//nx,ny is normal velocity
|
||||
|
||||
//var tx = vx - nx;//px,py is tangent velocity
|
||||
//var ty = vy - ny;
|
||||
|
||||
var dp = (this._vx * dx + this._vy * dy);
|
||||
var nx = dp * dx;//project velocity onto collision normal
|
||||
var ny = dp * dy;//nx,ny is normal velocity
|
||||
|
||||
var tx = this._vx - nx;//px,py is tangent velocity
|
||||
var ty = this._vy - ny;
|
||||
|
||||
//console.log('nxy', nx, ny);
|
||||
//console.log('nxy', nx, ny);
|
||||
//console.log('txy', tx, ty);
|
||||
|
||||
this.pos.x += px; //project object out of collision
|
||||
this.pos.y += py;
|
||||
|
||||
//this.oldpos.x += px;
|
||||
//this.oldpos.y += py;
|
||||
//this.pos.x += px;
|
||||
//this.pos.y += py;
|
||||
|
||||
//this.velocity.x += nx;
|
||||
//this.velocity.y += ny;
|
||||
|
||||
//we only want to apply collision response forces if the object is travelling into, and not out of, the collision
|
||||
if (dp < 0)
|
||||
//if (1 < 0)
|
||||
{
|
||||
// moving into collision, apply forces
|
||||
//var b = 1 + 0.5;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
|
||||
//var b = 0.5;//this bounce constant should be elsewhere, i.e inside the object/tile/etc..
|
||||
//var f = 0.05; // friction
|
||||
//var fx = tx * f;
|
||||
//var fy = ty * f;
|
||||
|
||||
//this.oldpos.x += (nx * b) + fx;//apply bounce+friction impulses which alter velocity
|
||||
//this.oldpos.y += (ny * b) + fy;
|
||||
this.velocity.x += nx;
|
||||
this.velocity.y += ny;
|
||||
|
||||
if (dx !== 0)
|
||||
{
|
||||
// this.velocity.x *= -1 * this.bounce.x;
|
||||
}
|
||||
|
||||
if (dy !== 0)
|
||||
{
|
||||
// this.velocity.y *= -1 * this.bounce.y;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public collideAABBVsTile(tile: Phaser.Physics.TileMapCell) {
|
||||
|
||||
var pos = this.pos;
|
||||
var c = tile;
|
||||
|
||||
var tx = c.pos.x;
|
||||
var ty = c.pos.y;
|
||||
var txw = c.xw;
|
||||
var tyw = c.yw;
|
||||
|
||||
var dx = pos.x - tx;//tile->obj delta
|
||||
var px = (txw + this.width) - Math.abs(dx);//penetration depth in x
|
||||
|
||||
if (0 < px)
|
||||
{
|
||||
var dy = pos.y - ty;//tile->obj delta
|
||||
var py = (tyw + this.height) - Math.abs(dy);//pen depth in y
|
||||
|
||||
if (0 < py)
|
||||
{
|
||||
//object may be colliding with tile; call tile-specific collision function
|
||||
|
||||
//calculate projection vectors
|
||||
if (px < py)
|
||||
{
|
||||
//project in x
|
||||
if (dx < 0)
|
||||
{
|
||||
//project to the left
|
||||
px *= -1;
|
||||
py = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
//proj to right
|
||||
py = 0;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//project in y
|
||||
if (dy < 0)
|
||||
{
|
||||
//project up
|
||||
px = 0;
|
||||
py *= -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
//project down
|
||||
px = 0;
|
||||
}
|
||||
}
|
||||
|
||||
this.resolveBoxTile(px, py, this, c);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public collideAABBVsWorldBounds() {
|
||||
|
||||
var p = this.pos;
|
||||
var xw = this.width;
|
||||
var yw = this.height;
|
||||
var XMIN = 0;
|
||||
var XMAX = 800;
|
||||
var YMIN = 0;
|
||||
var YMAX = 600;
|
||||
|
||||
//collide vs. x-bounds
|
||||
//test XMIN left side
|
||||
var dx = XMIN - (p.x - xw);
|
||||
if (0 < dx)
|
||||
{
|
||||
//object is colliding with XMIN
|
||||
this.reportCollisionVsWorld(dx, 0, 1, 0, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//test XMAX right side
|
||||
dx = (p.x + xw) - XMAX;
|
||||
if (0 < dx)
|
||||
{
|
||||
//object is colliding with XMAX
|
||||
this.reportCollisionVsWorld(-dx, 0, -1, 0, null);
|
||||
}
|
||||
}
|
||||
|
||||
//collide vs. y-bounds
|
||||
//test YMIN top
|
||||
var dy = YMIN - (p.y - yw);
|
||||
if (0 < dy)
|
||||
{
|
||||
//object is colliding with YMIN
|
||||
this.reportCollisionVsWorld(0, dy, 0, 1, null);
|
||||
}
|
||||
else
|
||||
{
|
||||
//test YMAX bottom
|
||||
dy = (p.y + yw) - YMAX;
|
||||
if (0 < dy)
|
||||
{
|
||||
//object is colliding with YMAX
|
||||
this.reportCollisionVsWorld(0, -dy, 0, -1, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public resolveBoxTile(x, y, box, t) {
|
||||
|
||||
if (0 < t.ID)
|
||||
{
|
||||
return this.aabbTileProjections[t.CTYPE](x, y, box, t);
|
||||
}
|
||||
else
|
||||
{
|
||||
//trace("resolveBoxTile() was called with an empty (or unknown) tile!: ID=" + t.ID + " ("+ t.i + "," + t.j + ")");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public render(context: CanvasRenderingContext2D) {
|
||||
|
||||
context.beginPath();
|
||||
context.strokeStyle = 'rgb(0,255,0)';
|
||||
context.strokeRect(this.pos.x - this.width, this.pos.y - this.height, this.width * 2, this.height * 2);
|
||||
context.stroke();
|
||||
context.closePath();
|
||||
|
||||
context.fillStyle = 'rgb(0,255,0)';
|
||||
context.fillRect(this.pos.x, this.pos.y, 2, 2);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,163 +0,0 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
|
||||
/**
|
||||
* Phaser - Physics - PhysicsManager
|
||||
*/
|
||||
|
||||
module Phaser.Physics {
|
||||
|
||||
export class PhysicsManager {
|
||||
|
||||
constructor(game: Phaser.Game) {
|
||||
|
||||
this.game = game;
|
||||
|
||||
//this.gravity = new Vec2;
|
||||
//this.drag = new Vec2;
|
||||
//this.bounce = new Vec2;
|
||||
//this.angularDrag = 0;
|
||||
|
||||
//this.bounds = new Rectangle(0, 0, width, height);
|
||||
|
||||
//this._distance = new Vec2;
|
||||
//this._tangent = new Vec2;
|
||||
|
||||
}
|
||||
|
||||
public game: Phaser.Game;
|
||||
|
||||
// Temp calculation vars
|
||||
private _drag: number;
|
||||
private _delta: number;
|
||||
private _velocityDelta: number;
|
||||
private _length: number = 0;
|
||||
private _distance: Vec2;
|
||||
private _tangent: Vec2;
|
||||
private _separatedX: bool;
|
||||
private _separatedY: bool;
|
||||
private _overlap: number;
|
||||
private _maxOverlap: number;
|
||||
private _obj1Velocity: number;
|
||||
private _obj2Velocity: number;
|
||||
private _obj1NewVelocity: number;
|
||||
private _obj2NewVelocity: number;
|
||||
private _average: number;
|
||||
private _quadTree: QuadTree;
|
||||
private _quadTreeResult: bool;
|
||||
|
||||
//public bounds: Rectangle;
|
||||
|
||||
//public gravity: Vec2;
|
||||
//public drag: Vec2;
|
||||
//public bounce: Vec2;
|
||||
//public angularDrag: number;
|
||||
|
||||
grav: number = 0.2;
|
||||
drag: number = 1;
|
||||
bounce: number = 0.3;
|
||||
friction: number = 0.05;
|
||||
|
||||
min_f: number = 0;
|
||||
max_f: number = 1;
|
||||
|
||||
min_b: number = 0;
|
||||
max_b: number = 1;
|
||||
|
||||
min_g: number = 0;
|
||||
max_g = 1;
|
||||
|
||||
xmin: number = 0;
|
||||
xmax: number = 800;
|
||||
ymin: number = 0;
|
||||
ymax: number = 600;
|
||||
|
||||
objrad: number = 24;
|
||||
tilerad: number = 24 * 2;
|
||||
objspeed: number = 0.2;
|
||||
maxspeed: number = 20;
|
||||
|
||||
public update() {
|
||||
}
|
||||
|
||||
public updateMotion(body: Phaser.Physics.Body) {
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.angularVelocity, body.gravity.x, body.angularAcceleration, body.angularDrag, body.maxAngular) - body.angularVelocity) / 2;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
body.sprite.transform.rotation += body.angularVelocity * this.game.time.physicsElapsed;
|
||||
body.angularVelocity += this._velocityDelta;
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.velocity.x, body.gravity.x, body.acceleration.x, body.drag.x) - body.velocity.x) / 2;
|
||||
body.velocity.x += this._velocityDelta;
|
||||
this._delta = body.velocity.x * this.game.time.physicsElapsed;
|
||||
|
||||
body.aabb.pos.x += this._delta;
|
||||
body.deltaX = this._delta;
|
||||
|
||||
this._velocityDelta = (this.computeVelocity(body.velocity.y, body.gravity.y, body.acceleration.y, body.drag.y) - body.velocity.y) / 2;
|
||||
body.velocity.y += this._velocityDelta;
|
||||
this._delta = body.velocity.y * this.game.time.physicsElapsed;
|
||||
|
||||
body.aabb.pos.y += this._delta;
|
||||
body.deltaY = this._delta;
|
||||
|
||||
//body.aabb.integrateVerlet();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* A tween-like function that takes a starting velocity and some other factors and returns an altered velocity.
|
||||
*
|
||||
* @param {number} Velocity Any component of velocity (e.g. 20).
|
||||
* @param {number} Acceleration Rate at which the velocity is changing.
|
||||
* @param {number} Drag Really kind of a deceleration, this is how much the velocity changes if Acceleration is not set.
|
||||
* @param {number} Max An absolute value cap for the velocity.
|
||||
*
|
||||
* @return {number} The altered Velocity value.
|
||||
*/
|
||||
public computeVelocity(velocity: number, gravity: number = 0, acceleration: number = 0, drag: number = 0, max: number = 10000): number {
|
||||
|
||||
if (acceleration !== 0)
|
||||
{
|
||||
velocity += (acceleration + gravity) * this.game.time.physicsElapsed;
|
||||
}
|
||||
else if (drag !== 0)
|
||||
{
|
||||
this._drag = drag * this.game.time.physicsElapsed;
|
||||
|
||||
if (velocity - this._drag > 0)
|
||||
{
|
||||
velocity = velocity - this._drag;
|
||||
}
|
||||
else if (velocity + this._drag < 0)
|
||||
{
|
||||
velocity += this._drag;
|
||||
}
|
||||
else
|
||||
{
|
||||
velocity = 0;
|
||||
}
|
||||
|
||||
//velocity += gravity;
|
||||
}
|
||||
|
||||
velocity += gravity;
|
||||
|
||||
if (velocity != 0)
|
||||
{
|
||||
if (velocity > max)
|
||||
{
|
||||
velocity = max;
|
||||
}
|
||||
else if (velocity < -max)
|
||||
{
|
||||
velocity = -max;
|
||||
}
|
||||
}
|
||||
|
||||
return velocity;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,192 +0,0 @@
|
|||
/// <reference path="../../_definitions.ts" />
|
||||
|
||||
module Phaser.Renderer.Canvas {
|
||||
|
||||
export class SpriteRenderer {
|
||||
|
||||
constructor(game: Phaser.Game) {
|
||||
this.game = game;
|
||||
}
|
||||
|
||||
/**
|
||||
* The essential reference to the main game object
|
||||
*/
|
||||
public game: Phaser.Game;
|
||||
|
||||
// Local rendering related temp vars to help avoid gc spikes through constant var creation
|
||||
//private _c: number = 0;
|
||||
private _ga: number = 1;
|
||||
private _sx: number = 0;
|
||||
private _sy: number = 0;
|
||||
private _sw: number = 0;
|
||||
private _sh: number = 0;
|
||||
private _dx: number = 0;
|
||||
private _dy: number = 0;
|
||||
private _dw: number = 0;
|
||||
private _dh: number = 0;
|
||||
|
||||
/**
|
||||
* Check whether this object is visible in a specific camera Rectangle.
|
||||
* @param camera {Rectangle} The Rectangle you want to check.
|
||||
* @return {bool} Return true if bounds of this sprite intersects the given Rectangle, otherwise return false.
|
||||
*/
|
||||
public inCamera(camera: Phaser.Camera, sprite: Phaser.Sprite): bool {
|
||||
|
||||
// Object fixed in place regardless of the camera scrolling? Then it's always visible
|
||||
if (sprite.transform.scrollFactor.equals(0))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return RectangleUtils.intersects(sprite.cameraView, camera.screenView);
|
||||
//return true;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Render this sprite to specific camera. Called by game loop after update().
|
||||
* @param camera {Camera} Camera this sprite will be rendered to.
|
||||
* @return {bool} Return false if not rendered, otherwise return true.
|
||||
*/
|
||||
public render(camera: Phaser.Camera, sprite: Phaser.Sprite): bool {
|
||||
|
||||
Phaser.SpriteUtils.updateCameraView(camera, sprite);
|
||||
|
||||
if (sprite.transform.scale.x == 0 || sprite.transform.scale.y == 0 || sprite.texture.alpha < 0.1 || this.inCamera(camera, sprite) == false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Reset our temp vars
|
||||
this._ga = -1;
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = sprite.texture.width;
|
||||
this._sh = sprite.texture.height;
|
||||
//this._dx = camera.screenView.x + sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
|
||||
//this._dy = camera.screenView.y + sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
|
||||
this._dx = sprite.x - (camera.worldView.x * sprite.transform.scrollFactor.x);
|
||||
this._dy = sprite.y - (camera.worldView.y * sprite.transform.scrollFactor.y);
|
||||
this._dw = sprite.texture.width;
|
||||
this._dh = sprite.texture.height;
|
||||
|
||||
if (sprite.animations.currentFrame !== null)
|
||||
{
|
||||
this._sx = sprite.animations.currentFrame.x;
|
||||
this._sy = sprite.animations.currentFrame.y;
|
||||
|
||||
if (sprite.animations.currentFrame.trimmed)
|
||||
{
|
||||
this._dx += sprite.animations.currentFrame.spriteSourceSizeX;
|
||||
this._dy += sprite.animations.currentFrame.spriteSourceSizeY;
|
||||
this._sw = sprite.animations.currentFrame.spriteSourceSizeW;
|
||||
this._sh = sprite.animations.currentFrame.spriteSourceSizeH;
|
||||
this._dw = sprite.animations.currentFrame.spriteSourceSizeW;
|
||||
this._dh = sprite.animations.currentFrame.spriteSourceSizeH;
|
||||
}
|
||||
}
|
||||
|
||||
if (sprite.modified)
|
||||
{
|
||||
camera.texture.context.save();
|
||||
|
||||
camera.texture.context.setTransform(
|
||||
sprite.transform.local.data[0], // scale x
|
||||
sprite.transform.local.data[3], // skew x
|
||||
sprite.transform.local.data[1], // skew y
|
||||
sprite.transform.local.data[4], // scale y
|
||||
this._dx, // translate x
|
||||
this._dy // translate y
|
||||
);
|
||||
|
||||
this._dx = sprite.transform.origin.x * -this._dw;
|
||||
this._dy = sprite.transform.origin.y * -this._dh;
|
||||
}
|
||||
else
|
||||
{
|
||||
this._dx -= (this._dw * sprite.transform.origin.x);
|
||||
this._dy -= (this._dh * sprite.transform.origin.y);
|
||||
}
|
||||
|
||||
if (sprite.crop)
|
||||
{
|
||||
this._sx += sprite.crop.x * sprite.transform.scale.x;
|
||||
this._sy += sprite.crop.y * sprite.transform.scale.y;
|
||||
this._sw = sprite.crop.width * sprite.transform.scale.x;
|
||||
this._sh = sprite.crop.height * sprite.transform.scale.y;
|
||||
this._dx += sprite.crop.x * sprite.transform.scale.x;
|
||||
this._dy += sprite.crop.y * sprite.transform.scale.y;
|
||||
this._dw = sprite.crop.width * sprite.transform.scale.x;
|
||||
this._dh = sprite.crop.height * sprite.transform.scale.y;
|
||||
}
|
||||
|
||||
this._sx = Math.floor(this._sx);
|
||||
this._sy = Math.floor(this._sy);
|
||||
this._sw = Math.floor(this._sw);
|
||||
this._sh = Math.floor(this._sh);
|
||||
this._dx = Math.floor(this._dx);
|
||||
this._dy = Math.floor(this._dy);
|
||||
this._dw = Math.floor(this._dw);
|
||||
this._dh = Math.floor(this._dh);
|
||||
|
||||
if (this._sw <= 0 || this._sh <= 0 || this._dw <= 0 || this._dh <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Global Composite Ops
|
||||
if (sprite.texture.globalCompositeOperation)
|
||||
{
|
||||
camera.texture.context.save();
|
||||
camera.texture.context.globalCompositeOperation = sprite.texture.globalCompositeOperation;
|
||||
}
|
||||
|
||||
// Alpha
|
||||
if (sprite.texture.alpha !== 1 && camera.texture.context.globalAlpha != sprite.texture.alpha)
|
||||
{
|
||||
this._ga = sprite.texture.context.globalAlpha;
|
||||
camera.texture.context.globalAlpha = sprite.texture.alpha;
|
||||
}
|
||||
|
||||
if (sprite.texture.opaque)
|
||||
{
|
||||
camera.texture.context.fillStyle = sprite.texture.backgroundColor;
|
||||
camera.texture.context.fillRect(this._dx, this._dy, this._dw, this._dh);
|
||||
}
|
||||
|
||||
if (sprite.texture.loaded)
|
||||
{
|
||||
camera.texture.context.drawImage(
|
||||
sprite.texture.texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh // Destination Height (always same as Source Height unless scaled)
|
||||
);
|
||||
}
|
||||
|
||||
if (sprite.modified || sprite.texture.globalCompositeOperation)
|
||||
{
|
||||
camera.texture.context.restore();
|
||||
}
|
||||
|
||||
if (this._ga > -1)
|
||||
{
|
||||
camera.texture.context.globalAlpha = this._ga;
|
||||
}
|
||||
|
||||
sprite.renderOrderID = this.game.renderer.renderCount;
|
||||
|
||||
this.game.renderer.renderCount++;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -1,5 +1,4 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
|
@ -21,7 +20,7 @@ var Phaser;
|
|||
_super.call(this, game, parent);
|
||||
/**
|
||||
* Whether render border of this camera or not. (default is true)
|
||||
* @type {boolean}
|
||||
* @type {bool}
|
||||
*/
|
||||
this.showBorder = true;
|
||||
/**
|
||||
|
@ -32,7 +31,7 @@ var Phaser;
|
|||
this.camera = parent;
|
||||
}
|
||||
Border.prototype.postRender = function () {
|
||||
if (this.showBorder == true) {
|
||||
if(this.showBorder == true) {
|
||||
this.game.stage.context.strokeStyle = this.borderColor;
|
||||
this.game.stage.context.lineWidth = 1;
|
||||
this.game.stage.context.rect(this.camera.x, this.camera.y, this.camera.width, this.camera.height);
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
|
@ -24,7 +23,7 @@ var Phaser;
|
|||
this._fxFadeAlpha = 0;
|
||||
this.camera = parent;
|
||||
}
|
||||
/**
|
||||
Fade.prototype.start = /**
|
||||
* The camera is gradually filled with this color.
|
||||
*
|
||||
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
|
||||
|
@ -32,46 +31,41 @@ var Phaser;
|
|||
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
|
||||
* @param Force Force an already running flash effect to reset.
|
||||
*/
|
||||
Fade.prototype.start = function (color, duration, onComplete, force) {
|
||||
function (color, duration, onComplete, force) {
|
||||
if (typeof color === "undefined") { color = 0x000000; }
|
||||
if (typeof duration === "undefined") { duration = 1; }
|
||||
if (typeof onComplete === "undefined") { onComplete = null; }
|
||||
if (typeof force === "undefined") { force = false; }
|
||||
if (force === false && this._fxFadeAlpha > 0) {
|
||||
if(force === false && this._fxFadeAlpha > 0) {
|
||||
// You can't fade again unless you force it
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration <= 0) {
|
||||
if(duration <= 0) {
|
||||
duration = 1;
|
||||
}
|
||||
|
||||
var red = color >> 16 & 0xFF;
|
||||
var green = color >> 8 & 0xFF;
|
||||
var blue = color & 0xFF;
|
||||
|
||||
this._fxFadeColor = 'rgba(' + red + ',' + green + ',' + blue + ',';
|
||||
this._fxFadeDuration = duration;
|
||||
this._fxFadeAlpha = 0.01;
|
||||
this._fxFadeComplete = onComplete;
|
||||
};
|
||||
|
||||
Fade.prototype.postUpdate = function () {
|
||||
if (this._fxFadeAlpha > 0) {
|
||||
// Update the Fade effect
|
||||
if(this._fxFadeAlpha > 0) {
|
||||
this._fxFadeAlpha += this.game.time.elapsed / this._fxFadeDuration;
|
||||
|
||||
if (this.game.math.roundTo(this._fxFadeAlpha, -2) >= 1) {
|
||||
if(this.game.math.roundTo(this._fxFadeAlpha, -2) >= 1) {
|
||||
this._fxFadeAlpha = 1;
|
||||
|
||||
if (this._fxFadeComplete !== null) {
|
||||
if(this._fxFadeComplete !== null) {
|
||||
this._fxFadeComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Fade.prototype.postRender = function () {
|
||||
if (this._fxFadeAlpha > 0) {
|
||||
// "Fade" FX
|
||||
if(this._fxFadeAlpha > 0) {
|
||||
this.game.stage.context.fillStyle = this._fxFadeColor + this._fxFadeAlpha + ')';
|
||||
this.game.stage.context.fillRect(this.camera.screenView.x, this.camera.screenView.y, this.camera.width, this.camera.height);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
|
@ -24,7 +23,7 @@ var Phaser;
|
|||
this._fxFlashAlpha = 0;
|
||||
this.camera = parent;
|
||||
}
|
||||
/**
|
||||
Flash.prototype.start = /**
|
||||
* The camera is filled with this color and returns to normal at the given duration.
|
||||
*
|
||||
* @param Color The color you want to use in 0xRRGGBB format, i.e. 0xffffff for white.
|
||||
|
@ -32,46 +31,40 @@ var Phaser;
|
|||
* @param OnComplete An optional function you want to run when the flash finishes. Set to null for no callback.
|
||||
* @param Force Force an already running flash effect to reset.
|
||||
*/
|
||||
Flash.prototype.start = function (color, duration, onComplete, force) {
|
||||
function (color, duration, onComplete, force) {
|
||||
if (typeof color === "undefined") { color = 0xffffff; }
|
||||
if (typeof duration === "undefined") { duration = 1; }
|
||||
if (typeof onComplete === "undefined") { onComplete = null; }
|
||||
if (typeof force === "undefined") { force = false; }
|
||||
if (force === false && this._fxFlashAlpha > 0) {
|
||||
if(force === false && this._fxFlashAlpha > 0) {
|
||||
// You can't flash again unless you force it
|
||||
return;
|
||||
}
|
||||
|
||||
if (duration <= 0) {
|
||||
if(duration <= 0) {
|
||||
duration = 1;
|
||||
}
|
||||
|
||||
var red = color >> 16 & 0xFF;
|
||||
var green = color >> 8 & 0xFF;
|
||||
var blue = color & 0xFF;
|
||||
|
||||
this._fxFlashColor = 'rgba(' + red + ',' + green + ',' + blue + ',';
|
||||
this._fxFlashDuration = duration;
|
||||
this._fxFlashAlpha = 1;
|
||||
this._fxFlashComplete = onComplete;
|
||||
};
|
||||
|
||||
Flash.prototype.postUpdate = function () {
|
||||
if (this._fxFlashAlpha > 0) {
|
||||
// Update the Flash effect
|
||||
if(this._fxFlashAlpha > 0) {
|
||||
this._fxFlashAlpha -= this.game.time.elapsed / this._fxFlashDuration;
|
||||
|
||||
if (this.game.math.roundTo(this._fxFlashAlpha, -2) <= 0) {
|
||||
if(this.game.math.roundTo(this._fxFlashAlpha, -2) <= 0) {
|
||||
this._fxFlashAlpha = 0;
|
||||
|
||||
if (this._fxFlashComplete !== null) {
|
||||
if(this._fxFlashComplete !== null) {
|
||||
this._fxFlashComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Flash.prototype.postRender = function () {
|
||||
if (this._fxFlashAlpha > 0) {
|
||||
if(this._fxFlashAlpha > 0) {
|
||||
this.game.stage.context.fillStyle = this._fxFlashColor + this._fxFlashAlpha + ')';
|
||||
this.game.stage.context.fillRect(this.camera.screenView.x, this.camera.screenView.y, this.camera.width, this.camera.height);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
|
@ -21,7 +20,7 @@ var Phaser;
|
|||
_super.call(this, game, parent);
|
||||
/**
|
||||
* Render camera shadow or not. (default is false)
|
||||
* @type {boolean}
|
||||
* @type {bool}
|
||||
*/
|
||||
this.showShadow = false;
|
||||
/**
|
||||
|
@ -41,24 +40,25 @@ var Phaser;
|
|||
this.shadowOffset = new Phaser.Point(4, 4);
|
||||
this.camera = parent;
|
||||
}
|
||||
/**
|
||||
Shadow.prototype.preRender = /**
|
||||
* Pre-render is called at the start of the object render cycle, before any transforms have taken place.
|
||||
* It happens directly AFTER a canvas context.save has happened if added to a Camera.
|
||||
*/
|
||||
Shadow.prototype.preRender = function () {
|
||||
if (this.showShadow == true) {
|
||||
function () {
|
||||
// Shadow
|
||||
if(this.showShadow == true) {
|
||||
this.game.stage.context.shadowColor = this.shadowColor;
|
||||
this.game.stage.context.shadowBlur = this.shadowBlur;
|
||||
this.game.stage.context.shadowOffsetX = this.shadowOffset.x;
|
||||
this.game.stage.context.shadowOffsetY = this.shadowOffset.y;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
Shadow.prototype.render = /**
|
||||
* render is called during the objects render cycle, right after all transforms have finished, but before any children/image data is rendered.
|
||||
*/
|
||||
Shadow.prototype.render = function () {
|
||||
if (this.showShadow == true) {
|
||||
function () {
|
||||
// Shadow off
|
||||
if(this.showShadow == true) {
|
||||
this.game.stage.context.shadowBlur = 0;
|
||||
this.game.stage.context.shadowOffsetX = 0;
|
||||
this.game.stage.context.shadowOffsetY = 0;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
|
@ -28,7 +27,10 @@ var Phaser;
|
|||
this._fxShakePrevY = 0;
|
||||
this.camera = parent;
|
||||
}
|
||||
/**
|
||||
Shake.SHAKE_BOTH_AXES = 0;
|
||||
Shake.SHAKE_HORIZONTAL_ONLY = 1;
|
||||
Shake.SHAKE_VERTICAL_ONLY = 2;
|
||||
Shake.prototype.start = /**
|
||||
* A simple camera shake effect.
|
||||
*
|
||||
* @param Intensity Percentage of screen size representing the maximum distance that the screen can move while shaking.
|
||||
|
@ -37,62 +39,54 @@ var Phaser;
|
|||
* @param Force Force the effect to reset (default = true, unlike flash() and fade()!).
|
||||
* @param Direction Whether to shake on both axes, just up and down, or just side to side (use class constants SHAKE_BOTH_AXES, SHAKE_VERTICAL_ONLY, or SHAKE_HORIZONTAL_ONLY).
|
||||
*/
|
||||
Shake.prototype.start = function (intensity, duration, onComplete, force, direction) {
|
||||
function (intensity, duration, onComplete, force, direction) {
|
||||
if (typeof intensity === "undefined") { intensity = 0.05; }
|
||||
if (typeof duration === "undefined") { duration = 0.5; }
|
||||
if (typeof onComplete === "undefined") { onComplete = null; }
|
||||
if (typeof force === "undefined") { force = true; }
|
||||
if (typeof direction === "undefined") { direction = Shake.SHAKE_BOTH_AXES; }
|
||||
if (!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))) {
|
||||
if(!force && ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0))) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) {
|
||||
// If a shake is not already running we need to store the offsets here
|
||||
if(this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) {
|
||||
this._fxShakePrevX = this.camera.x;
|
||||
this._fxShakePrevY = this.camera.y;
|
||||
}
|
||||
|
||||
this._fxShakeIntensity = intensity;
|
||||
this._fxShakeDuration = duration;
|
||||
this._fxShakeComplete = onComplete;
|
||||
this._fxShakeDirection = direction;
|
||||
this._fxShakeOffset.setTo(0, 0);
|
||||
};
|
||||
|
||||
Shake.prototype.postUpdate = function () {
|
||||
if (this._fxShakeDuration > 0) {
|
||||
// Update the "shake" special effect
|
||||
if(this._fxShakeDuration > 0) {
|
||||
this._fxShakeDuration -= this.game.time.elapsed;
|
||||
|
||||
if (this.game.math.roundTo(this._fxShakeDuration, -2) <= 0) {
|
||||
if(this.game.math.roundTo(this._fxShakeDuration, -2) <= 0) {
|
||||
this._fxShakeDuration = 0;
|
||||
this._fxShakeOffset.setTo(0, 0);
|
||||
this.camera.x = this._fxShakePrevX;
|
||||
this.camera.y = this._fxShakePrevY;
|
||||
|
||||
if (this._fxShakeComplete != null) {
|
||||
if(this._fxShakeComplete != null) {
|
||||
this._fxShakeComplete();
|
||||
}
|
||||
} else {
|
||||
if ((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_HORIZONTAL_ONLY)) {
|
||||
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_HORIZONTAL_ONLY)) {
|
||||
this._fxShakeOffset.x = (this.game.rnd.integer * this._fxShakeIntensity * this.camera.worldView.width * 2 - this._fxShakeIntensity * this.camera.worldView.width);
|
||||
}
|
||||
|
||||
if ((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_VERTICAL_ONLY)) {
|
||||
if((this._fxShakeDirection == Shake.SHAKE_BOTH_AXES) || (this._fxShakeDirection == Shake.SHAKE_VERTICAL_ONLY)) {
|
||||
this._fxShakeOffset.y = (this.game.rnd.integer * this._fxShakeIntensity * this.camera.worldView.height * 2 - this._fxShakeIntensity * this.camera.worldView.height);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Shake.prototype.preRender = function () {
|
||||
if ((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0)) {
|
||||
if((this._fxShakeOffset.x != 0) || (this._fxShakeOffset.y != 0)) {
|
||||
this.camera.x = this._fxShakePrevX + this._fxShakeOffset.x;
|
||||
this.camera.y = this._fxShakePrevY + this._fxShakeOffset.y;
|
||||
}
|
||||
};
|
||||
Shake.SHAKE_BOTH_AXES = 0;
|
||||
Shake.SHAKE_HORIZONTAL_ONLY = 1;
|
||||
Shake.SHAKE_VERTICAL_ONLY = 2;
|
||||
return Shake;
|
||||
})(Phaser.Plugin);
|
||||
CameraFX.Shake = Shake;
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
|
@ -16,58 +15,50 @@ var Phaser;
|
|||
__extends(Example, _super);
|
||||
function Example(game, parent) {
|
||||
_super.call(this, game, parent);
|
||||
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
|
||||
this.hasPreUpdate = false;
|
||||
this.hasUpdate = false;
|
||||
this.hasPostUpdate = false;
|
||||
|
||||
this.hasPreRender = false;
|
||||
this.hasRender = false;
|
||||
this.hasPostRender = false;
|
||||
}
|
||||
/**
|
||||
Example.prototype.preUpdate = /**
|
||||
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
Example.prototype.preUpdate = function () {
|
||||
function () {
|
||||
};
|
||||
|
||||
/**
|
||||
Example.prototype.update = /**
|
||||
* Pre-update is called at the start of the update cycle, after all the core system updates have taken place, but before the world update.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
Example.prototype.update = function () {
|
||||
function () {
|
||||
};
|
||||
|
||||
/**
|
||||
Example.prototype.postUpdate = /**
|
||||
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
Example.prototype.postUpdate = function () {
|
||||
function () {
|
||||
};
|
||||
|
||||
/**
|
||||
Example.prototype.preRender = /**
|
||||
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
Example.prototype.preRender = function () {
|
||||
function () {
|
||||
};
|
||||
|
||||
/**
|
||||
Example.prototype.render = /**
|
||||
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
Example.prototype.render = function () {
|
||||
function () {
|
||||
};
|
||||
|
||||
/**
|
||||
Example.prototype.postRender = /**
|
||||
* Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
Example.prototype.postRender = function () {
|
||||
function () {
|
||||
};
|
||||
return Example;
|
||||
})(Phaser.Plugin);
|
||||
|
|
|
@ -58,6 +58,8 @@ ToDo before release
|
|||
* Finish the Docs!
|
||||
* Getting Started guide!
|
||||
* Sprite Sheet / Atlas support for Dynamic Textures
|
||||
* Check browser support: OS X and iOS7 + Chrome Android latest
|
||||
* Tweening + collision - what happens?
|
||||
|
||||
|
||||
Mobile Optimisation Suggestions
|
||||
|
|
Binary file not shown.
0
Phaser/.gitignore → TS Source/.gitignore
vendored
0
Phaser/.gitignore → TS Source/.gitignore
vendored
455
TS Source/Game.js
Normal file
455
TS Source/Game.js
Normal file
|
@ -0,0 +1,455 @@
|
|||
/// <reference path="_definitions.ts" />
|
||||
/**
|
||||
* Game
|
||||
*
|
||||
* This is where the magic happens. The Game object is the heart of your game,
|
||||
* providing quick access to common functions and handling the boot process.
|
||||
*
|
||||
* "Hell, there are no rules here - we're trying to accomplish something."
|
||||
* Thomas A. Edison
|
||||
*
|
||||
* @package Phaser.Game
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Game = (function () {
|
||||
/**
|
||||
* Game constructor
|
||||
*
|
||||
* Instantiate a new <code>Phaser.Game</code> object.
|
||||
*
|
||||
* @constructor
|
||||
* @param callbackContext Which context will the callbacks be called with.
|
||||
* @param parent {string} ID of its parent DOM element.
|
||||
* @param width {number} The width of your game in game pixels.
|
||||
* @param height {number} The height of your game in game pixels.
|
||||
* @param preloadCallback {function} Preload callback invoked when init default screen.
|
||||
* @param createCallback {function} Create callback invoked when create default screen.
|
||||
* @param updateCallback {function} Update callback invoked when update default screen.
|
||||
* @param renderCallback {function} Render callback invoked when render default screen.
|
||||
* @param destroyCallback {function} Destroy callback invoked when state is destroyed.
|
||||
*/
|
||||
function Game(callbackContext, parent, width, height, preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
|
||||
if (typeof parent === "undefined") { parent = ''; }
|
||||
if (typeof width === "undefined") { width = 800; }
|
||||
if (typeof height === "undefined") { height = 600; }
|
||||
if (typeof preloadCallback === "undefined") { preloadCallback = null; }
|
||||
if (typeof createCallback === "undefined") { createCallback = null; }
|
||||
if (typeof updateCallback === "undefined") { updateCallback = null; }
|
||||
if (typeof renderCallback === "undefined") { renderCallback = null; }
|
||||
if (typeof destroyCallback === "undefined") { destroyCallback = null; }
|
||||
var _this = this;
|
||||
/**
|
||||
* Whether load complete loading or not.
|
||||
* @type {bool}
|
||||
*/
|
||||
this._loadComplete = false;
|
||||
/**
|
||||
* Game is paused?
|
||||
* @type {bool}
|
||||
*/
|
||||
this._paused = false;
|
||||
/**
|
||||
* The state to be switched to in the next frame.
|
||||
* @type {State}
|
||||
*/
|
||||
this._pendingState = null;
|
||||
/**
|
||||
* The current State object (defaults to null)
|
||||
* @type {State}
|
||||
*/
|
||||
this.state = null;
|
||||
/**
|
||||
* This will be called when init states. (loading assets...)
|
||||
* @type {function}
|
||||
*/
|
||||
this.onPreloadCallback = null;
|
||||
/**
|
||||
* This will be called when create states. (setup states...)
|
||||
* @type {function}
|
||||
*/
|
||||
this.onCreateCallback = null;
|
||||
/**
|
||||
* This will be called when State is updated, this doesn't happen during load (see onLoadUpdateCallback)
|
||||
* @type {function}
|
||||
*/
|
||||
this.onUpdateCallback = null;
|
||||
/**
|
||||
* This will be called when the State is rendered, this doesn't happen during load (see onLoadRenderCallback)
|
||||
* @type {function}
|
||||
*/
|
||||
this.onRenderCallback = null;
|
||||
/**
|
||||
* This will be called before the State is rendered and before the stage is cleared
|
||||
* @type {function}
|
||||
*/
|
||||
this.onPreRenderCallback = null;
|
||||
/**
|
||||
* This will be called when the State is updated but only during the load process
|
||||
* @type {function}
|
||||
*/
|
||||
this.onLoadUpdateCallback = null;
|
||||
/**
|
||||
* This will be called when the State is rendered but only during the load process
|
||||
* @type {function}
|
||||
*/
|
||||
this.onLoadRenderCallback = null;
|
||||
/**
|
||||
* This will be called when states paused.
|
||||
* @type {function}
|
||||
*/
|
||||
this.onPausedCallback = null;
|
||||
/**
|
||||
* This will be called when the state is destroyed (i.e. swapping to a new state)
|
||||
* @type {function}
|
||||
*/
|
||||
this.onDestroyCallback = null;
|
||||
/**
|
||||
* Whether the game engine is booted, aka available.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.isBooted = false;
|
||||
/**
|
||||
* Is game running or paused?
|
||||
* @type {bool}
|
||||
*/
|
||||
this.isRunning = false;
|
||||
// Single instance check
|
||||
if(window['PhaserGlobal'] && window['PhaserGlobal'].singleInstance) {
|
||||
if(Phaser.GAMES.length > 0) {
|
||||
console.log('Phaser detected an instance of this game already running, aborting');
|
||||
return;
|
||||
}
|
||||
}
|
||||
this.id = Phaser.GAMES.push(this) - 1;
|
||||
this.callbackContext = callbackContext;
|
||||
this.onPreloadCallback = preloadCallback;
|
||||
this.onCreateCallback = createCallback;
|
||||
this.onUpdateCallback = updateCallback;
|
||||
this.onRenderCallback = renderCallback;
|
||||
this.onDestroyCallback = destroyCallback;
|
||||
if(document.readyState === 'complete' || document.readyState === 'interactive') {
|
||||
setTimeout(function () {
|
||||
return Phaser.GAMES[_this.id].boot(parent, width, height);
|
||||
});
|
||||
} else {
|
||||
document.addEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot(parent, width, height), false);
|
||||
window.addEventListener('load', Phaser.GAMES[this.id].boot(parent, width, height), false);
|
||||
}
|
||||
}
|
||||
Game.prototype.boot = /**
|
||||
* Initialize engine sub modules and start the game.
|
||||
* @param parent {string} ID of parent Dom element.
|
||||
* @param width {number} Width of the game screen.
|
||||
* @param height {number} Height of the game screen.
|
||||
*/
|
||||
function (parent, width, height) {
|
||||
var _this = this;
|
||||
if(this.isBooted == true) {
|
||||
return;
|
||||
}
|
||||
if(!document.body) {
|
||||
setTimeout(function () {
|
||||
return Phaser.GAMES[_this.id].boot(parent, width, height);
|
||||
}, 13);
|
||||
} else {
|
||||
document.removeEventListener('DOMContentLoaded', Phaser.GAMES[this.id].boot);
|
||||
window.removeEventListener('load', Phaser.GAMES[this.id].boot);
|
||||
this.onPause = new Phaser.Signal();
|
||||
this.onResume = new Phaser.Signal();
|
||||
this.device = new Phaser.Device();
|
||||
this.net = new Phaser.Net(this);
|
||||
this.math = new Phaser.GameMath(this);
|
||||
this.stage = new Phaser.Stage(this, parent, width, height);
|
||||
this.world = new Phaser.World(this, width, height);
|
||||
this.add = new Phaser.GameObjectFactory(this);
|
||||
this.cache = new Phaser.Cache(this);
|
||||
this.load = new Phaser.Loader(this);
|
||||
this.time = new Phaser.TimeManager(this);
|
||||
this.tweens = new Phaser.TweenManager(this);
|
||||
this.input = new Phaser.InputManager(this);
|
||||
this.sound = new Phaser.SoundManager(this);
|
||||
this.rnd = new Phaser.RandomDataGenerator([
|
||||
(Date.now() * Math.random()).toString()
|
||||
]);
|
||||
this.physics = new Phaser.Physics.PhysicsManager(this);
|
||||
this.plugins = new Phaser.PluginManager(this, this);
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
this.setRenderer(Phaser.Types.RENDERER_CANVAS);
|
||||
this.world.boot();
|
||||
this.stage.boot();
|
||||
this.input.boot();
|
||||
this.isBooted = true;
|
||||
// Set-up some static helper references
|
||||
Phaser.DebugUtils.game = this;
|
||||
Phaser.ColorUtils.game = this;
|
||||
Phaser.DebugUtils.context = this.stage.context;
|
||||
// Display the default game screen?
|
||||
if(this.onPreloadCallback == null && this.onCreateCallback == null && this.onUpdateCallback == null && this.onRenderCallback == null && this._pendingState == null) {
|
||||
this._raf = new Phaser.RequestAnimationFrame(this, this.bootLoop);
|
||||
} else {
|
||||
this.isRunning = true;
|
||||
this._loadComplete = false;
|
||||
this._raf = new Phaser.RequestAnimationFrame(this, this.loop);
|
||||
if(this._pendingState) {
|
||||
this.switchState(this._pendingState, false, false);
|
||||
} else {
|
||||
this.startState();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Game.prototype.loadComplete = /**
|
||||
* Called when the load has finished after preload was run.
|
||||
*/
|
||||
function () {
|
||||
this._loadComplete = true;
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
};
|
||||
Game.prototype.bootLoop = /**
|
||||
* The bootLoop is called while the game is still booting (waiting for the DOM and resources to be available)
|
||||
*/
|
||||
function () {
|
||||
this.tweens.update();
|
||||
this.input.update();
|
||||
this.stage.update();
|
||||
};
|
||||
Game.prototype.pausedLoop = /**
|
||||
* The pausedLoop is called when the game is paused.
|
||||
*/
|
||||
function () {
|
||||
this.tweens.update();
|
||||
this.input.update();
|
||||
this.stage.update();
|
||||
this.sound.update();
|
||||
if(this.onPausedCallback !== null) {
|
||||
this.onPausedCallback.call(this.callbackContext);
|
||||
}
|
||||
};
|
||||
Game.prototype.loop = /**
|
||||
* Game loop method will be called when it's running.
|
||||
*/
|
||||
function () {
|
||||
this.plugins.preUpdate();
|
||||
this.tweens.update();
|
||||
this.input.update();
|
||||
this.stage.update();
|
||||
this.sound.update();
|
||||
this.physics.update();
|
||||
this.world.update();
|
||||
this.plugins.update();
|
||||
if(this._loadComplete && this.onUpdateCallback) {
|
||||
this.onUpdateCallback.call(this.callbackContext);
|
||||
} else if(this._loadComplete == false && this.onLoadUpdateCallback) {
|
||||
this.onLoadUpdateCallback.call(this.callbackContext);
|
||||
}
|
||||
this.world.postUpdate();
|
||||
this.plugins.postUpdate();
|
||||
this.plugins.preRender();
|
||||
if(this._loadComplete && this.onPreRenderCallback) {
|
||||
this.onPreRenderCallback.call(this.callbackContext);
|
||||
}
|
||||
this.renderer.render();
|
||||
this.plugins.render();
|
||||
if(this._loadComplete && this.onRenderCallback) {
|
||||
this.onRenderCallback.call(this.callbackContext);
|
||||
} else if(this._loadComplete == false && this.onLoadRenderCallback) {
|
||||
this.onLoadRenderCallback.call(this.callbackContext);
|
||||
}
|
||||
this.plugins.postRender();
|
||||
};
|
||||
Game.prototype.startState = /**
|
||||
* Start current state.
|
||||
*/
|
||||
function () {
|
||||
if(this.onPreloadCallback !== null) {
|
||||
this.load.reset();
|
||||
this.onPreloadCallback.call(this.callbackContext);
|
||||
// Is the loader empty?
|
||||
if(this.load.queueSize == 0) {
|
||||
if(this.onCreateCallback !== null) {
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
this._loadComplete = true;
|
||||
} else {
|
||||
// Start the loader going as we have something in the queue
|
||||
this.load.onLoadComplete.add(this.loadComplete, this);
|
||||
this.load.start();
|
||||
}
|
||||
} else {
|
||||
// No init? Then there was nothing to load either
|
||||
if(this.onCreateCallback !== null) {
|
||||
this.onCreateCallback.call(this.callbackContext);
|
||||
}
|
||||
this._loadComplete = true;
|
||||
}
|
||||
};
|
||||
Game.prototype.setRenderer = function (renderer) {
|
||||
switch(renderer) {
|
||||
case Phaser.Types.RENDERER_AUTO_DETECT:
|
||||
this.renderer = new Phaser.Renderer.Headless.HeadlessRenderer(this);
|
||||
break;
|
||||
case Phaser.Types.RENDERER_AUTO_DETECT:
|
||||
case Phaser.Types.RENDERER_CANVAS:
|
||||
this.renderer = new Phaser.Renderer.Canvas.CanvasRenderer(this);
|
||||
break;
|
||||
// WebGL coming soon :)
|
||||
}
|
||||
};
|
||||
Game.prototype.setCallbacks = /**
|
||||
* Set the most common state callbacks (init, create, update, render).
|
||||
* @param preloadCallback {function} Init callback invoked when init state.
|
||||
* @param createCallback {function} Create callback invoked when create state.
|
||||
* @param updateCallback {function} Update callback invoked when update state.
|
||||
* @param renderCallback {function} Render callback invoked when render state.
|
||||
* @param destroyCallback {function} Destroy callback invoked when state is destroyed.
|
||||
*/
|
||||
function (preloadCallback, createCallback, updateCallback, renderCallback, destroyCallback) {
|
||||
if (typeof preloadCallback === "undefined") { preloadCallback = null; }
|
||||
if (typeof createCallback === "undefined") { createCallback = null; }
|
||||
if (typeof updateCallback === "undefined") { updateCallback = null; }
|
||||
if (typeof renderCallback === "undefined") { renderCallback = null; }
|
||||
if (typeof destroyCallback === "undefined") { destroyCallback = null; }
|
||||
this.onPreloadCallback = preloadCallback;
|
||||
this.onCreateCallback = createCallback;
|
||||
this.onUpdateCallback = updateCallback;
|
||||
this.onRenderCallback = renderCallback;
|
||||
this.onDestroyCallback = destroyCallback;
|
||||
};
|
||||
Game.prototype.switchState = /**
|
||||
* Switch to a new State.
|
||||
* @param state {State} The state you want to switch to.
|
||||
* @param [clearWorld] {bool} clear everything in the world? (Default to true)
|
||||
* @param [clearCache] {bool} clear asset cache? (Default to false and ONLY available when clearWorld=true)
|
||||
*/
|
||||
function (state, clearWorld, clearCache) {
|
||||
if (typeof clearWorld === "undefined") { clearWorld = true; }
|
||||
if (typeof clearCache === "undefined") { clearCache = false; }
|
||||
if(this.isBooted == false) {
|
||||
this._pendingState = state;
|
||||
return;
|
||||
}
|
||||
// Destroy current state?
|
||||
if(this.onDestroyCallback !== null) {
|
||||
this.onDestroyCallback.call(this.callbackContext);
|
||||
}
|
||||
this.input.reset(true);
|
||||
// Prototype?
|
||||
if(typeof state === 'function') {
|
||||
this.state = new state(this);
|
||||
} else {
|
||||
this.state = state;
|
||||
}
|
||||
// Ok, have we got the right functions?
|
||||
if(this.state['create'] || this.state['update']) {
|
||||
this.callbackContext = this.state;
|
||||
this.onPreloadCallback = null;
|
||||
this.onLoadRenderCallback = null;
|
||||
this.onLoadUpdateCallback = null;
|
||||
this.onCreateCallback = null;
|
||||
this.onUpdateCallback = null;
|
||||
this.onRenderCallback = null;
|
||||
this.onPreRenderCallback = null;
|
||||
this.onPausedCallback = null;
|
||||
this.onDestroyCallback = null;
|
||||
// Bingo, let's set them up
|
||||
if(this.state['preload']) {
|
||||
this.onPreloadCallback = this.state['preload'];
|
||||
}
|
||||
if(this.state['loadRender']) {
|
||||
this.onLoadRenderCallback = this.state['loadRender'];
|
||||
}
|
||||
if(this.state['loadUpdate']) {
|
||||
this.onLoadUpdateCallback = this.state['loadUpdate'];
|
||||
}
|
||||
if(this.state['create']) {
|
||||
this.onCreateCallback = this.state['create'];
|
||||
}
|
||||
if(this.state['update']) {
|
||||
this.onUpdateCallback = this.state['update'];
|
||||
}
|
||||
if(this.state['preRender']) {
|
||||
this.onPreRenderCallback = this.state['preRender'];
|
||||
}
|
||||
if(this.state['render']) {
|
||||
this.onRenderCallback = this.state['render'];
|
||||
}
|
||||
if(this.state['paused']) {
|
||||
this.onPausedCallback = this.state['paused'];
|
||||
}
|
||||
if(this.state['destroy']) {
|
||||
this.onDestroyCallback = this.state['destroy'];
|
||||
}
|
||||
if(clearWorld) {
|
||||
this.world.destroy();
|
||||
if(clearCache == true) {
|
||||
this.cache.destroy();
|
||||
}
|
||||
}
|
||||
this._loadComplete = false;
|
||||
this.startState();
|
||||
} else {
|
||||
throw new Error("Invalid State object given. Must contain at least a create or update function.");
|
||||
}
|
||||
};
|
||||
Game.prototype.destroy = /**
|
||||
* Nuke the entire game from orbit
|
||||
*/
|
||||
function () {
|
||||
this.callbackContext = null;
|
||||
this.onPreloadCallback = null;
|
||||
this.onLoadRenderCallback = null;
|
||||
this.onLoadUpdateCallback = null;
|
||||
this.onCreateCallback = null;
|
||||
this.onUpdateCallback = null;
|
||||
this.onRenderCallback = null;
|
||||
this.onPausedCallback = null;
|
||||
this.onDestroyCallback = null;
|
||||
this.cache = null;
|
||||
this.input = null;
|
||||
this.load = null;
|
||||
this.sound = null;
|
||||
this.stage = null;
|
||||
this.time = null;
|
||||
this.world = null;
|
||||
this.isBooted = false;
|
||||
};
|
||||
Object.defineProperty(Game.prototype, "paused", {
|
||||
get: function () {
|
||||
return this._paused;
|
||||
},
|
||||
set: function (value) {
|
||||
if(value == true && this._paused == false) {
|
||||
this._paused = true;
|
||||
this.onPause.dispatch();
|
||||
this.sound.pauseAll();
|
||||
this._raf.callback = this.pausedLoop;
|
||||
} else if(value == false && this._paused == true) {
|
||||
this._paused = false;
|
||||
this.onResume.dispatch();
|
||||
this.input.reset();
|
||||
this.sound.resumeAll();
|
||||
if(this.isRunning == false) {
|
||||
this._raf.callback = this.bootLoop;
|
||||
} else {
|
||||
this._raf.callback = this.loop;
|
||||
}
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Game.prototype, "camera", {
|
||||
get: function () {
|
||||
return this.world.cameras.current;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Game;
|
||||
})();
|
||||
Phaser.Game = Game;
|
||||
})(Phaser || (Phaser = {}));
|
23
TS Source/Phaser.js
Normal file
23
TS Source/Phaser.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
/// <reference path="_definitions.ts" />
|
||||
/**
|
||||
* Phaser - http://www.phaser.io
|
||||
*
|
||||
* v1.0.0 - August 12th 2013
|
||||
*
|
||||
* A feature-packed 2D canvas game framework born from the firey pits of Flixel and
|
||||
* constructed via plenty of blood, sweat, tears and coffee by Richard Davey (@photonstorm).
|
||||
*
|
||||
* Many thanks to Adam Saltsman (@ADAMATOMIC) for releasing Flixel, from both which Phaser
|
||||
* and my love of game development originate.
|
||||
*
|
||||
* Follow Phaser progress at http://www.photonstorm.com
|
||||
*
|
||||
* "If you want your children to be intelligent, read them fairy tales."
|
||||
* "If you want them to be more intelligent, read them more fairy tales."
|
||||
* -- Albert Einstein
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
Phaser.VERSION = 'Phaser version 1.0.0';
|
||||
Phaser.GAMES = [];
|
||||
})(Phaser || (Phaser = {}));
|
282
TS Source/Stage.js
Normal file
282
TS Source/Stage.js
Normal file
|
@ -0,0 +1,282 @@
|
|||
/// <reference path="_definitions.ts" />
|
||||
/**
|
||||
* Stage
|
||||
*
|
||||
* The Stage controls the canvas on which everything is displayed. It handles display within the browser,
|
||||
* focus handling, game resizing, scaling and the pause, boot and orientation screens.
|
||||
*
|
||||
* @package Phaser.Stage
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Stage = (function () {
|
||||
/**
|
||||
* Stage constructor
|
||||
*
|
||||
* Create a new <code>Stage</code> with specific width and height.
|
||||
*
|
||||
* @param parent {number} ID of parent DOM element.
|
||||
* @param width {number} Width of the stage.
|
||||
* @param height {number} Height of the stage.
|
||||
*/
|
||||
function Stage(game, parent, width, height) {
|
||||
var _this = this;
|
||||
/**
|
||||
* Background color of the stage (defaults to black). Set via the public backgroundColor property.
|
||||
* @type {string}
|
||||
*/
|
||||
this._backgroundColor = 'rgb(0,0,0)';
|
||||
/**
|
||||
* Clear the whole stage every frame? (Default to true)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.clear = true;
|
||||
/**
|
||||
* Do not use pause screen when game is paused?
|
||||
* (Default to false, aka always use PauseScreen)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disablePauseScreen = false;
|
||||
/**
|
||||
* Do not use boot screen when engine starts?
|
||||
* (Default to false, aka always use BootScreen)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disableBootScreen = false;
|
||||
/**
|
||||
* If set to true the game will never pause when the browser or browser tab loses focuses
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disableVisibilityChange = false;
|
||||
this.game = game;
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = height;
|
||||
this.context = this.canvas.getContext('2d');
|
||||
Phaser.CanvasUtils.addToDOM(this.canvas, parent, true);
|
||||
Phaser.CanvasUtils.setTouchAction(this.canvas);
|
||||
this.canvas.oncontextmenu = function (event) {
|
||||
event.preventDefault();
|
||||
};
|
||||
this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
|
||||
this.scaleMode = Phaser.StageScaleMode.NO_SCALE;
|
||||
this.scale = new Phaser.StageScaleMode(this.game, width, height);
|
||||
this.getOffset(this.canvas);
|
||||
this.bounds = new Phaser.Rectangle(this.offset.x, this.offset.y, width, height);
|
||||
this.aspectRatio = width / height;
|
||||
document.addEventListener('visibilitychange', function (event) {
|
||||
return _this.visibilityChange(event);
|
||||
}, false);
|
||||
document.addEventListener('webkitvisibilitychange', function (event) {
|
||||
return _this.visibilityChange(event);
|
||||
}, false);
|
||||
document.addEventListener('pagehide', function (event) {
|
||||
return _this.visibilityChange(event);
|
||||
}, false);
|
||||
document.addEventListener('pageshow', function (event) {
|
||||
return _this.visibilityChange(event);
|
||||
}, false);
|
||||
window.onblur = function (event) {
|
||||
return _this.visibilityChange(event);
|
||||
};
|
||||
window.onfocus = function (event) {
|
||||
return _this.visibilityChange(event);
|
||||
};
|
||||
}
|
||||
Stage.prototype.boot = /**
|
||||
* Stage boot
|
||||
*/
|
||||
function () {
|
||||
this.bootScreen = new Phaser.BootScreen(this.game);
|
||||
this.pauseScreen = new Phaser.PauseScreen(this.game, this.width, this.height);
|
||||
this.orientationScreen = new Phaser.OrientationScreen(this.game);
|
||||
this.scale.setScreenSize(true);
|
||||
};
|
||||
Stage.prototype.update = /**
|
||||
* Update stage for rendering. This will handle scaling, clearing
|
||||
* and PauseScreen/BootScreen updating and rendering.
|
||||
*/
|
||||
function () {
|
||||
this.scale.update();
|
||||
this.context.setTransform(1, 0, 0, 1, 0, 0);
|
||||
if(this.clear || (this.game.paused && this.disablePauseScreen == false)) {
|
||||
if(this.game.device.patchAndroidClearRectBug) {
|
||||
this.context.fillStyle = this._backgroundColor;
|
||||
this.context.fillRect(0, 0, this.width, this.height);
|
||||
} else {
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
}
|
||||
if(this.game.paused && this.scale.incorrectOrientation) {
|
||||
this.orientationScreen.update();
|
||||
this.orientationScreen.render();
|
||||
return;
|
||||
}
|
||||
if(this.game.isRunning == false && this.disableBootScreen == false) {
|
||||
this.bootScreen.update();
|
||||
this.bootScreen.render();
|
||||
}
|
||||
if(this.game.paused && this.disablePauseScreen == false) {
|
||||
this.pauseScreen.update();
|
||||
this.pauseScreen.render();
|
||||
}
|
||||
};
|
||||
Stage.prototype.visibilityChange = /**
|
||||
* This method is called when the canvas elements visibility is changed.
|
||||
*/
|
||||
function (event) {
|
||||
if(this.disableVisibilityChange) {
|
||||
return;
|
||||
}
|
||||
if(event.type == 'pagehide' || event.type == 'blur' || document['hidden'] == true || document['webkitHidden'] == true) {
|
||||
if(this.game.paused == false) {
|
||||
this.pauseGame();
|
||||
}
|
||||
} else {
|
||||
if(this.game.paused == true) {
|
||||
this.resumeGame();
|
||||
}
|
||||
}
|
||||
};
|
||||
Stage.prototype.enableOrientationCheck = function (forceLandscape, forcePortrait, imageKey) {
|
||||
if (typeof imageKey === "undefined") { imageKey = ''; }
|
||||
this.scale.forceLandscape = forceLandscape;
|
||||
this.scale.forcePortrait = forcePortrait;
|
||||
this.orientationScreen.enable(imageKey);
|
||||
if(forceLandscape || forcePortrait) {
|
||||
if((this.scale.isLandscape && forcePortrait) || (this.scale.isPortrait && forceLandscape)) {
|
||||
// They are in the wrong orientation right now
|
||||
this.game.paused = true;
|
||||
this.scale.incorrectOrientation = true;
|
||||
} else {
|
||||
this.scale.incorrectOrientation = false;
|
||||
}
|
||||
}
|
||||
};
|
||||
Stage.prototype.pauseGame = function () {
|
||||
this.game.paused = true;
|
||||
if(this.disablePauseScreen == false && this.pauseScreen) {
|
||||
this.pauseScreen.onPaused();
|
||||
}
|
||||
this.saveCanvasValues();
|
||||
};
|
||||
Stage.prototype.resumeGame = function () {
|
||||
if(this.disablePauseScreen == false && this.pauseScreen) {
|
||||
this.pauseScreen.onResume();
|
||||
}
|
||||
this.restoreCanvasValues();
|
||||
this.game.paused = false;
|
||||
};
|
||||
Stage.prototype.getOffset = /**
|
||||
* Get the DOM offset values of the given element
|
||||
*/
|
||||
function (element, populateOffset) {
|
||||
if (typeof populateOffset === "undefined") { populateOffset = true; }
|
||||
var box = element.getBoundingClientRect();
|
||||
var clientTop = element.clientTop || document.body.clientTop || 0;
|
||||
var clientLeft = element.clientLeft || document.body.clientLeft || 0;
|
||||
var scrollTop = window.pageYOffset || element.scrollTop || document.body.scrollTop;
|
||||
var scrollLeft = window.pageXOffset || element.scrollLeft || document.body.scrollLeft;
|
||||
if(populateOffset) {
|
||||
this.offset = new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
|
||||
return this.offset;
|
||||
} else {
|
||||
return new Phaser.Point(box.left + scrollLeft - clientLeft, box.top + scrollTop - clientTop);
|
||||
}
|
||||
};
|
||||
Stage.prototype.saveCanvasValues = /**
|
||||
* Save current canvas properties (strokeStyle, lineWidth and fillStyle) for later using.
|
||||
*/
|
||||
function () {
|
||||
this.strokeStyle = this.context.strokeStyle;
|
||||
this.lineWidth = this.context.lineWidth;
|
||||
this.fillStyle = this.context.fillStyle;
|
||||
};
|
||||
Stage.prototype.restoreCanvasValues = /**
|
||||
* Restore current canvas values (strokeStyle, lineWidth and fillStyle) with saved values.
|
||||
*/
|
||||
function () {
|
||||
this.context.strokeStyle = this.strokeStyle;
|
||||
this.context.lineWidth = this.lineWidth;
|
||||
this.context.fillStyle = this.fillStyle;
|
||||
if(this.game.device.patchAndroidClearRectBug) {
|
||||
this.context.fillStyle = this._backgroundColor;
|
||||
this.context.fillRect(0, 0, this.width, this.height);
|
||||
} else {
|
||||
this.context.clearRect(0, 0, this.width, this.height);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Stage.prototype, "backgroundColor", {
|
||||
get: function () {
|
||||
return this._backgroundColor;
|
||||
},
|
||||
set: function (color) {
|
||||
this.canvas.style.backgroundColor = color;
|
||||
this._backgroundColor = color;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "x", {
|
||||
get: function () {
|
||||
return this.bounds.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "y", {
|
||||
get: function () {
|
||||
return this.bounds.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "width", {
|
||||
get: function () {
|
||||
return this.bounds.width;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "height", {
|
||||
get: function () {
|
||||
return this.bounds.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "centerX", {
|
||||
get: function () {
|
||||
return this.bounds.halfWidth;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "centerY", {
|
||||
get: function () {
|
||||
return this.bounds.halfHeight;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "randomX", {
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.width);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Stage.prototype, "randomY", {
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.height);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Stage;
|
||||
})();
|
||||
Phaser.Stage = Stage;
|
||||
})(Phaser || (Phaser = {}));
|
83
TS Source/State.js
Normal file
83
TS Source/State.js
Normal file
|
@ -0,0 +1,83 @@
|
|||
/// <reference path="_definitions.ts" />
|
||||
/**
|
||||
* State
|
||||
*
|
||||
* This is a base State class which can be extended if you are creating your game with TypeScript.
|
||||
* It provides quick access to common functions such as the camera, cache, input, match, sound and more.
|
||||
*
|
||||
* @package Phaser.State
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var State = (function () {
|
||||
/**
|
||||
* State constructor
|
||||
* Create a new <code>State</code>.
|
||||
*/
|
||||
function State(game) {
|
||||
this.game = game;
|
||||
this.add = game.add;
|
||||
this.camera = game.camera;
|
||||
this.cache = game.cache;
|
||||
this.input = game.input;
|
||||
this.load = game.load;
|
||||
this.math = game.math;
|
||||
this.sound = game.sound;
|
||||
this.stage = game.stage;
|
||||
this.time = game.time;
|
||||
this.tweens = game.tweens;
|
||||
this.world = game.world;
|
||||
}
|
||||
State.prototype.init = // Override these in your own States
|
||||
/**
|
||||
* Override this method to add some load operations.
|
||||
* If you need to use the loader, you may need to use them here.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
State.prototype.create = /**
|
||||
* This method is called after the game engine successfully switches states.
|
||||
* Feel free to add any setup code here.(Do not load anything here, override init() instead)
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
State.prototype.update = /**
|
||||
* Put update logic here.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
State.prototype.render = /**
|
||||
* Put render operations here.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
State.prototype.paused = /**
|
||||
* This method will be called when game paused.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
State.prototype.destroy = /**
|
||||
* This method will be called when the state is destroyed
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
return State;
|
||||
})();
|
||||
Phaser.State = State;
|
||||
/**
|
||||
* Checks for overlaps between two objects using the world QuadTree. Can be GameObject vs. GameObject, GameObject vs. Group or Group vs. Group.
|
||||
* Note: Does not take the objects scrollFactor into account. All overlaps are check in world space.
|
||||
* @param object1 The first GameObject or Group to check. If null the world.group is used.
|
||||
* @param object2 The second GameObject or Group to check.
|
||||
* @param notifyCallback A callback function that is called if the objects overlap. The two objects will be passed to this function in the same order in which you passed them to Collision.overlap.
|
||||
* @param processCallback A callback function that lets you perform additional checks against the two objects if they overlap. If this is set then notifyCallback will only be called if processCallback returns true.
|
||||
* @param context The context in which the callbacks will be called
|
||||
* @returns {bool} true if the objects overlap, otherwise false.
|
||||
*/
|
||||
//public collide(objectOrGroup1 = null, objectOrGroup2 = null, notifyCallback = null, context? = this.game.callbackContext): bool {
|
||||
// return this.collision.overlap(objectOrGroup1, objectOrGroup2, notifyCallback, Collision.separate, context);
|
||||
//}
|
||||
})(Phaser || (Phaser = {}));
|
61
TS Source/Statics.js
Normal file
61
TS Source/Statics.js
Normal file
|
@ -0,0 +1,61 @@
|
|||
/// <reference path="_definitions.ts" />
|
||||
/**
|
||||
* Types
|
||||
*
|
||||
* This file contains all constants used through-out Phaser.
|
||||
*
|
||||
* @package Phaser.Types
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Types = (function () {
|
||||
function Types() { }
|
||||
Types.RENDERER_AUTO_DETECT = 0;
|
||||
Types.RENDERER_HEADLESS = 1;
|
||||
Types.RENDERER_CANVAS = 2;
|
||||
Types.RENDERER_WEBGL = 3;
|
||||
Types.CAMERA_TYPE_ORTHOGRAPHIC = 0;
|
||||
Types.CAMERA_TYPE_ISOMETRIC = 1;
|
||||
Types.CAMERA_FOLLOW_LOCKON = 0;
|
||||
Types.CAMERA_FOLLOW_PLATFORMER = 1;
|
||||
Types.CAMERA_FOLLOW_TOPDOWN = 2;
|
||||
Types.CAMERA_FOLLOW_TOPDOWN_TIGHT = 3;
|
||||
Types.GROUP = 0;
|
||||
Types.SPRITE = 1;
|
||||
Types.GEOMSPRITE = 2;
|
||||
Types.PARTICLE = 3;
|
||||
Types.EMITTER = 4;
|
||||
Types.TILEMAP = 5;
|
||||
Types.SCROLLZONE = 6;
|
||||
Types.BUTTON = 7;
|
||||
Types.DYNAMICTEXTURE = 8;
|
||||
Types.GEOM_POINT = 0;
|
||||
Types.GEOM_CIRCLE = 1;
|
||||
Types.GEOM_RECTANGLE = 2;
|
||||
Types.GEOM_LINE = 3;
|
||||
Types.GEOM_POLYGON = 4;
|
||||
Types.BODY_DISABLED = 0;
|
||||
Types.BODY_STATIC = 1;
|
||||
Types.BODY_KINETIC = 2;
|
||||
Types.BODY_DYNAMIC = 3;
|
||||
Types.OUT_OF_BOUNDS_KILL = 0;
|
||||
Types.OUT_OF_BOUNDS_DESTROY = 1;
|
||||
Types.OUT_OF_BOUNDS_PERSIST = 2;
|
||||
Types.SORT_ASCENDING = -1;
|
||||
Types.SORT_DESCENDING = 1;
|
||||
Types.LEFT = 0x0001;
|
||||
Types.RIGHT = 0x0010;
|
||||
Types.UP = 0x0100;
|
||||
Types.DOWN = 0x1000;
|
||||
Types.NONE = 0;
|
||||
Types.CEILING = 0x0100;
|
||||
Types.FLOOR = 0x1000;
|
||||
Types.WALL = 0x0001 | 0x0010;
|
||||
Types.ANY = 0x0001 | 0x0010 | 0x0100 | 0x1000;
|
||||
return Types;
|
||||
})();
|
||||
Phaser.Types = Types;
|
||||
})(Phaser || (Phaser = {}));
|
141
TS Source/World.js
Normal file
141
TS Source/World.js
Normal file
|
@ -0,0 +1,141 @@
|
|||
/// <reference path="_definitions.ts" />
|
||||
/**
|
||||
* World
|
||||
*
|
||||
* "This world is but a canvas to our imagination." - Henry David Thoreau
|
||||
*
|
||||
* A game has only one world. The world is an abstract place in which all game objects live. It is not bound
|
||||
* by stage limits and can be any size. You look into the world via cameras. All game objects live within
|
||||
* the world at world-based coordinates. By default a world is created the same size as your Stage.
|
||||
*
|
||||
* @package Phaser.World
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var World = (function () {
|
||||
/**
|
||||
* World constructor
|
||||
* Create a new <code>World</code> with specific width and height.
|
||||
*
|
||||
* @param width {number} Width of the world bound.
|
||||
* @param height {number} Height of the world bound.
|
||||
*/
|
||||
function World(game, width, height) {
|
||||
/**
|
||||
* Object container stores every object created with `create*` methods.
|
||||
* @type {Group}
|
||||
*/
|
||||
this._groupCounter = 0;
|
||||
this.game = game;
|
||||
this.cameras = new Phaser.CameraManager(this.game, 0, 0, width, height);
|
||||
this.bounds = new Phaser.Rectangle(0, 0, width, height);
|
||||
}
|
||||
World.prototype.getNextGroupID = function () {
|
||||
return this._groupCounter++;
|
||||
};
|
||||
World.prototype.boot = /**
|
||||
* Called once by Game during the boot process.
|
||||
*/
|
||||
function () {
|
||||
this.group = new Phaser.Group(this.game, 0);
|
||||
};
|
||||
World.prototype.update = /**
|
||||
* This is called automatically every frame, and is where main logic happens.
|
||||
*/
|
||||
function () {
|
||||
this.group.update();
|
||||
this.cameras.update();
|
||||
};
|
||||
World.prototype.postUpdate = /**
|
||||
* This is called automatically every frame, and is where main logic happens.
|
||||
*/
|
||||
function () {
|
||||
this.group.postUpdate();
|
||||
this.cameras.postUpdate();
|
||||
};
|
||||
World.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this.group.destroy();
|
||||
this.cameras.destroy();
|
||||
};
|
||||
World.prototype.setSize = /**
|
||||
* Updates the size of this world.
|
||||
*
|
||||
* @param width {number} New width of the world.
|
||||
* @param height {number} New height of the world.
|
||||
* @param [updateCameraBounds] {bool} Update camera bounds automatically or not. Default to true.
|
||||
*/
|
||||
function (width, height, updateCameraBounds) {
|
||||
if (typeof updateCameraBounds === "undefined") { updateCameraBounds = true; }
|
||||
this.bounds.width = width;
|
||||
this.bounds.height = height;
|
||||
if(updateCameraBounds == true) {
|
||||
this.game.camera.setBounds(0, 0, width, height);
|
||||
}
|
||||
// dispatch world resize event
|
||||
};
|
||||
Object.defineProperty(World.prototype, "width", {
|
||||
get: function () {
|
||||
return this.bounds.width;
|
||||
},
|
||||
set: function (value) {
|
||||
this.bounds.width = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(World.prototype, "height", {
|
||||
get: function () {
|
||||
return this.bounds.height;
|
||||
},
|
||||
set: function (value) {
|
||||
this.bounds.height = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(World.prototype, "centerX", {
|
||||
get: function () {
|
||||
return this.bounds.halfWidth;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(World.prototype, "centerY", {
|
||||
get: function () {
|
||||
return this.bounds.halfHeight;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(World.prototype, "randomX", {
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.width);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(World.prototype, "randomY", {
|
||||
get: function () {
|
||||
return Math.round(Math.random() * this.bounds.height);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
World.prototype.getAllCameras = /**
|
||||
* Get all the cameras.
|
||||
*
|
||||
* @returns {array} An array contains all the cameras.
|
||||
*/
|
||||
function () {
|
||||
return this.cameras.getAll();
|
||||
};
|
||||
return World;
|
||||
})();
|
||||
Phaser.World = World;
|
||||
})(Phaser || (Phaser = {}));
|
129
TS Source/_definitions.js
Normal file
129
TS Source/_definitions.js
Normal file
|
@ -0,0 +1,129 @@
|
|||
/// <reference path="Phaser.ts" />
|
||||
/// <reference path="Statics.ts" />
|
||||
/// <reference path="geom/Point.ts" />
|
||||
/// <reference path="geom/Rectangle.ts" />
|
||||
/// <reference path="geom/Circle.ts" />
|
||||
/// <reference path="geom/Line.ts" />
|
||||
/// <reference path="math/GameMath.ts" />
|
||||
/// <reference path="math/Vec2.ts" />
|
||||
/// <reference path="math/Vec2Utils.ts" />
|
||||
/// <reference path="math/Mat3.ts" />
|
||||
/// <reference path="math/Mat3Utils.ts" />
|
||||
/// <reference path="math/QuadTree.ts" />
|
||||
/// <reference path="math/LinkedList.ts" />
|
||||
/// <reference path="math/RandomDataGenerator.ts" />
|
||||
/// <reference path="core/Plugin.ts" />
|
||||
/// <reference path="core/PluginManager.ts" />
|
||||
/// <reference path="core/Signal.ts" />
|
||||
/// <reference path="core/SignalBinding.ts" />
|
||||
/// <reference path="core/Group.ts" />
|
||||
/// <reference path="cameras/Camera.ts" />
|
||||
/// <reference path="cameras/CameraManager.ts" />
|
||||
/// <reference path="display/CSS3Filters.ts" />
|
||||
/// <reference path="display/DynamicTexture.ts" />
|
||||
/// <reference path="display/Texture.ts" />
|
||||
/// <reference path="tweens/easing/Back.ts" />
|
||||
/// <reference path="tweens/easing/Bounce.ts" />
|
||||
/// <reference path="tweens/easing/Circular.ts" />
|
||||
/// <reference path="tweens/easing/Cubic.ts" />
|
||||
/// <reference path="tweens/easing/Elastic.ts" />
|
||||
/// <reference path="tweens/easing/Exponential.ts" />
|
||||
/// <reference path="tweens/easing/Linear.ts" />
|
||||
/// <reference path="tweens/easing/Quadratic.ts" />
|
||||
/// <reference path="tweens/easing/Quartic.ts" />
|
||||
/// <reference path="tweens/easing/Quintic.ts" />
|
||||
/// <reference path="tweens/easing/Sinusoidal.ts" />
|
||||
/// <reference path="tweens/Tween.ts" />
|
||||
/// <reference path="tweens/TweenManager.ts" />
|
||||
/// <reference path="time/TimeManager.ts" />
|
||||
/// <reference path="net/Net.ts" />
|
||||
/// <reference path="input/Keyboard.ts" />
|
||||
/// <reference path="input/Mouse.ts" />
|
||||
/// <reference path="input/MSPointer.ts" />
|
||||
/// <reference path="input/Touch.ts" />
|
||||
/// <reference path="input/Pointer.ts" />
|
||||
/// <reference path="input/InputHandler.ts" />
|
||||
/// <reference path="input/InputManager.ts" />
|
||||
/// <reference path="system/Device.ts" />
|
||||
/// <reference path="system/RequestAnimationFrame.ts" />
|
||||
/// <reference path="system/StageScaleMode.ts" />
|
||||
/// <reference path="system/screens/BootScreen.ts" />
|
||||
/// <reference path="system/screens/OrientationScreen.ts" />
|
||||
/// <reference path="system/screens/PauseScreen.ts" />
|
||||
/// <reference path="sound/SoundManager.ts" />
|
||||
/// <reference path="sound/Sound.ts" />
|
||||
/// <reference path="animation/Animation.ts" />
|
||||
/// <reference path="animation/AnimationManager.ts" />
|
||||
/// <reference path="animation/Frame.ts" />
|
||||
/// <reference path="animation/FrameData.ts" />
|
||||
/// <reference path="loader/Cache.ts" />
|
||||
/// <reference path="loader/Loader.ts" />
|
||||
/// <reference path="loader/AnimationLoader.ts" />
|
||||
/// <reference path="tilemap/Tile.ts" />
|
||||
/// <reference path="tilemap/Tilemap.ts" />
|
||||
/// <reference path="tilemap/TilemapLayer.ts" />
|
||||
/// <reference path="physics/PhysicsManager.ts" />
|
||||
/// <reference path="physics/Body.ts" />
|
||||
/// <reference path="physics/AABB.ts" />
|
||||
/// <reference path="physics/Circle.ts" />
|
||||
/// <reference path="physics/TileMapCell.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABB22Deg.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABB45Deg.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABB67Deg.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABBConcave.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABBConvex.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABBFull.ts" />
|
||||
/// <reference path="physics/aabb/ProjAABBHalf.ts" />
|
||||
/// <reference path="physics/circle/ProjCircle22Deg.ts" />
|
||||
/// <reference path="physics/circle/ProjCircle45Deg.ts" />
|
||||
/// <reference path="physics/circle/ProjCircle67Deg.ts" />
|
||||
/// <reference path="physics/circle/ProjCircleConcave.ts" />
|
||||
/// <reference path="physics/circle/ProjCircleConvex.ts" />
|
||||
/// <reference path="physics/circle/ProjCircleFull.ts" />
|
||||
/// <reference path="physics/circle/ProjCircleHalf.ts" />
|
||||
/// <reference path="gameobjects/Events.ts" />
|
||||
/// <reference path="gameobjects/Sprite.ts" />
|
||||
/// <reference path="gameobjects/TransformManager.ts" />
|
||||
/// <reference path="gameobjects/ScrollRegion.ts" />
|
||||
/// <reference path="gameobjects/ScrollZone.ts" />
|
||||
/// <reference path="gameobjects/IGameObject.ts" />
|
||||
/// <reference path="gameobjects/GameObjectFactory.ts" />
|
||||
/// <reference path="ui/Button.ts" />
|
||||
/// <reference path="utils/CanvasUtils.ts" />
|
||||
/// <reference path="utils/CircleUtils.ts" />
|
||||
/// <reference path="utils/ColorUtils.ts" />
|
||||
/// <reference path="utils/PointUtils.ts" />
|
||||
/// <reference path="utils/RectangleUtils.ts" />
|
||||
/// <reference path="utils/SpriteUtils.ts" />
|
||||
/// <reference path="utils/DebugUtils.ts" />
|
||||
/// <reference path="renderers/IRenderer.ts" />
|
||||
/// <reference path="renderers/HeadlessRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/CameraRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/GeometryRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/GroupRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/ScrollZoneRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/SpriteRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/TilemapRenderer.ts" />
|
||||
/// <reference path="renderers/canvas/CanvasRenderer.ts" />
|
||||
/// <reference path="particles/ParticleManager.ts" />
|
||||
/// <reference path="particles/Particle.ts" />
|
||||
/// <reference path="particles/Emitter.ts" />
|
||||
/// <reference path="particles/ParticlePool.ts" />
|
||||
/// <reference path="particles/ParticleUtils.ts" />
|
||||
/// <reference path="particles/Polar2D.ts" />
|
||||
/// <reference path="particles/Span.ts" />
|
||||
/// <reference path="particles/NumericalIntegration.ts" />
|
||||
/// <reference path="particles/behaviours/Behaviour.ts" />
|
||||
/// <reference path="particles/behaviours/RandomDrift.ts" />
|
||||
/// <reference path="particles/initialize/Initialize.ts" />
|
||||
/// <reference path="particles/initialize/Life.ts" />
|
||||
/// <reference path="particles/initialize/Mass.ts" />
|
||||
/// <reference path="particles/initialize/Position.ts" />
|
||||
/// <reference path="particles/initialize/Rate.ts" />
|
||||
/// <reference path="particles/initialize/Velocity.ts" />
|
||||
/// <reference path="particles/zone/Zone.ts" />
|
||||
/// <reference path="particles/zone/PointZone.ts" />
|
||||
/// <reference path="World.ts" />
|
||||
/// <reference path="Stage.ts" />
|
||||
/// <reference path="State.ts" />
|
||||
/// <reference path="Game.ts" />
|
153
TS Source/animation/Animation.js
Normal file
153
TS Source/animation/Animation.js
Normal file
|
@ -0,0 +1,153 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Animation
|
||||
*
|
||||
* An Animation instance contains a single animation and the controls to play it.
|
||||
* It is created by the AnimationManager and belongs to Game Objects such as Sprite.
|
||||
*
|
||||
* @package Phaser.Animation
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Animation = (function () {
|
||||
/**
|
||||
* Animation constructor
|
||||
* Create a new <code>Animation</code>.
|
||||
*
|
||||
* @param parent {Sprite} Owner sprite of this animation.
|
||||
* @param frameData {FrameData} The FrameData object contains animation data.
|
||||
* @param name {string} Unique name of this animation.
|
||||
* @param frames {number[]/string[]} An array of numbers or strings indicating what frames to play in what order.
|
||||
* @param delay {number} Time between frames in ms.
|
||||
* @param looped {bool} Whether or not the animation is looped or just plays once.
|
||||
*/
|
||||
function Animation(game, parent, frameData, name, frames, delay, looped) {
|
||||
this.game = game;
|
||||
this._parent = parent;
|
||||
this._frames = frames;
|
||||
this._frameData = frameData;
|
||||
this.name = name;
|
||||
this.delay = 1000 / delay;
|
||||
this.looped = looped;
|
||||
this.isFinished = false;
|
||||
this.isPlaying = false;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
}
|
||||
Object.defineProperty(Animation.prototype, "frameTotal", {
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Animation.prototype, "frame", {
|
||||
get: function () {
|
||||
if(this.currentFrame !== null) {
|
||||
return this.currentFrame.index;
|
||||
} else {
|
||||
return this._frameIndex;
|
||||
}
|
||||
},
|
||||
set: function (value) {
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
if(this.currentFrame !== null) {
|
||||
this._parent.texture.width = this.currentFrame.width;
|
||||
this._parent.texture.height = this.currentFrame.height;
|
||||
this._frameIndex = value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Animation.prototype.play = /**
|
||||
* Play this animation.
|
||||
* @param frameRate {number} FrameRate you want to specify instead of using default.
|
||||
* @param loop {bool} Whether or not the animation is looped or just plays once.
|
||||
*/
|
||||
function (frameRate, loop) {
|
||||
if (typeof frameRate === "undefined") { frameRate = null; }
|
||||
if (typeof loop === "undefined") { loop = null; }
|
||||
if(frameRate !== null) {
|
||||
this.delay = 1000 / frameRate;
|
||||
}
|
||||
if(loop !== null) {
|
||||
// If they set a new loop value then use it, otherwise use the default set on creation
|
||||
this.looped = loop;
|
||||
}
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this._timeLastFrame = this.game.time.now;
|
||||
this._timeNextFrame = this.game.time.now + this.delay;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
this._parent.events.onAnimationStart.dispatch(this._parent, this);
|
||||
return this;
|
||||
};
|
||||
Animation.prototype.restart = /**
|
||||
* Play this animation from the first frame.
|
||||
*/
|
||||
function () {
|
||||
this.isPlaying = true;
|
||||
this.isFinished = false;
|
||||
this._timeLastFrame = this.game.time.now;
|
||||
this._timeNextFrame = this.game.time.now + this.delay;
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
};
|
||||
Animation.prototype.stop = /**
|
||||
* Stop playing animation and set it finished.
|
||||
*/
|
||||
function () {
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
};
|
||||
Animation.prototype.update = /**
|
||||
* Update animation frames.
|
||||
*/
|
||||
function () {
|
||||
if(this.isPlaying == true && this.game.time.now >= this._timeNextFrame) {
|
||||
this._frameIndex++;
|
||||
if(this._frameIndex == this._frames.length) {
|
||||
if(this.looped) {
|
||||
this._frameIndex = 0;
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
this._parent.events.onAnimationLoop.dispatch(this._parent, this);
|
||||
} else {
|
||||
this.onComplete();
|
||||
}
|
||||
} else {
|
||||
this.currentFrame = this._frameData.getFrame(this._frames[this._frameIndex]);
|
||||
}
|
||||
this._timeLastFrame = this.game.time.now;
|
||||
this._timeNextFrame = this.game.time.now + this.delay;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Animation.prototype.destroy = /**
|
||||
* Clean up animation memory.
|
||||
*/
|
||||
function () {
|
||||
this.game = null;
|
||||
this._parent = null;
|
||||
this._frames = null;
|
||||
this._frameData = null;
|
||||
this.currentFrame = null;
|
||||
this.isPlaying = false;
|
||||
};
|
||||
Animation.prototype.onComplete = /**
|
||||
* Animation complete callback method.
|
||||
*/
|
||||
function () {
|
||||
this.isPlaying = false;
|
||||
this.isFinished = true;
|
||||
this._parent.events.onAnimationComplete.dispatch(this._parent, this);
|
||||
};
|
||||
return Animation;
|
||||
})();
|
||||
Phaser.Animation = Animation;
|
||||
})(Phaser || (Phaser = {}));
|
226
TS Source/animation/AnimationManager.js
Normal file
226
TS Source/animation/AnimationManager.js
Normal file
|
@ -0,0 +1,226 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* AnimationManager
|
||||
*
|
||||
* Any Game Object that supports animation contains a single AnimationManager instance. It is used to add,
|
||||
* play and update Phaser.Animation objects.
|
||||
*
|
||||
* @package Phaser.Components.AnimationManager
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
(function (Components) {
|
||||
var AnimationManager = (function () {
|
||||
/**
|
||||
* AnimationManager constructor
|
||||
* Create a new <code>AnimationManager</code>.
|
||||
*
|
||||
* @param parent {Sprite} Owner sprite of this manager.
|
||||
*/
|
||||
function AnimationManager(parent) {
|
||||
/**
|
||||
* Data contains animation frames.
|
||||
* @type {FrameData}
|
||||
*/
|
||||
this._frameData = null;
|
||||
/**
|
||||
* When an animation frame changes you can choose to automatically update the physics bounds of the parent Sprite
|
||||
* to the width and height of the new frame. If you've set a specific physics bounds that you don't want changed during
|
||||
* animation then set this to false, otherwise leave it set to true.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.autoUpdateBounds = true;
|
||||
/**
|
||||
* Keeps track of the current frame of animation.
|
||||
*/
|
||||
this.currentFrame = null;
|
||||
this._parent = parent;
|
||||
this.game = parent.game;
|
||||
this._anims = {
|
||||
};
|
||||
}
|
||||
AnimationManager.prototype.loadFrameData = /**
|
||||
* Load animation frame data.
|
||||
* @param frameData Data to be loaded.
|
||||
*/
|
||||
function (frameData) {
|
||||
this._frameData = frameData;
|
||||
this.frame = 0;
|
||||
};
|
||||
AnimationManager.prototype.add = /**
|
||||
* Add a new animation.
|
||||
* @param name {string} What this animation should be called (e.g. "run").
|
||||
* @param frames {any[]} An array of numbers/strings indicating what frames to play in what order (e.g. [1, 2, 3] or ['run0', 'run1', run2]).
|
||||
* @param frameRate {number} The speed in frames per second that the animation should play at (e.g. 60 fps).
|
||||
* @param loop {bool} Whether or not the animation is looped or just plays once.
|
||||
* @param useNumericIndex {bool} Use number indexes instead of string indexes?
|
||||
* @return {Animation} The Animation that was created
|
||||
*/
|
||||
function (name, frames, frameRate, loop, useNumericIndex) {
|
||||
if (typeof frames === "undefined") { frames = null; }
|
||||
if (typeof frameRate === "undefined") { frameRate = 60; }
|
||||
if (typeof loop === "undefined") { loop = false; }
|
||||
if (typeof useNumericIndex === "undefined") { useNumericIndex = true; }
|
||||
if(this._frameData == null) {
|
||||
return;
|
||||
}
|
||||
// Create the signals the AnimationManager will emit
|
||||
if(this._parent.events.onAnimationStart == null) {
|
||||
this._parent.events.onAnimationStart = new Phaser.Signal();
|
||||
this._parent.events.onAnimationComplete = new Phaser.Signal();
|
||||
this._parent.events.onAnimationLoop = new Phaser.Signal();
|
||||
}
|
||||
if(frames == null) {
|
||||
frames = this._frameData.getFrameIndexes();
|
||||
} else {
|
||||
if(this.validateFrames(frames, useNumericIndex) == false) {
|
||||
throw Error('Invalid frames given to Animation ' + name);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if(useNumericIndex == false) {
|
||||
frames = this._frameData.getFrameIndexesByName(frames);
|
||||
}
|
||||
this._anims[name] = new Phaser.Animation(this.game, this._parent, this._frameData, name, frames, frameRate, loop);
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
return this._anims[name];
|
||||
};
|
||||
AnimationManager.prototype.validateFrames = /**
|
||||
* Check whether the frames is valid.
|
||||
* @param frames {any[]} Frames to be validated.
|
||||
* @param useNumericIndex {bool} Does these frames use number indexes or string indexes?
|
||||
* @return {bool} True if they're valid, otherwise return false.
|
||||
*/
|
||||
function (frames, useNumericIndex) {
|
||||
for(var i = 0; i < frames.length; i++) {
|
||||
if(useNumericIndex == true) {
|
||||
if(frames[i] > this._frameData.total) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(this._frameData.checkFrameName(frames[i]) == false) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
AnimationManager.prototype.play = /**
|
||||
* Play animation with specific name.
|
||||
* @param name {string} The string name of the animation you want to play.
|
||||
* @param frameRate {number} FrameRate you want to specify instead of using default.
|
||||
* @param loop {bool} Whether or not the animation is looped or just plays once.
|
||||
*/
|
||||
function (name, frameRate, loop) {
|
||||
if (typeof frameRate === "undefined") { frameRate = null; }
|
||||
if (typeof loop === "undefined") { loop = null; }
|
||||
if(this._anims[name]) {
|
||||
if(this.currentAnim == this._anims[name]) {
|
||||
if(this.currentAnim.isPlaying == false) {
|
||||
return this.currentAnim.play(frameRate, loop);
|
||||
}
|
||||
} else {
|
||||
this.currentAnim = this._anims[name];
|
||||
return this.currentAnim.play(frameRate, loop);
|
||||
}
|
||||
}
|
||||
};
|
||||
AnimationManager.prototype.stop = /**
|
||||
* Stop animation by name.
|
||||
* Current animation will be automatically set to the stopped one.
|
||||
*/
|
||||
function (name) {
|
||||
if(this._anims[name]) {
|
||||
this.currentAnim = this._anims[name];
|
||||
this.currentAnim.stop();
|
||||
}
|
||||
};
|
||||
AnimationManager.prototype.update = /**
|
||||
* Update animation and parent sprite's bounds.
|
||||
*/
|
||||
function () {
|
||||
if(this.currentAnim && this.currentAnim.update() == true) {
|
||||
this.currentFrame = this.currentAnim.currentFrame;
|
||||
this._parent.texture.width = this.currentFrame.width;
|
||||
this._parent.texture.height = this.currentFrame.height;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(AnimationManager.prototype, "frameData", {
|
||||
get: function () {
|
||||
return this._frameData;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AnimationManager.prototype, "frameTotal", {
|
||||
get: function () {
|
||||
if(this._frameData) {
|
||||
return this._frameData.total;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AnimationManager.prototype, "frame", {
|
||||
get: function () {
|
||||
return this._frameIndex;
|
||||
},
|
||||
set: /**
|
||||
*
|
||||
* @param value
|
||||
*/
|
||||
function (value) {
|
||||
if(this._frameData && this._frameData.getFrame(value) !== null) {
|
||||
this.currentFrame = this._frameData.getFrame(value);
|
||||
this._parent.texture.width = this.currentFrame.width;
|
||||
this._parent.texture.height = this.currentFrame.height;
|
||||
if(this.autoUpdateBounds && this._parent['body']) {
|
||||
this._parent.body.bounds.width = this.currentFrame.width;
|
||||
this._parent.body.bounds.height = this.currentFrame.height;
|
||||
}
|
||||
this._frameIndex = value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(AnimationManager.prototype, "frameName", {
|
||||
get: function () {
|
||||
return this.currentFrame.name;
|
||||
},
|
||||
set: function (value) {
|
||||
if(this._frameData && this._frameData.getFrameByName(value)) {
|
||||
this.currentFrame = this._frameData.getFrameByName(value);
|
||||
this._parent.texture.width = this.currentFrame.width;
|
||||
this._parent.texture.height = this.currentFrame.height;
|
||||
this._frameIndex = this.currentFrame.index;
|
||||
} else {
|
||||
throw new Error("Cannot set frameName: " + value);
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
AnimationManager.prototype.destroy = /**
|
||||
* Removes all related references
|
||||
*/
|
||||
function () {
|
||||
this._anims = {
|
||||
};
|
||||
this._frameData = null;
|
||||
this._frameIndex = 0;
|
||||
this.currentAnim = null;
|
||||
this.currentFrame = null;
|
||||
};
|
||||
return AnimationManager;
|
||||
})();
|
||||
Components.AnimationManager = AnimationManager;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
79
TS Source/animation/Frame.js
Normal file
79
TS Source/animation/Frame.js
Normal file
|
@ -0,0 +1,79 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Frame
|
||||
*
|
||||
* A Frame is a single frame of an animation and is part of a FrameData collection.
|
||||
*
|
||||
* @package Phaser.Frame
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Frame = (function () {
|
||||
/**
|
||||
* Frame constructor
|
||||
* Create a new <code>Frame</code> with specific position, size and name.
|
||||
*
|
||||
* @param x {number} X position within the image to cut from.
|
||||
* @param y {number} Y position within the image to cut from.
|
||||
* @param width {number} Width of the frame.
|
||||
* @param height {number} Height of the frame.
|
||||
* @param name {string} Name of this frame.
|
||||
*/
|
||||
function Frame(x, y, width, height, name) {
|
||||
/**
|
||||
* Useful for Texture Atlas files. (is set to the filename value)
|
||||
*/
|
||||
this.name = '';
|
||||
/**
|
||||
* Rotated? (not yet implemented)
|
||||
*/
|
||||
this.rotated = false;
|
||||
/**
|
||||
* Either cw or ccw, rotation is always 90 degrees.
|
||||
*/
|
||||
this.rotationDirection = 'cw';
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.name = name;
|
||||
this.rotated = false;
|
||||
this.trimmed = false;
|
||||
}
|
||||
Frame.prototype.setRotation = /**
|
||||
* Set rotation of this frame. (Not yet supported!)
|
||||
*/
|
||||
function (rotated, rotationDirection) {
|
||||
// Not yet supported
|
||||
};
|
||||
Frame.prototype.setTrim = /**
|
||||
* Set trim of the frame.
|
||||
* @param trimmed {bool} Whether this frame trimmed or not.
|
||||
* @param actualWidth {number} Actual width of this frame.
|
||||
* @param actualHeight {number} Actual height of this frame.
|
||||
* @param destX {number} Destination x position.
|
||||
* @param destY {number} Destination y position.
|
||||
* @param destWidth {number} Destination draw width.
|
||||
* @param destHeight {number} Destination draw height.
|
||||
*/
|
||||
function (trimmed, actualWidth, actualHeight, destX, destY, destWidth, destHeight) {
|
||||
//console.log('setTrim', trimmed, 'aw', actualWidth, 'ah', actualHeight, 'dx', destX, 'dy', destY, 'dw', destWidth, 'dh', destHeight);
|
||||
this.trimmed = trimmed;
|
||||
if(trimmed) {
|
||||
this.width = actualWidth;
|
||||
this.height = actualHeight;
|
||||
this.sourceSizeW = actualWidth;
|
||||
this.sourceSizeH = actualHeight;
|
||||
this.spriteSourceSizeX = destX;
|
||||
this.spriteSourceSizeY = destY;
|
||||
this.spriteSourceSizeW = destWidth;
|
||||
this.spriteSourceSizeH = destHeight;
|
||||
}
|
||||
};
|
||||
return Frame;
|
||||
})();
|
||||
Phaser.Frame = Frame;
|
||||
})(Phaser || (Phaser = {}));
|
138
TS Source/animation/FrameData.js
Normal file
138
TS Source/animation/FrameData.js
Normal file
|
@ -0,0 +1,138 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* FrameData
|
||||
*
|
||||
* FrameData is a container for Frame objects, which are the internal representation of animation data in Phaser.
|
||||
*
|
||||
* @package Phaser.FrameData
|
||||
* @author Richard Davey <rich@photonstorm.com>
|
||||
* @copyright 2013 Photon Storm Ltd.
|
||||
* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var FrameData = (function () {
|
||||
/**
|
||||
* FrameData constructor
|
||||
*/
|
||||
function FrameData() {
|
||||
this._frames = [];
|
||||
this._frameNames = [];
|
||||
}
|
||||
Object.defineProperty(FrameData.prototype, "total", {
|
||||
get: function () {
|
||||
return this._frames.length;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
FrameData.prototype.addFrame = /**
|
||||
* Add a new frame.
|
||||
* @param frame {Frame} The frame you want to add.
|
||||
* @return {Frame} The frame you just added.
|
||||
*/
|
||||
function (frame) {
|
||||
frame.index = this._frames.length;
|
||||
this._frames.push(frame);
|
||||
if(frame.name !== '') {
|
||||
this._frameNames[frame.name] = frame.index;
|
||||
}
|
||||
return frame;
|
||||
};
|
||||
FrameData.prototype.getFrame = /**
|
||||
* Get a frame by its index.
|
||||
* @param index {number} Index of the frame you want to get.
|
||||
* @return {Frame} The frame you want.
|
||||
*/
|
||||
function (index) {
|
||||
if(this._frames[index]) {
|
||||
return this._frames[index];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
FrameData.prototype.getFrameByName = /**
|
||||
* Get a frame by its name.
|
||||
* @param name {string} Name of the frame you want to get.
|
||||
* @return {Frame} The frame you want.
|
||||
*/
|
||||
function (name) {
|
||||
if(this._frameNames[name] !== '') {
|
||||
return this._frames[this._frameNames[name]];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
FrameData.prototype.checkFrameName = /**
|
||||
* Check whether there's a frame with given name.
|
||||
* @param name {string} Name of the frame you want to check.
|
||||
* @return {bool} True if frame with given name found, otherwise return false.
|
||||
*/
|
||||
function (name) {
|
||||
if(this._frameNames[name] == null) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
FrameData.prototype.getFrameRange = /**
|
||||
* Get ranges of frames in an array.
|
||||
* @param start {number} Start index of frames you want.
|
||||
* @param end {number} End index of frames you want.
|
||||
* @param [output] {Frame[]} result will be added into this array.
|
||||
* @return {Frame[]} Ranges of specific frames in an array.
|
||||
*/
|
||||
function (start, end, output) {
|
||||
if (typeof output === "undefined") { output = []; }
|
||||
for(var i = start; i <= end; i++) {
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
FrameData.prototype.getFrameIndexes = /**
|
||||
* Get all indexes of frames by giving their name.
|
||||
* @param [output] {number[]} result will be added into this array.
|
||||
* @return {number[]} Indexes of specific frames in an array.
|
||||
*/
|
||||
function (output) {
|
||||
if (typeof output === "undefined") { output = []; }
|
||||
output.length = 0;
|
||||
for(var i = 0; i < this._frames.length; i++) {
|
||||
output.push(i);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
FrameData.prototype.getFrameIndexesByName = /**
|
||||
* Get the frame indexes by giving the frame names.
|
||||
* @param [output] {number[]} result will be added into this array.
|
||||
* @return {number[]} Names of specific frames in an array.
|
||||
*/
|
||||
function (input) {
|
||||
var output = [];
|
||||
for(var i = 0; i < input.length; i++) {
|
||||
if(this.getFrameByName(input[i])) {
|
||||
output.push(this.getFrameByName(input[i]).index);
|
||||
}
|
||||
}
|
||||
return output;
|
||||
};
|
||||
FrameData.prototype.getAllFrames = /**
|
||||
* Get all frames in this frame data.
|
||||
* @return {Frame[]} All the frames in an array.
|
||||
*/
|
||||
function () {
|
||||
return this._frames;
|
||||
};
|
||||
FrameData.prototype.getFrames = /**
|
||||
* Get All frames with specific ranges.
|
||||
* @param range {number[]} Ranges in an array.
|
||||
* @return {Frame[]} All frames in an array.
|
||||
*/
|
||||
function (range) {
|
||||
var output = [];
|
||||
for(var i = 0; i < range.length; i++) {
|
||||
output.push(this._frames[i]);
|
||||
}
|
||||
return output;
|
||||
};
|
||||
return FrameData;
|
||||
})();
|
||||
Phaser.FrameData = FrameData;
|
||||
})(Phaser || (Phaser = {}));
|
370
TS Source/cameras/Camera.js
Normal file
370
TS Source/cameras/Camera.js
Normal file
|
@ -0,0 +1,370 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Camera
|
||||
*
|
||||
* A Camera is your view into the game world. It has a position, size, scale and rotation and renders only those objects
|
||||
* within its field of view. The game automatically creates a single Stage sized camera on boot, but it can be changed and
|
||||
* additional cameras created via the CameraManager.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Camera = (function () {
|
||||
/**
|
||||
* Instantiates a new camera at the specified location, with the specified size and zoom level.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param id {number} Unique identity.
|
||||
* @param x {number} X location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
||||
* @param y {number} Y location of the camera's display in pixels. Uses native, 1:1 resolution, ignores zoom.
|
||||
* @param width {number} The width of the camera display in pixels.
|
||||
* @param height {number} The height of the camera display in pixels.
|
||||
*/
|
||||
function Camera(game, id, x, y, width, height) {
|
||||
this._target = null;
|
||||
/**
|
||||
* Camera worldBounds.
|
||||
* @type {Rectangle}
|
||||
*/
|
||||
this.worldBounds = null;
|
||||
/**
|
||||
* A bool representing if the Camera has been modified in any way via a scale, rotate, flip or skew.
|
||||
*/
|
||||
this.modified = false;
|
||||
/**
|
||||
* Sprite moving inside this Rectangle will not cause camera moving.
|
||||
* @type {Rectangle}
|
||||
*/
|
||||
this.deadzone = null;
|
||||
/**
|
||||
* Whether this camera is visible or not. (default is true)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.visible = true;
|
||||
/**
|
||||
* The z value of this Camera. Cameras are rendered in z-index order by the Renderer.
|
||||
*/
|
||||
this.z = -1;
|
||||
this.game = game;
|
||||
this.ID = id;
|
||||
this.z = id;
|
||||
width = this.game.math.clamp(width, this.game.stage.width, 1);
|
||||
height = this.game.math.clamp(height, this.game.stage.height, 1);
|
||||
// The view into the world we wish to render (by default the full game world size)
|
||||
// The size of this Rect is the same as screenView, but the values are all in world coordinates instead of screen coordinates
|
||||
this.worldView = new Phaser.Rectangle(0, 0, width, height);
|
||||
// The rect of the area being rendered in stage/screen coordinates
|
||||
this.screenView = new Phaser.Rectangle(x, y, width, height);
|
||||
this.plugins = new Phaser.PluginManager(this.game, this);
|
||||
this.transform = new Phaser.Components.TransformManager(this);
|
||||
this.texture = new Phaser.Display.Texture(this);
|
||||
// We create a hidden canvas for our camera the size of the game (we use the screenView to clip the render to the camera size)
|
||||
this._canvas = document.createElement('canvas');
|
||||
this._canvas.width = width;
|
||||
this._canvas.height = height;
|
||||
this._renderLocal = true;
|
||||
this.texture.canvas = this._canvas;
|
||||
this.texture.context = this.texture.canvas.getContext('2d');
|
||||
this.texture.backgroundColor = this.game.stage.backgroundColor;
|
||||
// Handy proxies
|
||||
this.scale = this.transform.scale;
|
||||
this.alpha = this.texture.alpha;
|
||||
this.origin = this.transform.origin;
|
||||
this.crop = this.texture.crop;
|
||||
}
|
||||
Object.defineProperty(Camera.prototype, "alpha", {
|
||||
get: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
*/
|
||||
function () {
|
||||
return this.texture.alpha;
|
||||
},
|
||||
set: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
*/
|
||||
function (value) {
|
||||
this.texture.alpha = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "directToStage", {
|
||||
set: function (value) {
|
||||
if(value) {
|
||||
this._renderLocal = false;
|
||||
this.texture.canvas = this.game.stage.canvas;
|
||||
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.game.stage.backgroundColor);
|
||||
} else {
|
||||
this._renderLocal = true;
|
||||
this.texture.canvas = this._canvas;
|
||||
Phaser.CanvasUtils.setBackgroundColor(this.texture.canvas, this.texture.backgroundColor);
|
||||
}
|
||||
this.texture.context = this.texture.canvas.getContext('2d');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Camera.prototype.hide = /**
|
||||
* Hides an object from this Camera. Hidden objects are not rendered.
|
||||
* The object must implement a public cameraBlacklist property.
|
||||
*
|
||||
* @param object {Sprite/Group} The object this camera should ignore.
|
||||
*/
|
||||
function (object) {
|
||||
object.texture.hideFromCamera(this);
|
||||
};
|
||||
Camera.prototype.isHidden = /**
|
||||
* Returns true if the object is hidden from this Camera.
|
||||
*
|
||||
* @param object {Sprite/Group} The object to check.
|
||||
*/
|
||||
function (object) {
|
||||
return object.texture.isHidden(this);
|
||||
};
|
||||
Camera.prototype.show = /**
|
||||
* Un-hides an object previously hidden to this Camera.
|
||||
* The object must implement a public cameraBlacklist property.
|
||||
*
|
||||
* @param object {Sprite/Group} The object this camera should display.
|
||||
*/
|
||||
function (object) {
|
||||
object.texture.showToCamera(this);
|
||||
};
|
||||
Camera.prototype.follow = /**
|
||||
* Tells this camera object what sprite to track.
|
||||
* @param target {Sprite} The object you want the camera to track. Set to null to not follow anything.
|
||||
* @param [style] {number} Leverage one of the existing "deadzone" presets. If you use a custom deadzone, ignore this parameter and manually specify the deadzone after calling follow().
|
||||
*/
|
||||
function (target, style) {
|
||||
if (typeof style === "undefined") { style = Phaser.Types.CAMERA_FOLLOW_LOCKON; }
|
||||
this._target = target;
|
||||
var helper;
|
||||
switch(style) {
|
||||
case Phaser.Types.CAMERA_FOLLOW_PLATFORMER:
|
||||
var w = this.width / 8;
|
||||
var h = this.height / 3;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - w) / 2, (this.height - h) / 2 - h * 0.25, w, h);
|
||||
break;
|
||||
case Phaser.Types.CAMERA_FOLLOW_TOPDOWN:
|
||||
helper = Math.max(this.width, this.height) / 4;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
||||
break;
|
||||
case Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT:
|
||||
helper = Math.max(this.width, this.height) / 8;
|
||||
this.deadzone = new Phaser.Rectangle((this.width - helper) / 2, (this.height - helper) / 2, helper, helper);
|
||||
break;
|
||||
case Phaser.Types.CAMERA_FOLLOW_LOCKON:
|
||||
default:
|
||||
this.deadzone = null;
|
||||
break;
|
||||
}
|
||||
};
|
||||
Camera.prototype.focusOnXY = /**
|
||||
* Move the camera focus to this location instantly.
|
||||
* @param x {number} X position.
|
||||
* @param y {number} Y position.
|
||||
*/
|
||||
function (x, y) {
|
||||
x += (x > 0) ? 0.0000001 : -0.0000001;
|
||||
y += (y > 0) ? 0.0000001 : -0.0000001;
|
||||
this.worldView.x = Math.round(x - this.worldView.halfWidth);
|
||||
this.worldView.y = Math.round(y - this.worldView.halfHeight);
|
||||
};
|
||||
Camera.prototype.focusOn = /**
|
||||
* Move the camera focus to this location instantly.
|
||||
* @param point {any} Point you want to focus.
|
||||
*/
|
||||
function (point) {
|
||||
point.x += (point.x > 0) ? 0.0000001 : -0.0000001;
|
||||
point.y += (point.y > 0) ? 0.0000001 : -0.0000001;
|
||||
this.worldView.x = Math.round(point.x - this.worldView.halfWidth);
|
||||
this.worldView.y = Math.round(point.y - this.worldView.halfHeight);
|
||||
};
|
||||
Camera.prototype.setBounds = /**
|
||||
* Specify the boundaries of the world or where the camera is allowed to move.
|
||||
*
|
||||
* @param x {number} The smallest X value of your world (usually 0).
|
||||
* @param y {number} The smallest Y value of your world (usually 0).
|
||||
* @param width {number} The largest X value of your world (usually the world width).
|
||||
* @param height {number} The largest Y value of your world (usually the world height).
|
||||
*/
|
||||
function (x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
if(this.worldBounds == null) {
|
||||
this.worldBounds = new Phaser.Rectangle();
|
||||
}
|
||||
this.worldBounds.setTo(x, y, width, height);
|
||||
this.worldView.x = x;
|
||||
this.worldView.y = y;
|
||||
this.update();
|
||||
};
|
||||
Camera.prototype.update = /**
|
||||
* Update focusing and scrolling.
|
||||
*/
|
||||
function () {
|
||||
if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
|
||||
this.modified = true;
|
||||
}
|
||||
this.plugins.preUpdate();
|
||||
if(this._target !== null) {
|
||||
if(this.deadzone == null) {
|
||||
this.focusOnXY(this._target.x, this._target.y);
|
||||
} else {
|
||||
var edge;
|
||||
var targetX = this._target.x + ((this._target.x > 0) ? 0.0000001 : -0.0000001);
|
||||
var targetY = this._target.y + ((this._target.y > 0) ? 0.0000001 : -0.0000001);
|
||||
edge = targetX - this.deadzone.x;
|
||||
if(this.worldView.x > edge) {
|
||||
this.worldView.x = edge;
|
||||
}
|
||||
edge = targetX + this._target.width - this.deadzone.x - this.deadzone.width;
|
||||
if(this.worldView.x < edge) {
|
||||
this.worldView.x = edge;
|
||||
}
|
||||
edge = targetY - this.deadzone.y;
|
||||
if(this.worldView.y > edge) {
|
||||
this.worldView.y = edge;
|
||||
}
|
||||
edge = targetY + this._target.height - this.deadzone.y - this.deadzone.height;
|
||||
if(this.worldView.y < edge) {
|
||||
this.worldView.y = edge;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Make sure we didn't go outside the cameras worldBounds
|
||||
if(this.worldBounds !== null) {
|
||||
if(this.worldView.x < this.worldBounds.left) {
|
||||
this.worldView.x = this.worldBounds.left;
|
||||
}
|
||||
if(this.worldView.x > this.worldBounds.right - this.width) {
|
||||
this.worldView.x = (this.worldBounds.right - this.width) + 1;
|
||||
}
|
||||
if(this.worldView.y < this.worldBounds.top) {
|
||||
this.worldView.y = this.worldBounds.top;
|
||||
}
|
||||
if(this.worldView.y > this.worldBounds.bottom - this.height) {
|
||||
this.worldView.y = (this.worldBounds.bottom - this.height) + 1;
|
||||
}
|
||||
}
|
||||
this.worldView.floor();
|
||||
this.plugins.update();
|
||||
};
|
||||
Camera.prototype.postUpdate = /**
|
||||
* Update focusing and scrolling.
|
||||
*/
|
||||
function () {
|
||||
if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
|
||||
this.modified = false;
|
||||
}
|
||||
// Make sure we didn't go outside the cameras worldBounds
|
||||
if(this.worldBounds !== null) {
|
||||
if(this.worldView.x < this.worldBounds.left) {
|
||||
this.worldView.x = this.worldBounds.left;
|
||||
}
|
||||
if(this.worldView.x > this.worldBounds.right - this.width) {
|
||||
this.worldView.x = this.worldBounds.right - this.width;
|
||||
}
|
||||
if(this.worldView.y < this.worldBounds.top) {
|
||||
this.worldView.y = this.worldBounds.top;
|
||||
}
|
||||
if(this.worldView.y > this.worldBounds.bottom - this.height) {
|
||||
this.worldView.y = this.worldBounds.bottom - this.height;
|
||||
}
|
||||
}
|
||||
this.worldView.floor();
|
||||
this.plugins.postUpdate();
|
||||
};
|
||||
Camera.prototype.destroy = /**
|
||||
* Destroys this camera, associated FX and removes itself from the CameraManager.
|
||||
*/
|
||||
function () {
|
||||
this.game.world.cameras.removeCamera(this.ID);
|
||||
this.plugins.destroy();
|
||||
};
|
||||
Object.defineProperty(Camera.prototype, "x", {
|
||||
get: function () {
|
||||
return this.worldView.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this.worldView.x = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "y", {
|
||||
get: function () {
|
||||
return this.worldView.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this.worldView.y = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "width", {
|
||||
get: function () {
|
||||
return this.screenView.width;
|
||||
},
|
||||
set: function (value) {
|
||||
this.screenView.width = value;
|
||||
this.worldView.width = value;
|
||||
if(value !== this.texture.canvas.width) {
|
||||
this.texture.canvas.width = value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Camera.prototype, "height", {
|
||||
get: function () {
|
||||
return this.screenView.height;
|
||||
},
|
||||
set: function (value) {
|
||||
this.screenView.height = value;
|
||||
this.worldView.height = value;
|
||||
if(value !== this.texture.canvas.height) {
|
||||
this.texture.canvas.height = value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Camera.prototype.setPosition = function (x, y) {
|
||||
this.screenView.x = x;
|
||||
this.screenView.y = y;
|
||||
};
|
||||
Camera.prototype.setSize = function (width, height) {
|
||||
this.screenView.width = width * this.transform.scale.x;
|
||||
this.screenView.height = height * this.transform.scale.y;
|
||||
this.worldView.width = width;
|
||||
this.worldView.height = height;
|
||||
if(width !== this.texture.canvas.width) {
|
||||
this.texture.canvas.width = width;
|
||||
}
|
||||
if(height !== this.texture.canvas.height) {
|
||||
this.texture.canvas.height = height;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Camera.prototype, "rotation", {
|
||||
get: /**
|
||||
* The angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
*/
|
||||
function () {
|
||||
return this.transform.rotation;
|
||||
},
|
||||
set: /**
|
||||
* Set the angle of the Camera in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
* The value is automatically wrapped to be between 0 and 360.
|
||||
*/
|
||||
function (value) {
|
||||
this.transform.rotation = this.game.math.wrap(value, 360, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Camera;
|
||||
})();
|
||||
Phaser.Camera = Camera;
|
||||
})(Phaser || (Phaser = {}));
|
154
TS Source/cameras/CameraManager.js
Normal file
154
TS Source/cameras/CameraManager.js
Normal file
|
@ -0,0 +1,154 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - CameraManager
|
||||
*
|
||||
* Your game only has one CameraManager instance and it's responsible for looking after, creating and destroying
|
||||
* all of the cameras in the world.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var CameraManager = (function () {
|
||||
/**
|
||||
* CameraManager constructor
|
||||
* This will create a new <code>Camera</code> with position and size.
|
||||
*
|
||||
* @param x {number} X Position of the created camera.
|
||||
* @param y {number} y Position of the created camera.
|
||||
* @param width {number} Width of the created camera.
|
||||
* @param height {number} Height of the created camera.
|
||||
*/
|
||||
function CameraManager(game, x, y, width, height) {
|
||||
/**
|
||||
* Helper for sort.
|
||||
*/
|
||||
this._sortIndex = '';
|
||||
this.game = game;
|
||||
this._cameras = [];
|
||||
this._cameraLength = 0;
|
||||
this.defaultCamera = this.addCamera(x, y, width, height);
|
||||
this.defaultCamera.directToStage = true;
|
||||
this.current = this.defaultCamera;
|
||||
}
|
||||
CameraManager.prototype.getAll = /**
|
||||
* Get all the cameras.
|
||||
*
|
||||
* @returns {Camera[]} An array contains all the cameras.
|
||||
*/
|
||||
function () {
|
||||
return this._cameras;
|
||||
};
|
||||
CameraManager.prototype.update = /**
|
||||
* Update cameras.
|
||||
*/
|
||||
function () {
|
||||
for(var i = 0; i < this._cameras.length; i++) {
|
||||
this._cameras[i].update();
|
||||
}
|
||||
};
|
||||
CameraManager.prototype.postUpdate = /**
|
||||
* postUpdate cameras.
|
||||
*/
|
||||
function () {
|
||||
for(var i = 0; i < this._cameras.length; i++) {
|
||||
this._cameras[i].postUpdate();
|
||||
}
|
||||
};
|
||||
CameraManager.prototype.addCamera = /**
|
||||
* Create a new camera with specific position and size.
|
||||
*
|
||||
* @param x {number} X position of the new camera.
|
||||
* @param y {number} Y position of the new camera.
|
||||
* @param width {number} Width of the new camera.
|
||||
* @param height {number} Height of the new camera.
|
||||
* @returns {Camera} The newly created camera object.
|
||||
*/
|
||||
function (x, y, width, height) {
|
||||
var newCam = new Phaser.Camera(this.game, this._cameraLength, x, y, width, height);
|
||||
this._cameraLength = this._cameras.push(newCam);
|
||||
return newCam;
|
||||
};
|
||||
CameraManager.prototype.removeCamera = /**
|
||||
* Remove a new camera with its id.
|
||||
*
|
||||
* @param id {number} ID of the camera you want to remove.
|
||||
* @returns {bool} True if successfully removed the camera, otherwise return false.
|
||||
*/
|
||||
function (id) {
|
||||
for(var c = 0; c < this._cameras.length; c++) {
|
||||
if(this._cameras[c].ID == id) {
|
||||
if(this.current.ID === this._cameras[c].ID) {
|
||||
this.current = null;
|
||||
}
|
||||
this._cameras.splice(c, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
CameraManager.prototype.swap = function (camera1, camera2, sort) {
|
||||
if (typeof sort === "undefined") { sort = true; }
|
||||
if(camera1.ID == camera2.ID) {
|
||||
return false;
|
||||
}
|
||||
var tempZ = camera1.z;
|
||||
camera1.z = camera2.z;
|
||||
camera2.z = tempZ;
|
||||
if(sort) {
|
||||
this.sort();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
CameraManager.prototype.getCameraUnderPoint = function (x, y) {
|
||||
// Work through the cameras in reverse as they are rendered in array order
|
||||
// Return the first camera we find matching the criteria
|
||||
for(var c = this._cameraLength - 1; c >= 0; c--) {
|
||||
if(this._cameras[c].visible && Phaser.RectangleUtils.contains(this._cameras[c].screenView, x, y)) {
|
||||
return this._cameras[c];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
CameraManager.prototype.sort = /**
|
||||
* Call this function to sort the Cameras according to a particular value and order (default is their Z value).
|
||||
* The order in which they are sorted determines the render order. If sorted on z then Cameras with a lower z-index value render first.
|
||||
*
|
||||
* @param {string} index The <code>string</code> name of the Camera variable you want to sort on. Default value is "z".
|
||||
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
|
||||
*/
|
||||
function (index, order) {
|
||||
if (typeof index === "undefined") { index = 'z'; }
|
||||
if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
|
||||
var _this = this;
|
||||
this._sortIndex = index;
|
||||
this._sortOrder = order;
|
||||
this._cameras.sort(function (a, b) {
|
||||
return _this.sortHandler(a, b);
|
||||
});
|
||||
};
|
||||
CameraManager.prototype.sortHandler = /**
|
||||
* Helper function for the sort process.
|
||||
*
|
||||
* @param {Basic} Obj1 The first object being sorted.
|
||||
* @param {Basic} Obj2 The second object being sorted.
|
||||
*
|
||||
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
||||
*/
|
||||
function (obj1, obj2) {
|
||||
if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
|
||||
return this._sortOrder;
|
||||
} else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
|
||||
return -this._sortOrder;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
CameraManager.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this._cameras.length = 0;
|
||||
this.current = this.addCamera(0, 0, this.game.stage.width, this.game.stage.height);
|
||||
};
|
||||
return CameraManager;
|
||||
})();
|
||||
Phaser.CameraManager = CameraManager;
|
||||
})(Phaser || (Phaser = {}));
|
731
TS Source/core/Group.js
Normal file
731
TS Source/core/Group.js
Normal file
|
@ -0,0 +1,731 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Group
|
||||
*
|
||||
* This class is used for organising, updating and sorting game objects.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Group = (function () {
|
||||
function Group(game, maxSize) {
|
||||
if (typeof maxSize === "undefined") { maxSize = 0; }
|
||||
/**
|
||||
* Helper for sort.
|
||||
*/
|
||||
this._sortIndex = '';
|
||||
/**
|
||||
* This keeps track of the z value of any game object added to this Group
|
||||
*/
|
||||
this._zCounter = 0;
|
||||
/**
|
||||
* The unique Group ID
|
||||
*/
|
||||
this.ID = -1;
|
||||
/**
|
||||
* The z value of this Group (within its parent Group, if any)
|
||||
*/
|
||||
this.z = -1;
|
||||
/**
|
||||
* The Group this Group is a child of (if any).
|
||||
*/
|
||||
this.group = null;
|
||||
/**
|
||||
* A bool representing if the Group has been modified in any way via a scale, rotate, flip or skew.
|
||||
*/
|
||||
this.modified = false;
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.GROUP;
|
||||
this.active = true;
|
||||
this.exists = true;
|
||||
this.visible = true;
|
||||
this.members = [];
|
||||
this.length = 0;
|
||||
this._maxSize = maxSize;
|
||||
this._marker = 0;
|
||||
this._sortIndex = null;
|
||||
this.ID = this.game.world.getNextGroupID();
|
||||
this.transform = new Phaser.Components.TransformManager(this);
|
||||
this.texture = new Phaser.Display.Texture(this);
|
||||
this.texture.opaque = false;
|
||||
}
|
||||
Group.prototype.getNextZIndex = /**
|
||||
* Gets the next z index value for children of this Group
|
||||
*/
|
||||
function () {
|
||||
return this._zCounter++;
|
||||
};
|
||||
Group.prototype.destroy = /**
|
||||
* Override this function to handle any deleting or "shutdown" type operations you might need,
|
||||
* such as removing traditional children like Basic objects.
|
||||
*/
|
||||
function () {
|
||||
if(this.members != null) {
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
this._member.destroy();
|
||||
}
|
||||
}
|
||||
this.members.length = 0;
|
||||
}
|
||||
this._sortIndex = null;
|
||||
};
|
||||
Group.prototype.update = /**
|
||||
* Calls update on all members of this Group who have a status of active=true and exists=true
|
||||
* You can also call Object.update directly, which will bypass the active/exists check.
|
||||
*/
|
||||
function () {
|
||||
if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
|
||||
this.modified = true;
|
||||
}
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists && this._member.active) {
|
||||
if(this._member.type != Phaser.Types.GROUP) {
|
||||
this._member.preUpdate();
|
||||
}
|
||||
this._member.update();
|
||||
}
|
||||
}
|
||||
};
|
||||
Group.prototype.postUpdate = /**
|
||||
* Calls update on all members of this Group who have a status of active=true and exists=true
|
||||
* You can also call Object.postUpdate directly, which will bypass the active/exists check.
|
||||
*/
|
||||
function () {
|
||||
if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
|
||||
this.modified = false;
|
||||
}
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists && this._member.active) {
|
||||
this._member.postUpdate();
|
||||
}
|
||||
}
|
||||
};
|
||||
Group.prototype.render = /**
|
||||
* Calls render on all members of this Group who have a status of visible=true and exists=true
|
||||
* You can also call Object.render directly, which will bypass the visible/exists check.
|
||||
*/
|
||||
function (camera) {
|
||||
if(camera.isHidden(this) == true) {
|
||||
return;
|
||||
}
|
||||
this.game.renderer.groupRenderer.preRender(camera, this);
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists && this._member.visible && camera.isHidden(this._member) == false) {
|
||||
if(this._member.type == Phaser.Types.GROUP) {
|
||||
this._member.render(camera);
|
||||
} else {
|
||||
this.game.renderer.renderGameObject(camera, this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.game.renderer.groupRenderer.postRender(camera, this);
|
||||
};
|
||||
Group.prototype.directRender = /**
|
||||
* Calls render on all members of this Group regardless of their visible status and also ignores the camera blacklist.
|
||||
* Use this when the Group objects render to hidden canvases for example.
|
||||
*/
|
||||
function (camera) {
|
||||
this.game.renderer.groupRenderer.preRender(camera, this);
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists) {
|
||||
if(this._member.type == Phaser.Types.GROUP) {
|
||||
this._member.directRender(camera);
|
||||
} else {
|
||||
this.game.renderer.renderGameObject(this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.game.renderer.groupRenderer.postRender(camera, this);
|
||||
};
|
||||
Object.defineProperty(Group.prototype, "maxSize", {
|
||||
get: /**
|
||||
* The maximum capacity of this group. Default is 0, meaning no max capacity, and the group can just grow.
|
||||
*/
|
||||
function () {
|
||||
return this._maxSize;
|
||||
},
|
||||
set: /**
|
||||
* @private
|
||||
*/
|
||||
function (size) {
|
||||
this._maxSize = size;
|
||||
if(this._marker >= this._maxSize) {
|
||||
this._marker = 0;
|
||||
}
|
||||
if(this._maxSize == 0 || this.members == null || (this._maxSize >= this.members.length)) {
|
||||
return;
|
||||
}
|
||||
//If the max size has shrunk, we need to get rid of some objects
|
||||
this._i = this._maxSize;
|
||||
this._length = this.members.length;
|
||||
while(this._i < this._length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
this._member.destroy();
|
||||
}
|
||||
}
|
||||
this.length = this.members.length = this._maxSize;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Group.prototype.add = /**
|
||||
* Adds a new Game Object to the group.
|
||||
* Group will try to replace a null member of the array first.
|
||||
* Failing that, Group will add it to the end of the member array,
|
||||
* assuming there is room for it, and doubling the size of the array if necessary.
|
||||
*
|
||||
* <p>WARNING: If the group has a maxSize that has already been met,
|
||||
* the object will NOT be added to the group!</p>
|
||||
*
|
||||
* @param {Basic} Object The object you want to add to the group.
|
||||
* @return {Basic} The same object that was passed in.
|
||||
*/
|
||||
function (object) {
|
||||
// Is this object already in another Group?
|
||||
// You can't add a Group to itself or an object to the same Group twice
|
||||
if(object.group && (object.group.ID == this.ID || (object.type == Phaser.Types.GROUP && object.ID == this.ID))) {
|
||||
return object;
|
||||
}
|
||||
// First, look for a null entry where we can add the object.
|
||||
this._i = 0;
|
||||
this._length = this.members.length;
|
||||
while(this._i < this._length) {
|
||||
if(this.members[this._i] == null) {
|
||||
this.members[this._i] = object;
|
||||
this.setObjectIDs(object);
|
||||
if(this._i >= this.length) {
|
||||
this.length = this._i + 1;
|
||||
}
|
||||
return object;
|
||||
}
|
||||
this._i++;
|
||||
}
|
||||
// Failing that, expand the array (if we can) and add the object.
|
||||
if(this._maxSize > 0) {
|
||||
if(this.members.length >= this._maxSize) {
|
||||
return object;
|
||||
} else if(this.members.length * 2 <= this._maxSize) {
|
||||
this.members.length *= 2;
|
||||
} else {
|
||||
this.members.length = this._maxSize;
|
||||
}
|
||||
} else {
|
||||
this.members.length *= 2;
|
||||
}
|
||||
// If we made it this far, then we successfully grew the group,
|
||||
// and we can go ahead and add the object at the first open slot.
|
||||
this.members[this._i] = object;
|
||||
this.length = this._i + 1;
|
||||
this.setObjectIDs(object);
|
||||
return object;
|
||||
};
|
||||
Group.prototype.addNewSprite = /**
|
||||
* Create a new Sprite within this Group at the specified position.
|
||||
*
|
||||
* @param x {number} X position of the new sprite.
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
function (x, y, key, frame) {
|
||||
if (typeof key === "undefined") { key = ''; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
return this.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
};
|
||||
Group.prototype.setObjectIDs = /**
|
||||
* Sets all of the game object properties needed to exist within this Group.
|
||||
*/
|
||||
function (object, zIndex) {
|
||||
if (typeof zIndex === "undefined") { zIndex = -1; }
|
||||
// If the object is already in another Group, inform that Group it has left
|
||||
if(object.group !== null) {
|
||||
object.group.remove(object);
|
||||
}
|
||||
object.group = this;
|
||||
if(zIndex == -1) {
|
||||
zIndex = this.getNextZIndex();
|
||||
}
|
||||
object.z = zIndex;
|
||||
if(object['events']) {
|
||||
object['events'].onAddedToGroup.dispatch(object, this, object.z);
|
||||
}
|
||||
};
|
||||
Group.prototype.recycle = /**
|
||||
* Recycling is designed to help you reuse game objects without always re-allocating or "newing" them.
|
||||
*
|
||||
* <p>If you specified a maximum size for this group (like in Emitter),
|
||||
* then recycle will employ what we're calling "rotating" recycling.
|
||||
* Recycle() will first check to see if the group is at capacity yet.
|
||||
* If group is not yet at capacity, recycle() returns a new object.
|
||||
* If the group IS at capacity, then recycle() just returns the next object in line.</p>
|
||||
*
|
||||
* <p>If you did NOT specify a maximum size for this group,
|
||||
* then recycle() will employ what we're calling "grow-style" recycling.
|
||||
* Recycle() will return either the first object with exists == false,
|
||||
* or, finding none, add a new object to the array,
|
||||
* doubling the size of the array if necessary.</p>
|
||||
*
|
||||
* <p>WARNING: If this function needs to create a new object,
|
||||
* and no object class was provided, it will return null
|
||||
* instead of a valid object!</p>
|
||||
*
|
||||
* @param {class} ObjectClass The class type you want to recycle (e.g. Basic, EvilRobot, etc). Do NOT "new" the class in the parameter!
|
||||
*
|
||||
* @return {any} A reference to the object that was created. Don't forget to cast it back to the Class you want (e.g. myObject = myGroup.recycle(myObjectClass) as myObjectClass;).
|
||||
*/
|
||||
function (objectClass) {
|
||||
if (typeof objectClass === "undefined") { objectClass = null; }
|
||||
if(this._maxSize > 0) {
|
||||
if(this.length < this._maxSize) {
|
||||
if(objectClass == null) {
|
||||
return null;
|
||||
}
|
||||
return this.add(new objectClass(this.game));
|
||||
} else {
|
||||
this._member = this.members[this._marker++];
|
||||
if(this._marker >= this._maxSize) {
|
||||
this._marker = 0;
|
||||
}
|
||||
return this._member;
|
||||
}
|
||||
} else {
|
||||
this._member = this.getFirstAvailable(objectClass);
|
||||
if(this._member != null) {
|
||||
return this._member;
|
||||
}
|
||||
if(objectClass == null) {
|
||||
return null;
|
||||
}
|
||||
return this.add(new objectClass(this.game));
|
||||
}
|
||||
};
|
||||
Group.prototype.remove = /**
|
||||
* Removes an object from the group.
|
||||
*
|
||||
* @param {Basic} object The Game Object you want to remove.
|
||||
* @param {bool} splice Whether the object should be cut from the array entirely or not.
|
||||
*
|
||||
* @return {Basic} The removed object.
|
||||
*/
|
||||
function (object, splice) {
|
||||
if (typeof splice === "undefined") { splice = false; }
|
||||
//console.log('removing from group: ', object.name);
|
||||
this._i = this.members.indexOf(object);
|
||||
if(this._i < 0 || (this._i >= this.members.length)) {
|
||||
return null;
|
||||
}
|
||||
if(splice) {
|
||||
this.members.splice(this._i, 1);
|
||||
this.length--;
|
||||
} else {
|
||||
this.members[this._i] = null;
|
||||
}
|
||||
//console.log('nulled');
|
||||
if(object['events']) {
|
||||
object['events'].onRemovedFromGroup.dispatch(object, this);
|
||||
}
|
||||
object.group = null;
|
||||
object.z = -1;
|
||||
return object;
|
||||
};
|
||||
Group.prototype.replace = /**
|
||||
* Replaces an existing game object in this Group with a new one.
|
||||
*
|
||||
* @param {Basic} oldObject The object you want to replace.
|
||||
* @param {Basic} newObject The new object you want to use instead.
|
||||
*
|
||||
* @return {Basic} The new object.
|
||||
*/
|
||||
function (oldObject, newObject) {
|
||||
this._i = this.members.indexOf(oldObject);
|
||||
if(this._i < 0 || (this._i >= this.members.length)) {
|
||||
return null;
|
||||
}
|
||||
this.setObjectIDs(newObject, this.members[this._i].z);
|
||||
// Null the old object
|
||||
this.remove(this.members[this._i]);
|
||||
this.members[this._i] = newObject;
|
||||
return newObject;
|
||||
};
|
||||
Group.prototype.swap = /**
|
||||
* Swaps two existing game object in this Group with each other.
|
||||
*
|
||||
* @param {Basic} child1 The first object to swap.
|
||||
* @param {Basic} child2 The second object to swap.
|
||||
*
|
||||
* @return {Basic} True if the two objects successfully swapped position.
|
||||
*/
|
||||
function (child1, child2, sort) {
|
||||
if (typeof sort === "undefined") { sort = true; }
|
||||
if(child1.group.ID != this.ID || child2.group.ID != this.ID || child1 === child2) {
|
||||
return false;
|
||||
}
|
||||
var tempZ = child1.z;
|
||||
child1.z = child2.z;
|
||||
child2.z = tempZ;
|
||||
if(sort) {
|
||||
this.sort();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
Group.prototype.bringToTop = function (child) {
|
||||
//console.log('bringToTop', child.name,'current z', child.z);
|
||||
var oldZ = child.z;
|
||||
// If child not in this group, or is already at the top of the group, return false
|
||||
//if (!child || child.group == null || child.group.ID != this.ID || child.z == this._zCounter)
|
||||
if(!child || child.group == null || child.group.ID != this.ID) {
|
||||
//console.log('If child not in this group, or is already at the top of the group, return false');
|
||||
return false;
|
||||
}
|
||||
// Find out the largest z index
|
||||
var topZ = -1;
|
||||
for(var i = 0; i < this.length; i++) {
|
||||
if(this.members[i] && this.members[i].z > topZ) {
|
||||
topZ = this.members[i].z;
|
||||
}
|
||||
}
|
||||
// Child is already at the top
|
||||
if(child.z == topZ) {
|
||||
return false;
|
||||
}
|
||||
child.z = topZ + 1;
|
||||
// Sort them out based on the current z indexes
|
||||
this.sort();
|
||||
// Now tidy-up the z indexes, removing gaps, etc
|
||||
for(var i = 0; i < this.length; i++) {
|
||||
if(this.members[i]) {
|
||||
this.members[i].z = i;
|
||||
}
|
||||
}
|
||||
//console.log('bringToTop', child.name, 'old z', oldZ, 'new z', child.z);
|
||||
return true;
|
||||
// What's the z index of the top most child?
|
||||
/*
|
||||
var childIndex: number = this._zCounter;
|
||||
|
||||
console.log('childIndex', childIndex);
|
||||
|
||||
this._i = 0;
|
||||
|
||||
while (this._i < this.length)
|
||||
{
|
||||
this._member = this.members[this._i++];
|
||||
|
||||
if (this._member)
|
||||
{
|
||||
if (this._i > childIndex)
|
||||
{
|
||||
this._member.z--;
|
||||
}
|
||||
else if (this._member.z == child.z)
|
||||
{
|
||||
childIndex = this._i;
|
||||
this._member.z = this._zCounter;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
console.log('child inserted at index', child.z);
|
||||
|
||||
// Maybe redundant?
|
||||
this.sort();
|
||||
|
||||
return true;
|
||||
*/
|
||||
};
|
||||
Group.prototype.sort = /**
|
||||
* Call this function to sort the group according to a particular value and order.
|
||||
* For example, to sort game objects for Zelda-style overlaps you might call
|
||||
* <code>myGroup.sort("y",Group.ASCENDING)</code> at the bottom of your
|
||||
* <code>State.update()</code> override. To sort all existing objects after
|
||||
* a big explosion or bomb attack, you might call <code>myGroup.sort("exists",Group.DESCENDING)</code>.
|
||||
*
|
||||
* @param {string} index The <code>string</code> name of the member variable you want to sort on. Default value is "z".
|
||||
* @param {number} order A <code>Group</code> constant that defines the sort order. Possible values are <code>Group.ASCENDING</code> and <code>Group.DESCENDING</code>. Default value is <code>Group.ASCENDING</code>.
|
||||
*/
|
||||
function (index, order) {
|
||||
if (typeof index === "undefined") { index = 'z'; }
|
||||
if (typeof order === "undefined") { order = Phaser.Types.SORT_ASCENDING; }
|
||||
var _this = this;
|
||||
this._sortIndex = index;
|
||||
this._sortOrder = order;
|
||||
this.members.sort(function (a, b) {
|
||||
return _this.sortHandler(a, b);
|
||||
});
|
||||
};
|
||||
Group.prototype.sortHandler = /**
|
||||
* Helper function for the sort process.
|
||||
*
|
||||
* @param {Basic} Obj1 The first object being sorted.
|
||||
* @param {Basic} Obj2 The second object being sorted.
|
||||
*
|
||||
* @return {number} An integer value: -1 (Obj1 before Obj2), 0 (same), or 1 (Obj1 after Obj2).
|
||||
*/
|
||||
function (obj1, obj2) {
|
||||
if(!obj1 || !obj2) {
|
||||
//console.log('null objects in sort', obj1, obj2);
|
||||
return 0;
|
||||
}
|
||||
if(obj1[this._sortIndex] < obj2[this._sortIndex]) {
|
||||
return this._sortOrder;
|
||||
} else if(obj1[this._sortIndex] > obj2[this._sortIndex]) {
|
||||
return -this._sortOrder;
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
Group.prototype.setAll = /**
|
||||
* Go through and set the specified variable to the specified value on all members of the group.
|
||||
*
|
||||
* @param {string} VariableName The string representation of the variable name you want to modify, for example "visible" or "scrollFactor".
|
||||
* @param {Object} Value The value you want to assign to that variable.
|
||||
* @param {bool} Recurse Default value is true, meaning if <code>setAll()</code> encounters a member that is a group, it will call <code>setAll()</code> on that group rather than modifying its variable.
|
||||
*/
|
||||
function (variableName, value, recurse) {
|
||||
if (typeof recurse === "undefined") { recurse = true; }
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
if(recurse && this._member.type == Phaser.Types.GROUP) {
|
||||
this._member.setAll(variableName, value, recurse);
|
||||
} else {
|
||||
this._member[variableName] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Group.prototype.callAll = /**
|
||||
* Go through and call the specified function on all members of the group.
|
||||
* Currently only works on functions that have no required parameters.
|
||||
*
|
||||
* @param {string} FunctionName The string representation of the function you want to call on each object, for example "kill()" or "init()".
|
||||
* @param {bool} Recurse Default value is true, meaning if <code>callAll()</code> encounters a member that is a group, it will call <code>callAll()</code> on that group rather than calling the group's function.
|
||||
*/
|
||||
function (functionName, recurse) {
|
||||
if (typeof recurse === "undefined") { recurse = true; }
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
if(recurse && this._member.type == Phaser.Types.GROUP) {
|
||||
this._member.callAll(functionName, recurse);
|
||||
} else {
|
||||
this._member[functionName]();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Group.prototype.forEach = /**
|
||||
* @param {function} callback
|
||||
* @param {bool} recursive
|
||||
*/
|
||||
function (callback, recursive) {
|
||||
if (typeof recursive === "undefined") { recursive = false; }
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
if(recursive && this._member.type == Phaser.Types.GROUP) {
|
||||
this._member.forEach(callback, true);
|
||||
} else {
|
||||
callback.call(this, this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Group.prototype.forEachAlive = /**
|
||||
* @param {any} context
|
||||
* @param {function} callback
|
||||
* @param {bool} recursive
|
||||
*/
|
||||
function (context, callback, recursive) {
|
||||
if (typeof recursive === "undefined") { recursive = false; }
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.alive) {
|
||||
if(recursive && this._member.type == Phaser.Types.GROUP) {
|
||||
this._member.forEachAlive(context, callback, true);
|
||||
} else {
|
||||
callback.call(context, this._member);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Group.prototype.getFirstAvailable = /**
|
||||
* Call this function to retrieve the first object with exists == false in the group.
|
||||
* This is handy for recycling in general, e.g. respawning enemies.
|
||||
*
|
||||
* @param {any} [ObjectClass] An optional parameter that lets you narrow the results to instances of this particular class.
|
||||
*
|
||||
* @return {any} A <code>Basic</code> currently flagged as not existing.
|
||||
*/
|
||||
function (objectClass) {
|
||||
if (typeof objectClass === "undefined") { objectClass = null; }
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if((this._member != null) && !this._member.exists && ((objectClass == null) || (typeof this._member === objectClass))) {
|
||||
return this._member;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Group.prototype.getFirstNull = /**
|
||||
* Call this function to retrieve the first index set to 'null'.
|
||||
* Returns -1 if no index stores a null object.
|
||||
*
|
||||
* @return {number} An <code>int</code> indicating the first null slot in the group.
|
||||
*/
|
||||
function () {
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
if(this.members[this._i] == null) {
|
||||
return this._i;
|
||||
} else {
|
||||
this._i++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
Group.prototype.getFirstExtant = /**
|
||||
* Call this function to retrieve the first object with exists == true in the group.
|
||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
||||
*
|
||||
* @return {Basic} A <code>Basic</code> currently flagged as existing.
|
||||
*/
|
||||
function () {
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null && this._member.exists) {
|
||||
return this._member;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Group.prototype.getFirstAlive = /**
|
||||
* Call this function to retrieve the first object with dead == false in the group.
|
||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
||||
*
|
||||
* @return {Basic} A <code>Basic</code> currently flagged as not dead.
|
||||
*/
|
||||
function () {
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if((this._member != null) && this._member.exists && this._member.alive) {
|
||||
return this._member;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Group.prototype.getFirstDead = /**
|
||||
* Call this function to retrieve the first object with dead == true in the group.
|
||||
* This is handy for checking if everything's wiped out, or choosing a squad leader, etc.
|
||||
*
|
||||
* @return {Basic} A <code>Basic</code> currently flagged as dead.
|
||||
*/
|
||||
function () {
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if((this._member != null) && !this._member.alive) {
|
||||
return this._member;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Group.prototype.countLiving = /**
|
||||
* Call this function to find out how many members of the group are not dead.
|
||||
*
|
||||
* @return {number} The number of <code>Basic</code>s flagged as not dead. Returns -1 if group is empty.
|
||||
*/
|
||||
function () {
|
||||
this._count = -1;
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
if(this._count < 0) {
|
||||
this._count = 0;
|
||||
}
|
||||
if(this._member.exists && this._member.alive) {
|
||||
this._count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._count;
|
||||
};
|
||||
Group.prototype.countDead = /**
|
||||
* Call this function to find out how many members of the group are dead.
|
||||
*
|
||||
* @return {number} The number of <code>Basic</code>s flagged as dead. Returns -1 if group is empty.
|
||||
*/
|
||||
function () {
|
||||
this._count = -1;
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if(this._member != null) {
|
||||
if(this._count < 0) {
|
||||
this._count = 0;
|
||||
}
|
||||
if(!this._member.alive) {
|
||||
this._count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return this._count;
|
||||
};
|
||||
Group.prototype.getRandom = /**
|
||||
* Returns a member at random from the group.
|
||||
*
|
||||
* @param {number} StartIndex Optional offset off the front of the array. Default value is 0, or the beginning of the array.
|
||||
* @param {number} Length Optional restriction on the number of values you want to randomly select from.
|
||||
*
|
||||
* @return {Basic} A <code>Basic</code> from the members list.
|
||||
*/
|
||||
function (startIndex, length) {
|
||||
if (typeof startIndex === "undefined") { startIndex = 0; }
|
||||
if (typeof length === "undefined") { length = 0; }
|
||||
if(length == 0) {
|
||||
length = this.length;
|
||||
}
|
||||
return this.game.math.getRandom(this.members, startIndex, length);
|
||||
};
|
||||
Group.prototype.clear = /**
|
||||
* Remove all instances of <code>Basic</code> subclass (Basic, Block, etc) from the list.
|
||||
* WARNING: does not destroy() or kill() any of these objects!
|
||||
*/
|
||||
function () {
|
||||
this.length = this.members.length = 0;
|
||||
};
|
||||
Group.prototype.kill = /**
|
||||
* Calls kill on the group's members and then on the group itself.
|
||||
*/
|
||||
function () {
|
||||
this._i = 0;
|
||||
while(this._i < this.length) {
|
||||
this._member = this.members[this._i++];
|
||||
if((this._member != null) && this._member.exists) {
|
||||
this._member.kill();
|
||||
}
|
||||
}
|
||||
};
|
||||
return Group;
|
||||
})();
|
||||
Phaser.Group = Group;
|
||||
})(Phaser || (Phaser = {}));
|
68
TS Source/core/Plugin.js
Normal file
68
TS Source/core/Plugin.js
Normal file
|
@ -0,0 +1,68 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Plugin
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Plugin = (function () {
|
||||
function Plugin(game, parent) {
|
||||
this.game = game;
|
||||
this.parent = parent;
|
||||
this.active = false;
|
||||
this.visible = false;
|
||||
this.hasPreUpdate = false;
|
||||
this.hasUpdate = false;
|
||||
this.hasPostUpdate = false;
|
||||
this.hasPreRender = false;
|
||||
this.hasRender = false;
|
||||
this.hasPostRender = false;
|
||||
}
|
||||
Plugin.prototype.preUpdate = /**
|
||||
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Plugin.prototype.update = /**
|
||||
* Pre-update is called at the start of the update cycle, before any other updates have taken place.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Plugin.prototype.postUpdate = /**
|
||||
* Post-update is called at the end of the objects update cycle, after other update logic has taken place.
|
||||
* It is only called if active is set to true.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Plugin.prototype.preRender = /**
|
||||
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Plugin.prototype.render = /**
|
||||
* Pre-render is called right before the Game Renderer starts and before any custom preRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Plugin.prototype.postRender = /**
|
||||
* Post-render is called after every camera and game object has been rendered, also after any custom postRender callbacks have been run.
|
||||
* It is only called if visible is set to true.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Plugin.prototype.destroy = /**
|
||||
* Clear down this Plugin and null out references
|
||||
*/
|
||||
function () {
|
||||
this.game = null;
|
||||
this.parent = null;
|
||||
this.active = false;
|
||||
this.visible = false;
|
||||
};
|
||||
return Plugin;
|
||||
})();
|
||||
Phaser.Plugin = Plugin;
|
||||
})(Phaser || (Phaser = {}));
|
121
TS Source/core/PluginManager.js
Normal file
121
TS Source/core/PluginManager.js
Normal file
|
@ -0,0 +1,121 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - PluginManager
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var PluginManager = (function () {
|
||||
function PluginManager(game, parent) {
|
||||
this.game = game;
|
||||
this._parent = parent;
|
||||
this.plugins = [];
|
||||
}
|
||||
PluginManager.prototype.add = /**
|
||||
* Add a new Plugin to the PluginManager.
|
||||
* The plugins game and parent reference are set to this game and pluginmanager parent.
|
||||
* @type {Phaser.Plugin}
|
||||
*/
|
||||
function (plugin) {
|
||||
var result = false;
|
||||
// Prototype?
|
||||
if(typeof plugin === 'function') {
|
||||
plugin = new plugin(this.game, this._parent);
|
||||
} else {
|
||||
plugin.game = this.game;
|
||||
plugin.parent = this._parent;
|
||||
}
|
||||
// Check for methods now to avoid having to do this every loop
|
||||
if(typeof plugin['preUpdate'] === 'function') {
|
||||
plugin.hasPreUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
if(typeof plugin['update'] === 'function') {
|
||||
plugin.hasUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
if(typeof plugin['postUpdate'] === 'function') {
|
||||
plugin.hasPostUpdate = true;
|
||||
result = true;
|
||||
}
|
||||
if(typeof plugin['preRender'] === 'function') {
|
||||
plugin.hasPreRender = true;
|
||||
result = true;
|
||||
}
|
||||
if(typeof plugin['render'] === 'function') {
|
||||
plugin.hasRender = true;
|
||||
result = true;
|
||||
}
|
||||
if(typeof plugin['postRender'] === 'function') {
|
||||
plugin.hasPostRender = true;
|
||||
result = true;
|
||||
}
|
||||
// The plugin must have at least one of the above functions to be added to the PluginManager.
|
||||
if(result == true) {
|
||||
if(plugin.hasPreUpdate || plugin.hasUpdate || plugin.hasPostUpdate) {
|
||||
plugin.active = true;
|
||||
}
|
||||
if(plugin.hasPreRender || plugin.hasRender || plugin.hasPostRender) {
|
||||
plugin.visible = true;
|
||||
}
|
||||
this._pluginsLength = this.plugins.push(plugin);
|
||||
return plugin;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.remove = function (plugin) {
|
||||
// TODO :)
|
||||
this._pluginsLength--;
|
||||
};
|
||||
PluginManager.prototype.preUpdate = function () {
|
||||
for(this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if(this.plugins[this._p].active && this.plugins[this._p].hasPreUpdate) {
|
||||
this.plugins[this._p].preUpdate();
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.update = function () {
|
||||
for(this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if(this.plugins[this._p].active && this.plugins[this._p].hasUpdate) {
|
||||
this.plugins[this._p].update();
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.postUpdate = function () {
|
||||
for(this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if(this.plugins[this._p].active && this.plugins[this._p].hasPostUpdate) {
|
||||
this.plugins[this._p].postUpdate();
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.preRender = function () {
|
||||
for(this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if(this.plugins[this._p].visible && this.plugins[this._p].hasPreRender) {
|
||||
this.plugins[this._p].preRender();
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.render = function () {
|
||||
for(this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if(this.plugins[this._p].visible && this.plugins[this._p].hasRender) {
|
||||
this.plugins[this._p].render();
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.postRender = function () {
|
||||
for(this._p = 0; this._p < this._pluginsLength; this._p++) {
|
||||
if(this.plugins[this._p].visible && this.plugins[this._p].hasPostRender) {
|
||||
this.plugins[this._p].postRender();
|
||||
}
|
||||
}
|
||||
};
|
||||
PluginManager.prototype.destroy = function () {
|
||||
this.plugins.length = 0;
|
||||
this._pluginsLength = 0;
|
||||
this.game = null;
|
||||
this._parent = null;
|
||||
};
|
||||
return PluginManager;
|
||||
})();
|
||||
Phaser.PluginManager = PluginManager;
|
||||
})(Phaser || (Phaser = {}));
|
250
TS Source/core/Signal.js
Normal file
250
TS Source/core/Signal.js
Normal file
|
@ -0,0 +1,250 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Signal
|
||||
*
|
||||
* A Signal is used for object communication via a custom broadcaster instead of Events.
|
||||
* Based on JS Signals by Miller Medeiros. Converted by TypeScript by Richard Davey.
|
||||
* Released under the MIT license
|
||||
* http://millermedeiros.github.com/js-signals/
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Signal = (function () {
|
||||
function Signal() {
|
||||
/**
|
||||
*
|
||||
* @property _bindings
|
||||
* @type Array
|
||||
* @private
|
||||
*/
|
||||
this._bindings = [];
|
||||
/**
|
||||
*
|
||||
* @property _prevParams
|
||||
* @type Any
|
||||
* @private
|
||||
*/
|
||||
this._prevParams = null;
|
||||
/**
|
||||
* If Signal should keep record of previously dispatched parameters and
|
||||
* automatically execute listener during `add()`/`addOnce()` if Signal was
|
||||
* already dispatched before.
|
||||
* @type bool
|
||||
*/
|
||||
this.memorize = false;
|
||||
/**
|
||||
* @type bool
|
||||
* @private
|
||||
*/
|
||||
this._shouldPropagate = true;
|
||||
/**
|
||||
* If Signal is active and should broadcast events.
|
||||
* <p><strong>IMPORTANT:</strong> Setting this property during a dispatch will only affect the next dispatch, if you want to stop the propagation of a signal use `halt()` instead.</p>
|
||||
* @type bool
|
||||
*/
|
||||
this.active = true;
|
||||
}
|
||||
Signal.VERSION = '1.0.0';
|
||||
Signal.prototype.validateListener = /**
|
||||
*
|
||||
* @method validateListener
|
||||
* @param {Any} listener
|
||||
* @param {Any} fnName
|
||||
*/
|
||||
function (listener, fnName) {
|
||||
if(typeof listener !== 'function') {
|
||||
throw new Error('listener is a required param of {fn}() and should be a Function.'.replace('{fn}', fnName));
|
||||
}
|
||||
};
|
||||
Signal.prototype._registerListener = /**
|
||||
* @param {Function} listener
|
||||
* @param {bool} isOnce
|
||||
* @param {Object} [listenerContext]
|
||||
* @param {Number} [priority]
|
||||
* @return {SignalBinding}
|
||||
* @private
|
||||
*/
|
||||
function (listener, isOnce, listenerContext, priority) {
|
||||
var prevIndex = this._indexOfListener(listener, listenerContext);
|
||||
var binding;
|
||||
if(prevIndex !== -1) {
|
||||
binding = this._bindings[prevIndex];
|
||||
if(binding.isOnce() !== isOnce) {
|
||||
throw new Error('You cannot add' + (isOnce ? '' : 'Once') + '() then add' + (!isOnce ? '' : 'Once') + '() the same listener without removing the relationship first.');
|
||||
}
|
||||
} else {
|
||||
binding = new Phaser.SignalBinding(this, listener, isOnce, listenerContext, priority);
|
||||
this._addBinding(binding);
|
||||
}
|
||||
if(this.memorize && this._prevParams) {
|
||||
binding.execute(this._prevParams);
|
||||
}
|
||||
return binding;
|
||||
};
|
||||
Signal.prototype._addBinding = /**
|
||||
*
|
||||
* @method _addBinding
|
||||
* @param {SignalBinding} binding
|
||||
* @private
|
||||
*/
|
||||
function (binding) {
|
||||
//simplified insertion sort
|
||||
var n = this._bindings.length;
|
||||
do {
|
||||
--n;
|
||||
}while(this._bindings[n] && binding.priority <= this._bindings[n].priority);
|
||||
this._bindings.splice(n + 1, 0, binding);
|
||||
};
|
||||
Signal.prototype._indexOfListener = /**
|
||||
*
|
||||
* @method _indexOfListener
|
||||
* @param {Function} listener
|
||||
* @return {number}
|
||||
* @private
|
||||
*/
|
||||
function (listener, context) {
|
||||
var n = this._bindings.length;
|
||||
var cur;
|
||||
while(n--) {
|
||||
cur = this._bindings[n];
|
||||
if(cur.getListener() === listener && cur.context === context) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
Signal.prototype.has = /**
|
||||
* Check if listener was attached to Signal.
|
||||
* @param {Function} listener
|
||||
* @param {Object} [context]
|
||||
* @return {bool} if Signal has the specified listener.
|
||||
*/
|
||||
function (listener, context) {
|
||||
if (typeof context === "undefined") { context = null; }
|
||||
return this._indexOfListener(listener, context) !== -1;
|
||||
};
|
||||
Signal.prototype.add = /**
|
||||
* Add a listener to the signal.
|
||||
* @param {Function} listener Signal handler function.
|
||||
* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
|
||||
* @return {SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
function (listener, listenerContext, priority) {
|
||||
if (typeof listenerContext === "undefined") { listenerContext = null; }
|
||||
if (typeof priority === "undefined") { priority = 0; }
|
||||
this.validateListener(listener, 'add');
|
||||
return this._registerListener(listener, false, listenerContext, priority);
|
||||
};
|
||||
Signal.prototype.addOnce = /**
|
||||
* Add listener to the signal that should be removed after first execution (will be executed only once).
|
||||
* @param {Function} listener Signal handler function.
|
||||
* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {Number} [priority] The priority level of the event listener. Listeners with higher priority will be executed before listeners with lower priority. Listeners with same priority level will be executed at the same order as they were added. (default = 0)
|
||||
* @return {SignalBinding} An Object representing the binding between the Signal and listener.
|
||||
*/
|
||||
function (listener, listenerContext, priority) {
|
||||
if (typeof listenerContext === "undefined") { listenerContext = null; }
|
||||
if (typeof priority === "undefined") { priority = 0; }
|
||||
this.validateListener(listener, 'addOnce');
|
||||
return this._registerListener(listener, true, listenerContext, priority);
|
||||
};
|
||||
Signal.prototype.remove = /**
|
||||
* Remove a single listener from the dispatch queue.
|
||||
* @param {Function} listener Handler function that should be removed.
|
||||
* @param {Object} [context] Execution context (since you can add the same handler multiple times if executing in a different context).
|
||||
* @return {Function} Listener handler function.
|
||||
*/
|
||||
function (listener, context) {
|
||||
if (typeof context === "undefined") { context = null; }
|
||||
this.validateListener(listener, 'remove');
|
||||
var i = this._indexOfListener(listener, context);
|
||||
if(i !== -1) {
|
||||
this._bindings[i]._destroy();
|
||||
this._bindings.splice(i, 1);
|
||||
}
|
||||
return listener;
|
||||
};
|
||||
Signal.prototype.removeAll = /**
|
||||
* Remove all listeners from the Signal.
|
||||
*/
|
||||
function () {
|
||||
if(this._bindings) {
|
||||
var n = this._bindings.length;
|
||||
while(n--) {
|
||||
this._bindings[n]._destroy();
|
||||
}
|
||||
this._bindings.length = 0;
|
||||
}
|
||||
};
|
||||
Signal.prototype.getNumListeners = /**
|
||||
* @return {number} Number of listeners attached to the Signal.
|
||||
*/
|
||||
function () {
|
||||
return this._bindings.length;
|
||||
};
|
||||
Signal.prototype.halt = /**
|
||||
* Stop propagation of the event, blocking the dispatch to next listeners on the queue.
|
||||
* <p><strong>IMPORTANT:</strong> should be called only during signal dispatch, calling it before/after dispatch won't affect signal broadcast.</p>
|
||||
* @see Signal.prototype.disable
|
||||
*/
|
||||
function () {
|
||||
this._shouldPropagate = false;
|
||||
};
|
||||
Signal.prototype.dispatch = /**
|
||||
* Dispatch/Broadcast Signal to all listeners added to the queue.
|
||||
* @param {...*} [params] Parameters that should be passed to each handler.
|
||||
*/
|
||||
function () {
|
||||
var paramsArr = [];
|
||||
for (var _i = 0; _i < (arguments.length - 0); _i++) {
|
||||
paramsArr[_i] = arguments[_i + 0];
|
||||
}
|
||||
if(!this.active) {
|
||||
return;
|
||||
}
|
||||
var n = this._bindings.length;
|
||||
var bindings;
|
||||
if(this.memorize) {
|
||||
this._prevParams = paramsArr;
|
||||
}
|
||||
if(!n) {
|
||||
//should come after memorize
|
||||
return;
|
||||
}
|
||||
bindings = this._bindings.slice(0)//clone array in case add/remove items during dispatch
|
||||
;
|
||||
this._shouldPropagate = true//in case `halt` was called before dispatch or during the previous dispatch.
|
||||
;
|
||||
//execute all callbacks until end of the list or until a callback returns `false` or stops propagation
|
||||
//reverse loop since listeners with higher priority will be added at the end of the list
|
||||
do {
|
||||
n--;
|
||||
}while(bindings[n] && this._shouldPropagate && bindings[n].execute(paramsArr) !== false);
|
||||
};
|
||||
Signal.prototype.forget = /**
|
||||
* Forget memorized arguments.
|
||||
* @see Signal.memorize
|
||||
*/
|
||||
function () {
|
||||
this._prevParams = null;
|
||||
};
|
||||
Signal.prototype.dispose = /**
|
||||
* Remove all bindings from signal and destroy any reference to external objects (destroy Signal object).
|
||||
* <p><strong>IMPORTANT:</strong> calling any method on the signal instance after calling dispose will throw errors.</p>
|
||||
*/
|
||||
function () {
|
||||
this.removeAll();
|
||||
delete this._bindings;
|
||||
delete this._prevParams;
|
||||
};
|
||||
Signal.prototype.toString = /**
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
function () {
|
||||
return '[Signal active:' + this.active + ' numListeners:' + this.getNumListeners() + ']';
|
||||
};
|
||||
return Signal;
|
||||
})();
|
||||
Phaser.Signal = Signal;
|
||||
})(Phaser || (Phaser = {}));
|
113
TS Source/core/SignalBinding.js
Normal file
113
TS Source/core/SignalBinding.js
Normal file
|
@ -0,0 +1,113 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - SignalBinding
|
||||
*
|
||||
* An object that represents a binding between a Signal and a listener function.
|
||||
* Based on JS Signals by Miller Medeiros. Converted by TypeScript by Richard Davey.
|
||||
* Released under the MIT license
|
||||
* http://millermedeiros.github.com/js-signals/
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var SignalBinding = (function () {
|
||||
/**
|
||||
* Object that represents a binding between a Signal and a listener function.
|
||||
* <br />- <strong>This is an internal constructor and shouldn't be called by regular users.</strong>
|
||||
* <br />- inspired by Joa Ebert AS3 SignalBinding and Robert Penner's Slot classes.
|
||||
* @author Miller Medeiros
|
||||
* @constructor
|
||||
* @internal
|
||||
* @name SignalBinding
|
||||
* @param {Signal} signal Reference to Signal object that listener is currently bound to.
|
||||
* @param {Function} listener Handler function bound to the signal.
|
||||
* @param {bool} isOnce If binding should be executed just once.
|
||||
* @param {Object} [listenerContext] Context on which listener will be executed (object that should represent the `this` variable inside listener function).
|
||||
* @param {Number} [priority] The priority level of the event listener. (default = 0).
|
||||
*/
|
||||
function SignalBinding(signal, listener, isOnce, listenerContext, priority) {
|
||||
if (typeof priority === "undefined") { priority = 0; }
|
||||
/**
|
||||
* If binding is active and should be executed.
|
||||
* @type bool
|
||||
*/
|
||||
this.active = true;
|
||||
/**
|
||||
* Default parameters passed to listener during `Signal.dispatch` and `SignalBinding.execute`. (curried parameters)
|
||||
* @type Array|null
|
||||
*/
|
||||
this.params = null;
|
||||
this._listener = listener;
|
||||
this._isOnce = isOnce;
|
||||
this.context = listenerContext;
|
||||
this._signal = signal;
|
||||
this.priority = priority || 0;
|
||||
}
|
||||
SignalBinding.prototype.execute = /**
|
||||
* Call listener passing arbitrary parameters.
|
||||
* <p>If binding was added using `Signal.addOnce()` it will be automatically removed from signal dispatch queue, this method is used internally for the signal dispatch.</p>
|
||||
* @param {Array} [paramsArr] Array of parameters that should be passed to the listener
|
||||
* @return {*} Value returned by the listener.
|
||||
*/
|
||||
function (paramsArr) {
|
||||
var handlerReturn;
|
||||
var params;
|
||||
if(this.active && !!this._listener) {
|
||||
params = this.params ? this.params.concat(paramsArr) : paramsArr;
|
||||
handlerReturn = this._listener.apply(this.context, params);
|
||||
if(this._isOnce) {
|
||||
this.detach();
|
||||
}
|
||||
}
|
||||
return handlerReturn;
|
||||
};
|
||||
SignalBinding.prototype.detach = /**
|
||||
* Detach binding from signal.
|
||||
* - alias to: mySignal.remove(myBinding.getListener());
|
||||
* @return {Function|null} Handler function bound to the signal or `null` if binding was previously detached.
|
||||
*/
|
||||
function () {
|
||||
return this.isBound() ? this._signal.remove(this._listener, this.context) : null;
|
||||
};
|
||||
SignalBinding.prototype.isBound = /**
|
||||
* @return {bool} `true` if binding is still bound to the signal and have a listener.
|
||||
*/
|
||||
function () {
|
||||
return (!!this._signal && !!this._listener);
|
||||
};
|
||||
SignalBinding.prototype.isOnce = /**
|
||||
* @return {bool} If SignalBinding will only be executed once.
|
||||
*/
|
||||
function () {
|
||||
return this._isOnce;
|
||||
};
|
||||
SignalBinding.prototype.getListener = /**
|
||||
* @return {Function} Handler function bound to the signal.
|
||||
*/
|
||||
function () {
|
||||
return this._listener;
|
||||
};
|
||||
SignalBinding.prototype.getSignal = /**
|
||||
* @return {Signal} Signal that listener is currently bound to.
|
||||
*/
|
||||
function () {
|
||||
return this._signal;
|
||||
};
|
||||
SignalBinding.prototype._destroy = /**
|
||||
* Delete instance properties
|
||||
* @private
|
||||
*/
|
||||
function () {
|
||||
delete this._signal;
|
||||
delete this._listener;
|
||||
delete this.context;
|
||||
};
|
||||
SignalBinding.prototype.toString = /**
|
||||
* @return {string} String representation of the object.
|
||||
*/
|
||||
function () {
|
||||
return '[SignalBinding isOnce:' + this._isOnce + ', isBound:' + this.isBound() + ', active:' + this.active + ']';
|
||||
};
|
||||
return SignalBinding;
|
||||
})();
|
||||
Phaser.SignalBinding = SignalBinding;
|
||||
})(Phaser || (Phaser = {}));
|
177
TS Source/display/CSS3Filters.js
Normal file
177
TS Source/display/CSS3Filters.js
Normal file
|
@ -0,0 +1,177 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Display - CSS3Filters
|
||||
*
|
||||
* Allows for easy addition and modification of CSS3 Filters on DOM objects (typically the Game.Stage.canvas).
|
||||
*/
|
||||
(function (Display) {
|
||||
var CSS3Filters = (function () {
|
||||
/**
|
||||
* Creates a new CSS3 Filter component
|
||||
* @param parent The DOM object to apply the filters to.
|
||||
*/
|
||||
function CSS3Filters(parent) {
|
||||
this._blur = 0;
|
||||
this._grayscale = 0;
|
||||
this._sepia = 0;
|
||||
this._brightness = 0;
|
||||
this._contrast = 0;
|
||||
this._hueRotate = 0;
|
||||
this._invert = 0;
|
||||
this._opacity = 0;
|
||||
this._saturate = 0;
|
||||
this.parent = parent;
|
||||
}
|
||||
CSS3Filters.prototype.setFilter = function (local, prefix, value, unit) {
|
||||
this[local] = value;
|
||||
if(this.parent) {
|
||||
this.parent.style['-webkit-filter'] = prefix + '(' + value + unit + ')';
|
||||
}
|
||||
};
|
||||
Object.defineProperty(CSS3Filters.prototype, "blur", {
|
||||
get: function () {
|
||||
return this._blur;
|
||||
},
|
||||
set: /**
|
||||
* Applies a Gaussian blur to the DOM element. The value of 'radius' defines the value of the standard deviation to the Gaussian function,
|
||||
* or how many pixels on the screen blend into each other, so a larger value will create more blur.
|
||||
* If no parameter is provided, then a value 0 is used. The parameter is specified as a CSS length, but does not accept percentage values.
|
||||
*/
|
||||
function (radius) {
|
||||
this.setFilter('_blur', 'blur', radius, 'px');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "grayscale", {
|
||||
get: function () {
|
||||
return this._grayscale;
|
||||
},
|
||||
set: /**
|
||||
* Converts the input image to grayscale. The value of 'amount' defines the proportion of the conversion.
|
||||
* A value of 100% is completely grayscale. A value of 0% leaves the input unchanged.
|
||||
* Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
|
||||
*/
|
||||
function (amount) {
|
||||
this.setFilter('_grayscale', 'grayscale', amount, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "sepia", {
|
||||
get: function () {
|
||||
return this._sepia;
|
||||
},
|
||||
set: /**
|
||||
* Converts the input image to sepia. The value of 'amount' defines the proportion of the conversion.
|
||||
* A value of 100% is completely sepia. A value of 0 leaves the input unchanged.
|
||||
* Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
|
||||
*/
|
||||
function (amount) {
|
||||
this.setFilter('_sepia', 'sepia', amount, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "brightness", {
|
||||
get: function () {
|
||||
return this._brightness;
|
||||
},
|
||||
set: /**
|
||||
* Applies a linear multiplier to input image, making it appear more or less bright.
|
||||
* A value of 0% will create an image that is completely black. A value of 100% leaves the input unchanged.
|
||||
* Other values are linear multipliers on the effect. Values of an amount over 100% are allowed, providing brighter results.
|
||||
* If the 'amount' parameter is missing, a value of 100% is used.
|
||||
*/
|
||||
function (amount) {
|
||||
this.setFilter('_brightness', 'brightness', amount, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "contrast", {
|
||||
get: function () {
|
||||
return this._contrast;
|
||||
},
|
||||
set: /**
|
||||
* Adjusts the contrast of the input. A value of 0% will create an image that is completely black.
|
||||
* A value of 100% leaves the input unchanged. Values of amount over 100% are allowed, providing results with less contrast.
|
||||
* If the 'amount' parameter is missing, a value of 100% is used.
|
||||
*/
|
||||
function (amount) {
|
||||
this.setFilter('_contrast', 'contrast', amount, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "hueRotate", {
|
||||
get: function () {
|
||||
return this._hueRotate;
|
||||
},
|
||||
set: /**
|
||||
* Applies a hue rotation on the input image. The value of 'angle' defines the number of degrees around the color circle
|
||||
* the input samples will be adjusted. A value of 0deg leaves the input unchanged. If the 'angle' parameter is missing,
|
||||
* a value of 0deg is used. Maximum value is 360deg.
|
||||
*/
|
||||
function (angle) {
|
||||
this.setFilter('_hueRotate', 'hue-rotate', angle, 'deg');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "invert", {
|
||||
get: function () {
|
||||
return this._invert;
|
||||
},
|
||||
set: /**
|
||||
* Inverts the samples in the input image. The value of 'amount' defines the proportion of the conversion.
|
||||
* A value of 100% is completely inverted. A value of 0% leaves the input unchanged.
|
||||
* Values between 0% and 100% are linear multipliers on the effect. If the 'amount' parameter is missing, a value of 100% is used.
|
||||
*/
|
||||
function (value) {
|
||||
this.setFilter('_invert', 'invert', value, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "opacity", {
|
||||
get: function () {
|
||||
return this._opacity;
|
||||
},
|
||||
set: /**
|
||||
* Applies transparency to the samples in the input image. The value of 'amount' defines the proportion of the conversion.
|
||||
* A value of 0% is completely transparent. A value of 100% leaves the input unchanged.
|
||||
* Values between 0% and 100% are linear multipliers on the effect. This is equivalent to multiplying the input image samples by amount.
|
||||
* If the 'amount' parameter is missing, a value of 100% is used.
|
||||
* This function is similar to the more established opacity property; the difference is that with filters, some browsers provide hardware acceleration for better performance.
|
||||
*/
|
||||
function (value) {
|
||||
this.setFilter('_opacity', 'opacity', value, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(CSS3Filters.prototype, "saturate", {
|
||||
get: function () {
|
||||
return this._saturate;
|
||||
},
|
||||
set: /**
|
||||
* Saturates the input image. The value of 'amount' defines the proportion of the conversion.
|
||||
* A value of 0% is completely un-saturated. A value of 100% leaves the input unchanged.
|
||||
* Other values are linear multipliers on the effect. Values of amount over 100% are allowed, providing super-saturated results.
|
||||
* If the 'amount' parameter is missing, a value of 100% is used.
|
||||
*/
|
||||
function (value) {
|
||||
this.setFilter('_saturate', 'saturate', value, '%');
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return CSS3Filters;
|
||||
})();
|
||||
Display.CSS3Filters = CSS3Filters;
|
||||
})(Phaser.Display || (Phaser.Display = {}));
|
||||
var Display = Phaser.Display;
|
||||
})(Phaser || (Phaser = {}));
|
238
TS Source/display/DynamicTexture.js
Normal file
238
TS Source/display/DynamicTexture.js
Normal file
|
@ -0,0 +1,238 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Display - DynamicTexture
|
||||
*
|
||||
* A DynamicTexture can be thought of as a mini canvas into which you can draw anything.
|
||||
* Game Objects can be assigned a DynamicTexture, so when they render in the world they do so
|
||||
* based on the contents of the texture at the time. This allows you to create powerful effects
|
||||
* once and have them replicated across as many game objects as you like.
|
||||
*/
|
||||
(function (Display) {
|
||||
var DynamicTexture = (function () {
|
||||
/**
|
||||
* DynamicTexture constructor
|
||||
* Create a new <code>DynamicTexture</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param width {number} Init width of this texture.
|
||||
* @param height {number} Init height of this texture.
|
||||
*/
|
||||
function DynamicTexture(game, width, height) {
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._sw = 0;
|
||||
this._sh = 0;
|
||||
this._dx = 0;
|
||||
this._dy = 0;
|
||||
this._dw = 0;
|
||||
this._dh = 0;
|
||||
/**
|
||||
* You can set a globalCompositeOperation that will be applied before the render method is called on this Sprite.
|
||||
* This is useful if you wish to apply an effect like 'lighten'.
|
||||
* If this value is set it will call a canvas context save and restore before and after the render pass, so use it sparingly.
|
||||
* Set to null to disable.
|
||||
*/
|
||||
this.globalCompositeOperation = null;
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.DYNAMICTEXTURE;
|
||||
this.canvas = document.createElement('canvas');
|
||||
this.canvas.width = width;
|
||||
this.canvas.height = height;
|
||||
this.context = this.canvas.getContext('2d');
|
||||
this.css3 = new Phaser.Display.CSS3Filters(this.canvas);
|
||||
this.bounds = new Phaser.Rectangle(0, 0, width, height);
|
||||
}
|
||||
DynamicTexture.prototype.getPixel = /**
|
||||
* Get a color of a specific pixel.
|
||||
* @param x {number} X position of the pixel in this texture.
|
||||
* @param y {number} Y position of the pixel in this texture.
|
||||
* @return {number} A native color value integer (format: 0xRRGGBB)
|
||||
*/
|
||||
function (x, y) {
|
||||
//r = imageData.data[0];
|
||||
//g = imageData.data[1];
|
||||
//b = imageData.data[2];
|
||||
//a = imageData.data[3];
|
||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||
return Phaser.ColorUtils.getColor(imageData.data[0], imageData.data[1], imageData.data[2]);
|
||||
};
|
||||
DynamicTexture.prototype.getPixel32 = /**
|
||||
* Get a color of a specific pixel (including alpha value).
|
||||
* @param x {number} X position of the pixel in this texture.
|
||||
* @param y {number} Y position of the pixel in this texture.
|
||||
* @return A native color value integer (format: 0xAARRGGBB)
|
||||
*/
|
||||
function (x, y) {
|
||||
var imageData = this.context.getImageData(x, y, 1, 1);
|
||||
return Phaser.ColorUtils.getColor32(imageData.data[3], imageData.data[0], imageData.data[1], imageData.data[2]);
|
||||
};
|
||||
DynamicTexture.prototype.getPixels = /**
|
||||
* Get pixels in array in a specific Rectangle.
|
||||
* @param rect {Rectangle} The specific Rectangle.
|
||||
* @returns {array} CanvasPixelArray.
|
||||
*/
|
||||
function (rect) {
|
||||
return this.context.getImageData(rect.x, rect.y, rect.width, rect.height);
|
||||
};
|
||||
DynamicTexture.prototype.setPixel = /**
|
||||
* Set color of a specific pixel.
|
||||
* @param x {number} X position of the target pixel.
|
||||
* @param y {number} Y position of the target pixel.
|
||||
* @param color {number} Native integer with color value. (format: 0xRRGGBB)
|
||||
*/
|
||||
function (x, y, color) {
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
};
|
||||
DynamicTexture.prototype.setPixel32 = /**
|
||||
* Set color (with alpha) of a specific pixel.
|
||||
* @param x {number} X position of the target pixel.
|
||||
* @param y {number} Y position of the target pixel.
|
||||
* @param color {number} Native integer with color value. (format: 0xAARRGGBB)
|
||||
*/
|
||||
function (x, y, color) {
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(x, y, 1, 1);
|
||||
};
|
||||
DynamicTexture.prototype.setPixels = /**
|
||||
* Set image data to a specific Rectangle.
|
||||
* @param rect {Rectangle} Target Rectangle.
|
||||
* @param input {object} Source image data.
|
||||
*/
|
||||
function (rect, input) {
|
||||
this.context.putImageData(input, rect.x, rect.y);
|
||||
};
|
||||
DynamicTexture.prototype.fillRect = /**
|
||||
* Fill a given Rectangle with specific color.
|
||||
* @param rect {Rectangle} Target Rectangle you want to fill.
|
||||
* @param color {number} A native number with color value. (format: 0xRRGGBB)
|
||||
*/
|
||||
function (rect, color) {
|
||||
this.context.fillStyle = color;
|
||||
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
|
||||
};
|
||||
DynamicTexture.prototype.pasteImage = /**
|
||||
*
|
||||
*/
|
||||
function (key, frame, destX, destY, destWidth, destHeight) {
|
||||
if (typeof frame === "undefined") { frame = -1; }
|
||||
if (typeof destX === "undefined") { destX = 0; }
|
||||
if (typeof destY === "undefined") { destY = 0; }
|
||||
if (typeof destWidth === "undefined") { destWidth = null; }
|
||||
if (typeof destHeight === "undefined") { destHeight = null; }
|
||||
var texture = null;
|
||||
var frameData;
|
||||
this._sx = 0;
|
||||
this._sy = 0;
|
||||
this._dx = destX;
|
||||
this._dy = destY;
|
||||
// TODO - Load a frame from a sprite sheet, otherwise we'll draw the whole lot
|
||||
if(frame > -1) {
|
||||
//if (this.game.cache.isSpriteSheet(key))
|
||||
//{
|
||||
// texture = this.game.cache.getImage(key);
|
||||
//this.animations.loadFrameData(this.game.cache.getFrameData(key));
|
||||
//}
|
||||
} else {
|
||||
texture = this.game.cache.getImage(key);
|
||||
this._sw = texture.width;
|
||||
this._sh = texture.height;
|
||||
this._dw = texture.width;
|
||||
this._dh = texture.height;
|
||||
}
|
||||
if(destWidth !== null) {
|
||||
this._dw = destWidth;
|
||||
}
|
||||
if(destHeight !== null) {
|
||||
this._dh = destHeight;
|
||||
}
|
||||
if(texture != null) {
|
||||
this.context.drawImage(texture, // Source Image
|
||||
this._sx, // Source X (location within the source image)
|
||||
this._sy, // Source Y
|
||||
this._sw, // Source Width
|
||||
this._sh, // Source Height
|
||||
this._dx, // Destination X (where on the canvas it'll be drawn)
|
||||
this._dy, // Destination Y
|
||||
this._dw, // Destination Width (always same as Source Width unless scaled)
|
||||
this._dh);
|
||||
// Destination Height (always same as Source Height unless scaled)
|
||||
}
|
||||
};
|
||||
DynamicTexture.prototype.copyPixels = // TODO - Add in support for: alphaBitmapData: BitmapData = null, alphaPoint: Point = null, mergeAlpha: bool = false
|
||||
/**
|
||||
* Copy pixel from another DynamicTexture to this texture.
|
||||
* @param sourceTexture {DynamicTexture} Source texture object.
|
||||
* @param sourceRect {Rectangle} The specific region Rectangle to be copied to this in the source.
|
||||
* @param destPoint {Point} Top-left point the target image data will be paste at.
|
||||
*/
|
||||
function (sourceTexture, sourceRect, destPoint) {
|
||||
// Swap for drawImage if the sourceRect is the same size as the sourceTexture to avoid a costly getImageData call
|
||||
if(Phaser.RectangleUtils.equals(sourceRect, this.bounds) == true) {
|
||||
this.context.drawImage(sourceTexture.canvas, destPoint.x, destPoint.y);
|
||||
} else {
|
||||
this.context.putImageData(sourceTexture.getPixels(sourceRect), destPoint.x, destPoint.y);
|
||||
}
|
||||
};
|
||||
DynamicTexture.prototype.add = function (sprite) {
|
||||
sprite.texture.canvas = this.canvas;
|
||||
sprite.texture.context = this.context;
|
||||
};
|
||||
DynamicTexture.prototype.assignCanvasToGameObjects = /**
|
||||
* Given an array of Sprites it will update each of them so that their canvas/contexts reference this DynamicTexture
|
||||
* @param objects {Array} An array of GameObjects, or objects that inherit from it such as Sprites
|
||||
*/
|
||||
function (objects) {
|
||||
for(var i = 0; i < objects.length; i++) {
|
||||
if(objects[i].texture) {
|
||||
objects[i].texture.canvas = this.canvas;
|
||||
objects[i].texture.context = this.context;
|
||||
}
|
||||
}
|
||||
};
|
||||
DynamicTexture.prototype.clear = /**
|
||||
* Clear the whole canvas.
|
||||
*/
|
||||
function () {
|
||||
this.context.clearRect(0, 0, this.bounds.width, this.bounds.height);
|
||||
};
|
||||
DynamicTexture.prototype.render = /**
|
||||
* Renders this DynamicTexture to the Stage at the given x/y coordinates
|
||||
*
|
||||
* @param x {number} The X coordinate to render on the stage to (given in screen coordinates, not world)
|
||||
* @param y {number} The Y coordinate to render on the stage to (given in screen coordinates, not world)
|
||||
*/
|
||||
function (x, y) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if(this.globalCompositeOperation) {
|
||||
this.game.stage.context.save();
|
||||
this.game.stage.context.globalCompositeOperation = this.globalCompositeOperation;
|
||||
}
|
||||
this.game.stage.context.drawImage(this.canvas, x, y);
|
||||
if(this.globalCompositeOperation) {
|
||||
this.game.stage.context.restore();
|
||||
}
|
||||
};
|
||||
Object.defineProperty(DynamicTexture.prototype, "width", {
|
||||
get: function () {
|
||||
return this.bounds.width;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(DynamicTexture.prototype, "height", {
|
||||
get: function () {
|
||||
return this.bounds.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return DynamicTexture;
|
||||
})();
|
||||
Display.DynamicTexture = DynamicTexture;
|
||||
})(Phaser.Display || (Phaser.Display = {}));
|
||||
var Display = Phaser.Display;
|
||||
})(Phaser || (Phaser = {}));
|
218
TS Source/display/Texture.js
Normal file
218
TS Source/display/Texture.js
Normal file
|
@ -0,0 +1,218 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Display - Texture
|
||||
*
|
||||
* The Texture being used to render the object (Sprite, Group background, etc). Either Image based on a DynamicTexture.
|
||||
*/
|
||||
(function (Display) {
|
||||
var Texture = (function () {
|
||||
/**
|
||||
* Creates a new Texture component
|
||||
* @param parent The object using this Texture to render.
|
||||
* @param key An optional Game.Cache key to load an image from
|
||||
*/
|
||||
function Texture(parent) {
|
||||
/**
|
||||
* Reference to the Image stored in the Game.Cache that is used as the texture for the Sprite.
|
||||
*/
|
||||
this.imageTexture = null;
|
||||
/**
|
||||
* Reference to the DynamicTexture that is used as the texture for the Sprite.
|
||||
* @type {DynamicTexture}
|
||||
*/
|
||||
this.dynamicTexture = null;
|
||||
/**
|
||||
* The load status of the texture image.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.loaded = false;
|
||||
/**
|
||||
* Whether the texture background is opaque or not. If set to true the object is filled with
|
||||
* the value of Texture.backgroundColor every frame. Normally you wouldn't enable this but
|
||||
* for some effects it can be handy.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.opaque = false;
|
||||
/**
|
||||
* The Background Color of the Sprite if Texture.opaque is set to true.
|
||||
* Given in css color string format, i.e. 'rgb(0,0,0)' or '#ff0000'.
|
||||
* @type {string}
|
||||
*/
|
||||
this.backgroundColor = 'rgb(255,255,255)';
|
||||
/**
|
||||
* You can set a globalCompositeOperation that will be applied before the render method is called on this Sprite.
|
||||
* This is useful if you wish to apply an effect like 'lighten'.
|
||||
* If this value is set it will call a canvas context save and restore before and after the render pass, so use it sparingly.
|
||||
* Set to null to disable.
|
||||
*/
|
||||
this.globalCompositeOperation = null;
|
||||
/**
|
||||
* Controls if the Sprite is rendered rotated or not.
|
||||
* If renderRotation is false then the object can still rotate but it will never be rendered rotated.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.renderRotation = true;
|
||||
/**
|
||||
* Flip the graphic horizontally (defaults to false)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.flippedX = false;
|
||||
/**
|
||||
* Flip the graphic vertically (defaults to false)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.flippedY = false;
|
||||
/**
|
||||
* Is the texture a DynamicTexture?
|
||||
* @type {bool}
|
||||
*/
|
||||
this.isDynamic = false;
|
||||
this.game = parent.game;
|
||||
this.parent = parent;
|
||||
this.canvas = parent.game.stage.canvas;
|
||||
this.context = parent.game.stage.context;
|
||||
this.alpha = 1;
|
||||
this.flippedX = false;
|
||||
this.flippedY = false;
|
||||
this._width = 16;
|
||||
this._height = 16;
|
||||
this.cameraBlacklist = [];
|
||||
this._blacklist = 0;
|
||||
}
|
||||
Texture.prototype.hideFromCamera = /**
|
||||
* Hides an object from this Camera. Hidden objects are not rendered.
|
||||
*
|
||||
* @param object {Camera} The camera this object should ignore.
|
||||
*/
|
||||
function (camera) {
|
||||
if(this.isHidden(camera) == false) {
|
||||
this.cameraBlacklist.push(camera.ID);
|
||||
this._blacklist++;
|
||||
}
|
||||
};
|
||||
Texture.prototype.isHidden = /**
|
||||
* Returns true if this texture is hidden from rendering to the given camera, otherwise false.
|
||||
*/
|
||||
function (camera) {
|
||||
if(this._blacklist && this.cameraBlacklist.indexOf(camera.ID) !== -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
Texture.prototype.showToCamera = /**
|
||||
* Un-hides an object previously hidden to this Camera.
|
||||
* The object must implement a public cameraBlacklist property.
|
||||
*
|
||||
* @param object {Sprite/Group} The object this camera should display.
|
||||
*/
|
||||
function (camera) {
|
||||
if(this.isHidden(camera)) {
|
||||
this.cameraBlacklist.slice(this.cameraBlacklist.indexOf(camera.ID), 1);
|
||||
this._blacklist--;
|
||||
}
|
||||
};
|
||||
Texture.prototype.setTo = /**
|
||||
* Updates the texture being used to render the Sprite.
|
||||
* Called automatically by SpriteUtils.loadTexture and SpriteUtils.loadDynamicTexture.
|
||||
*/
|
||||
function (image, dynamic) {
|
||||
if (typeof image === "undefined") { image = null; }
|
||||
if (typeof dynamic === "undefined") { dynamic = null; }
|
||||
if(dynamic) {
|
||||
this.isDynamic = true;
|
||||
this.dynamicTexture = dynamic;
|
||||
this.texture = this.dynamicTexture.canvas;
|
||||
} else {
|
||||
this.isDynamic = false;
|
||||
this.imageTexture = image;
|
||||
this.texture = this.imageTexture;
|
||||
this._width = image.width;
|
||||
this._height = image.height;
|
||||
}
|
||||
this.loaded = true;
|
||||
return this.parent;
|
||||
};
|
||||
Texture.prototype.loadImage = /**
|
||||
* Sets a new graphic from the game cache to use as the texture for this Sprite.
|
||||
* The graphic can be SpriteSheet or Texture Atlas. If you need to use a DynamicTexture see loadDynamicTexture.
|
||||
* @param key {string} Key of the graphic you want to load for this sprite.
|
||||
* @param clearAnimations {bool} If this Sprite has a set of animation data already loaded you can choose to keep or clear it with this bool
|
||||
* @param updateBody {bool} Update the physics body dimensions to match the newly loaded texture/frame?
|
||||
*/
|
||||
function (key, clearAnimations, updateBody) {
|
||||
if (typeof clearAnimations === "undefined") { clearAnimations = true; }
|
||||
if (typeof updateBody === "undefined") { updateBody = true; }
|
||||
if(clearAnimations && this.parent['animations'] && this.parent['animations'].frameData !== null) {
|
||||
this.parent.animations.destroy();
|
||||
}
|
||||
if(this.game.cache.getImage(key) !== null) {
|
||||
this.setTo(this.game.cache.getImage(key), null);
|
||||
this.cacheKey = key;
|
||||
if(this.game.cache.isSpriteSheet(key) && this.parent['animations']) {
|
||||
this.parent.animations.loadFrameData(this.parent.game.cache.getFrameData(key));
|
||||
} else {
|
||||
if(updateBody && this.parent['body']) {
|
||||
this.parent.body.bounds.width = this.width;
|
||||
this.parent.body.bounds.height = this.height;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Texture.prototype.loadDynamicTexture = /**
|
||||
* Load a DynamicTexture as its texture.
|
||||
* @param texture {DynamicTexture} The texture object to be used by this sprite.
|
||||
*/
|
||||
function (texture) {
|
||||
if(this.parent.animations.frameData !== null) {
|
||||
this.parent.animations.destroy();
|
||||
}
|
||||
this.setTo(null, texture);
|
||||
this.parent.texture.width = this.width;
|
||||
this.parent.texture.height = this.height;
|
||||
};
|
||||
Object.defineProperty(Texture.prototype, "width", {
|
||||
get: /**
|
||||
* The width of the texture. If an animation it will be the frame width, not the width of the sprite sheet.
|
||||
* If using a DynamicTexture it will be the width of the dynamic texture itself.
|
||||
* @type {number}
|
||||
*/
|
||||
function () {
|
||||
if(this.isDynamic) {
|
||||
return this.dynamicTexture.width;
|
||||
} else {
|
||||
return this._width;
|
||||
}
|
||||
},
|
||||
set: function (value) {
|
||||
this._width = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Texture.prototype, "height", {
|
||||
get: /**
|
||||
* The height of the texture. If an animation it will be the frame height, not the height of the sprite sheet.
|
||||
* If using a DynamicTexture it will be the height of the dynamic texture itself.
|
||||
* @type {number}
|
||||
*/
|
||||
function () {
|
||||
if(this.isDynamic) {
|
||||
return this.dynamicTexture.height;
|
||||
} else {
|
||||
return this._height;
|
||||
}
|
||||
},
|
||||
set: function (value) {
|
||||
this._height = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
return Texture;
|
||||
})();
|
||||
Display.Texture = Texture;
|
||||
})(Phaser.Display || (Phaser.Display = {}));
|
||||
var Display = Phaser.Display;
|
||||
})(Phaser || (Phaser = {}));
|
29
TS Source/gameobjects/Events.js
Normal file
29
TS Source/gameobjects/Events.js
Normal file
|
@ -0,0 +1,29 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Components - Events
|
||||
*
|
||||
* Signals that are dispatched by the Sprite and its various components
|
||||
*/
|
||||
(function (Components) {
|
||||
var Events = (function () {
|
||||
/**
|
||||
* The Events component is a collection of events fired by the parent game object and its components.
|
||||
* @param parent The game object using this Input component
|
||||
*/
|
||||
function Events(parent) {
|
||||
this.game = parent.game;
|
||||
this._parent = parent;
|
||||
this.onAddedToGroup = new Phaser.Signal();
|
||||
this.onRemovedFromGroup = new Phaser.Signal();
|
||||
this.onKilled = new Phaser.Signal();
|
||||
this.onRevived = new Phaser.Signal();
|
||||
this.onOutOfBounds = new Phaser.Signal();
|
||||
}
|
||||
return Events;
|
||||
})();
|
||||
Components.Events = Events;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
260
TS Source/gameobjects/GameObjectFactory.js
Normal file
260
TS Source/gameobjects/GameObjectFactory.js
Normal file
|
@ -0,0 +1,260 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - GameObjectFactory
|
||||
*
|
||||
* A quick way to create new world objects and add existing objects to the current world.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var GameObjectFactory = (function () {
|
||||
/**
|
||||
* GameObjectFactory constructor
|
||||
* @param game {Game} A reference to the current Game.
|
||||
*/
|
||||
function GameObjectFactory(game) {
|
||||
this.game = game;
|
||||
this._world = this.game.world;
|
||||
}
|
||||
GameObjectFactory.prototype.camera = /**
|
||||
* Create a new camera with specific position and size.
|
||||
*
|
||||
* @param x {number} X position of the new camera.
|
||||
* @param y {number} Y position of the new camera.
|
||||
* @param width {number} Width of the new camera.
|
||||
* @param height {number} Height of the new camera.
|
||||
* @returns {Camera} The newly created camera object.
|
||||
*/
|
||||
function (x, y, width, height) {
|
||||
return this._world.cameras.addCamera(x, y, width, height);
|
||||
};
|
||||
GameObjectFactory.prototype.button = /**
|
||||
* Create a new GeomSprite with specific position.
|
||||
*
|
||||
* @param x {number} X position of the new geom sprite.
|
||||
* @param y {number} Y position of the new geom sprite.
|
||||
* @returns {GeomSprite} The newly created geom sprite object.
|
||||
*/
|
||||
//public geomSprite(x: number, y: number): GeomSprite {
|
||||
// return <GeomSprite> this._world.group.add(new GeomSprite(this.game, x, y));
|
||||
//}
|
||||
/**
|
||||
* Create a new Button game object.
|
||||
*
|
||||
* @param [x] {number} X position of the button.
|
||||
* @param [y] {number} Y position of the button.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this button.
|
||||
* @param [callback] {function} The function to call when this button is pressed
|
||||
* @param [callbackContext] {object} The context in which the callback will be called (usually 'this')
|
||||
* @param [overFrame] {string|number} This is the frame or frameName that will be set when this button is in an over state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param [outFrame] {string|number} This is the frame or frameName that will be set when this button is in an out state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @param [downFrame] {string|number} This is the frame or frameName that will be set when this button is in a down state. Give either a number to use a frame ID or a string for a frame name.
|
||||
* @returns {Button} The newly created button object.
|
||||
*/
|
||||
function (x, y, key, callback, callbackContext, overFrame, outFrame, downFrame) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof key === "undefined") { key = null; }
|
||||
if (typeof callback === "undefined") { callback = null; }
|
||||
if (typeof callbackContext === "undefined") { callbackContext = null; }
|
||||
if (typeof overFrame === "undefined") { overFrame = null; }
|
||||
if (typeof outFrame === "undefined") { outFrame = null; }
|
||||
if (typeof downFrame === "undefined") { downFrame = null; }
|
||||
return this._world.group.add(new Phaser.UI.Button(this.game, x, y, key, callback, callbackContext, overFrame, outFrame, downFrame));
|
||||
};
|
||||
GameObjectFactory.prototype.sprite = /**
|
||||
* Create a new Sprite with specific position and sprite sheet key.
|
||||
*
|
||||
* @param x {number} X position of the new sprite.
|
||||
* @param y {number} Y position of the new sprite.
|
||||
* @param [key] {string} The image key as defined in the Game.Cache to use as the texture for this sprite
|
||||
* @param [frame] {string|number} If the sprite uses an image from a texture atlas or sprite sheet you can pass the frame here. Either a number for a frame ID or a string for a frame name.
|
||||
* @returns {Sprite} The newly created sprite object.
|
||||
*/
|
||||
function (x, y, key, frame) {
|
||||
if (typeof key === "undefined") { key = ''; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
return this._world.group.add(new Phaser.Sprite(this.game, x, y, key, frame));
|
||||
};
|
||||
GameObjectFactory.prototype.audio = function (key, volume, loop) {
|
||||
if (typeof volume === "undefined") { volume = 1; }
|
||||
if (typeof loop === "undefined") { loop = false; }
|
||||
return this.game.sound.add(key, volume, loop);
|
||||
};
|
||||
GameObjectFactory.prototype.circle = function (x, y, radius) {
|
||||
return new Phaser.Physics.Circle(this.game, x, y, radius);
|
||||
};
|
||||
GameObjectFactory.prototype.aabb = function (x, y, width, height) {
|
||||
return new Phaser.Physics.AABB(this.game, x, y, Math.floor(width / 2), Math.floor(height / 2));
|
||||
};
|
||||
GameObjectFactory.prototype.cell = function (x, y, width, height, state) {
|
||||
if (typeof state === "undefined") { state = Phaser.Physics.TileMapCell.TID_FULL; }
|
||||
return new Phaser.Physics.TileMapCell(this.game, x, y, width, height).SetState(state);
|
||||
};
|
||||
GameObjectFactory.prototype.dynamicTexture = /**
|
||||
* Create a new DynamicTexture with specific size.
|
||||
*
|
||||
* @param width {number} Width of the texture.
|
||||
* @param height {number} Height of the texture.
|
||||
* @returns {DynamicTexture} The newly created dynamic texture object.
|
||||
*/
|
||||
function (width, height) {
|
||||
return new Phaser.Display.DynamicTexture(this.game, width, height);
|
||||
};
|
||||
GameObjectFactory.prototype.group = /**
|
||||
* Create a new object container.
|
||||
*
|
||||
* @param maxSize {number} Optional, capacity of this group.
|
||||
* @returns {Group} The newly created group.
|
||||
*/
|
||||
function (maxSize) {
|
||||
if (typeof maxSize === "undefined") { maxSize = 0; }
|
||||
return this._world.group.add(new Phaser.Group(this.game, maxSize));
|
||||
};
|
||||
GameObjectFactory.prototype.scrollZone = /**
|
||||
* Create a new Particle.
|
||||
*
|
||||
* @return {Particle} The newly created particle object.
|
||||
*/
|
||||
//public particle(): Phaser.ArcadeParticle {
|
||||
// return new Phaser.ArcadeParticle(this.game);
|
||||
//}
|
||||
/**
|
||||
* Create a new Emitter.
|
||||
*
|
||||
* @param x {number} Optional, x position of the emitter.
|
||||
* @param y {number} Optional, y position of the emitter.
|
||||
* @param size {number} Optional, size of this emitter.
|
||||
* @return {Emitter} The newly created emitter object.
|
||||
*/
|
||||
//public emitter(x: number = 0, y: number = 0, size: number = 0): Phaser.ArcadeEmitter {
|
||||
// return <Phaser.ArcadeEmitter> this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size));
|
||||
//}
|
||||
/**
|
||||
* Create a new ScrollZone object with image key, position and size.
|
||||
*
|
||||
* @param key {string} Key to a image you wish this object to use.
|
||||
* @param x {number} X position of this object.
|
||||
* @param y {number} Y position of this object.
|
||||
* @param width number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @returns {ScrollZone} The newly created scroll zone object.
|
||||
*/
|
||||
function (key, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
return this._world.group.add(new Phaser.ScrollZone(this.game, key, x, y, width, height));
|
||||
};
|
||||
GameObjectFactory.prototype.tilemap = /**
|
||||
* Create a new Tilemap.
|
||||
*
|
||||
* @param key {string} Key for tileset image.
|
||||
* @param mapData {string} Data of this tilemap.
|
||||
* @param format {number} Format of map data. (Tilemap.FORMAT_CSV or Tilemap.FORMAT_TILED_JSON)
|
||||
* @param [resizeWorld] {bool} resize the world to make same as tilemap?
|
||||
* @param [tileWidth] {number} width of each tile.
|
||||
* @param [tileHeight] {number} height of each tile.
|
||||
* @return {Tilemap} The newly created tilemap object.
|
||||
*/
|
||||
function (key, mapData, format, resizeWorld, tileWidth, tileHeight) {
|
||||
if (typeof resizeWorld === "undefined") { resizeWorld = true; }
|
||||
if (typeof tileWidth === "undefined") { tileWidth = 0; }
|
||||
if (typeof tileHeight === "undefined") { tileHeight = 0; }
|
||||
return this._world.group.add(new Phaser.Tilemap(this.game, key, mapData, format, resizeWorld, tileWidth, tileHeight));
|
||||
};
|
||||
GameObjectFactory.prototype.tween = /**
|
||||
* Create a tween object for a specific object. The object can be any JavaScript object or Phaser object such as Sprite.
|
||||
*
|
||||
* @param obj {object} Object the tween will be run on.
|
||||
* @param [localReference] {bool} If true the tween will be stored in the object.tween property so long as it exists. If already set it'll be over-written.
|
||||
* @return {Phaser.Tween} The newly created tween object.
|
||||
*/
|
||||
function (obj, localReference) {
|
||||
if (typeof localReference === "undefined") { localReference = false; }
|
||||
return this.game.tweens.create(obj, localReference);
|
||||
};
|
||||
GameObjectFactory.prototype.existingSprite = /**
|
||||
* Add an existing Sprite to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param sprite The Sprite to add to the Game World
|
||||
* @return {Phaser.Sprite} The Sprite object
|
||||
*/
|
||||
function (sprite) {
|
||||
return this._world.group.add(sprite);
|
||||
};
|
||||
GameObjectFactory.prototype.existingGroup = /**
|
||||
* Add an existing Group to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param group The Group to add to the Game World
|
||||
* @return {Phaser.Group} The Group object
|
||||
*/
|
||||
function (group) {
|
||||
return this._world.group.add(group);
|
||||
};
|
||||
GameObjectFactory.prototype.existingButton = /**
|
||||
* Add an existing Button to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param button The Button to add to the Game World
|
||||
* @return {Phaser.Button} The Button object
|
||||
*/
|
||||
function (button) {
|
||||
return this._world.group.add(button);
|
||||
};
|
||||
GameObjectFactory.prototype.existingScrollZone = /**
|
||||
* Add an existing GeomSprite to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param sprite The GeomSprite to add to the Game World
|
||||
* @return {Phaser.GeomSprite} The GeomSprite object
|
||||
*/
|
||||
//public existingGeomSprite(sprite: GeomSprite): GeomSprite {
|
||||
// return this._world.group.add(sprite);
|
||||
//}
|
||||
/**
|
||||
* Add an existing Emitter to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param emitter The Emitter to add to the Game World
|
||||
* @return {Phaser.Emitter} The Emitter object
|
||||
*/
|
||||
//public existingEmitter(emitter: Phaser.ArcadeEmitter): Phaser.ArcadeEmitter {
|
||||
// return this._world.group.add(emitter);
|
||||
//}
|
||||
/**
|
||||
* Add an existing ScrollZone to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param scrollZone The ScrollZone to add to the Game World
|
||||
* @return {Phaser.ScrollZone} The ScrollZone object
|
||||
*/
|
||||
function (scrollZone) {
|
||||
return this._world.group.add(scrollZone);
|
||||
};
|
||||
GameObjectFactory.prototype.existingTilemap = /**
|
||||
* Add an existing Tilemap to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param tilemap The Tilemap to add to the Game World
|
||||
* @return {Phaser.Tilemap} The Tilemap object
|
||||
*/
|
||||
function (tilemap) {
|
||||
return this._world.group.add(tilemap);
|
||||
};
|
||||
GameObjectFactory.prototype.existingTween = /**
|
||||
* Add an existing Tween to the current world.
|
||||
* Note: This doesn't check or update the objects reference to Game. If that is wrong, all kinds of things will break.
|
||||
*
|
||||
* @param tween The Tween to add to the Game World
|
||||
* @return {Phaser.Tween} The Tween object
|
||||
*/
|
||||
function (tween) {
|
||||
return this.game.tweens.add(tween);
|
||||
};
|
||||
return GameObjectFactory;
|
||||
})();
|
||||
Phaser.GameObjectFactory = GameObjectFactory;
|
||||
})(Phaser || (Phaser = {}));
|
148
TS Source/gameobjects/ScrollRegion.js
Normal file
148
TS Source/gameobjects/ScrollRegion.js
Normal file
|
@ -0,0 +1,148 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - ScrollRegion
|
||||
*
|
||||
* Creates a scrolling region within a ScrollZone.
|
||||
* It is scrolled via the scrollSpeed.x/y properties.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var ScrollRegion = (function () {
|
||||
/**
|
||||
* ScrollRegion constructor
|
||||
* Create a new <code>ScrollRegion</code>.
|
||||
*
|
||||
* @param x {number} X position in world coordinate.
|
||||
* @param y {number} Y position in world coordinate.
|
||||
* @param width {number} Width of this object.
|
||||
* @param height {number} Height of this object.
|
||||
* @param speedX {number} X-axis scrolling speed.
|
||||
* @param speedY {number} Y-axis scrolling speed.
|
||||
*/
|
||||
function ScrollRegion(x, y, width, height, speedX, speedY) {
|
||||
this._anchorWidth = 0;
|
||||
this._anchorHeight = 0;
|
||||
this._inverseWidth = 0;
|
||||
this._inverseHeight = 0;
|
||||
/**
|
||||
* Will this region be rendered? (default to true)
|
||||
* @type {bool}
|
||||
*/
|
||||
this.visible = true;
|
||||
// Our seamless scrolling quads
|
||||
this._A = new Phaser.Rectangle(x, y, width, height);
|
||||
this._B = new Phaser.Rectangle(x, y, width, height);
|
||||
this._C = new Phaser.Rectangle(x, y, width, height);
|
||||
this._D = new Phaser.Rectangle(x, y, width, height);
|
||||
this._scroll = new Phaser.Vec2();
|
||||
this._bounds = new Phaser.Rectangle(x, y, width, height);
|
||||
this.scrollSpeed = new Phaser.Vec2(speedX, speedY);
|
||||
}
|
||||
ScrollRegion.prototype.update = /**
|
||||
* Update region scrolling with tick time.
|
||||
* @param delta {number} Elapsed time since last update.
|
||||
*/
|
||||
function (delta) {
|
||||
this._scroll.x += this.scrollSpeed.x;
|
||||
this._scroll.y += this.scrollSpeed.y;
|
||||
if(this._scroll.x > this._bounds.right) {
|
||||
this._scroll.x = this._bounds.x;
|
||||
}
|
||||
if(this._scroll.x < this._bounds.x) {
|
||||
this._scroll.x = this._bounds.right;
|
||||
}
|
||||
if(this._scroll.y > this._bounds.bottom) {
|
||||
this._scroll.y = this._bounds.y;
|
||||
}
|
||||
if(this._scroll.y < this._bounds.y) {
|
||||
this._scroll.y = this._bounds.bottom;
|
||||
}
|
||||
// Anchor Dimensions
|
||||
this._anchorWidth = (this._bounds.width - this._scroll.x) + this._bounds.x;
|
||||
this._anchorHeight = (this._bounds.height - this._scroll.y) + this._bounds.y;
|
||||
if(this._anchorWidth > this._bounds.width) {
|
||||
this._anchorWidth = this._bounds.width;
|
||||
}
|
||||
if(this._anchorHeight > this._bounds.height) {
|
||||
this._anchorHeight = this._bounds.height;
|
||||
}
|
||||
this._inverseWidth = this._bounds.width - this._anchorWidth;
|
||||
this._inverseHeight = this._bounds.height - this._anchorHeight;
|
||||
// Rectangle A
|
||||
this._A.setTo(this._scroll.x, this._scroll.y, this._anchorWidth, this._anchorHeight);
|
||||
// Rectangle B
|
||||
this._B.y = this._scroll.y;
|
||||
this._B.width = this._inverseWidth;
|
||||
this._B.height = this._anchorHeight;
|
||||
// Rectangle C
|
||||
this._C.x = this._scroll.x;
|
||||
this._C.width = this._anchorWidth;
|
||||
this._C.height = this._inverseHeight;
|
||||
// Rectangle D
|
||||
this._D.width = this._inverseWidth;
|
||||
this._D.height = this._inverseHeight;
|
||||
};
|
||||
ScrollRegion.prototype.render = /**
|
||||
* Render this region to specific context.
|
||||
* @param context {CanvasRenderingContext2D} Canvas context this region will be rendered to.
|
||||
* @param texture {object} The texture to be rendered.
|
||||
* @param dx {number} X position in world coordinate.
|
||||
* @param dy {number} Y position in world coordinate.
|
||||
* @param width {number} Width of this region to be rendered.
|
||||
* @param height {number} Height of this region to be rendered.
|
||||
*/
|
||||
function (context, texture, dx, dy, dw, dh) {
|
||||
if(this.visible == false) {
|
||||
return;
|
||||
}
|
||||
// dx/dy are the world coordinates to render the FULL ScrollZone into.
|
||||
// This ScrollRegion may be smaller than that and offset from the dx/dy coordinates.
|
||||
this.crop(context, texture, this._A.x, this._A.y, this._A.width, this._A.height, dx, dy, dw, dh, 0, 0);
|
||||
this.crop(context, texture, this._B.x, this._B.y, this._B.width, this._B.height, dx, dy, dw, dh, this._A.width, 0);
|
||||
this.crop(context, texture, this._C.x, this._C.y, this._C.width, this._C.height, dx, dy, dw, dh, 0, this._A.height);
|
||||
this.crop(context, texture, this._D.x, this._D.y, this._D.width, this._D.height, dx, dy, dw, dh, this._C.width, this._A.height);
|
||||
//context.fillStyle = 'rgb(255,255,255)';
|
||||
//context.font = '18px Arial';
|
||||
//context.fillText('RectangleA: ' + this._A.toString(), 32, 450);
|
||||
//context.fillText('RectangleB: ' + this._B.toString(), 32, 480);
|
||||
//context.fillText('RectangleC: ' + this._C.toString(), 32, 510);
|
||||
//context.fillText('RectangleD: ' + this._D.toString(), 32, 540);
|
||||
};
|
||||
ScrollRegion.prototype.crop = /**
|
||||
* Crop part of the texture and render it to the given context.
|
||||
* @param context {CanvasRenderingContext2D} Canvas context the texture will be rendered to.
|
||||
* @param texture {object} Texture to be rendered.
|
||||
* @param srcX {number} Target region top-left x coordinate in the texture.
|
||||
* @param srcX {number} Target region top-left y coordinate in the texture.
|
||||
* @param srcW {number} Target region width in the texture.
|
||||
* @param srcH {number} Target region height in the texture.
|
||||
* @param destX {number} Render region top-left x coordinate in the context.
|
||||
* @param destX {number} Render region top-left y coordinate in the context.
|
||||
* @param destW {number} Target region width in the context.
|
||||
* @param destH {number} Target region height in the context.
|
||||
* @param offsetX {number} X offset to the context.
|
||||
* @param offsetY {number} Y offset to the context.
|
||||
*/
|
||||
function (context, texture, srcX, srcY, srcW, srcH, destX, destY, destW, destH, offsetX, offsetY) {
|
||||
offsetX += destX;
|
||||
offsetY += destY;
|
||||
if(srcW > (destX + destW) - offsetX) {
|
||||
srcW = (destX + destW) - offsetX;
|
||||
}
|
||||
if(srcH > (destY + destH) - offsetY) {
|
||||
srcH = (destY + destH) - offsetY;
|
||||
}
|
||||
srcX = Math.floor(srcX);
|
||||
srcY = Math.floor(srcY);
|
||||
srcW = Math.floor(srcW);
|
||||
srcH = Math.floor(srcH);
|
||||
offsetX = Math.floor(offsetX + this._bounds.x);
|
||||
offsetY = Math.floor(offsetY + this._bounds.y);
|
||||
if(srcW > 0 && srcH > 0) {
|
||||
context.drawImage(texture, srcX, srcY, srcW, srcH, offsetX, offsetY, srcW, srcH);
|
||||
}
|
||||
};
|
||||
return ScrollRegion;
|
||||
})();
|
||||
Phaser.ScrollRegion = ScrollRegion;
|
||||
})(Phaser || (Phaser = {}));
|
111
TS Source/gameobjects/ScrollZone.js
Normal file
111
TS Source/gameobjects/ScrollZone.js
Normal file
|
@ -0,0 +1,111 @@
|
|||
var __extends = this.__extends || function (d, b) {
|
||||
function __() { this.constructor = d; }
|
||||
__.prototype = b.prototype;
|
||||
d.prototype = new __();
|
||||
};
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - ScrollZone
|
||||
*
|
||||
* Creates a scrolling region of the given width and height from an image in the cache.
|
||||
* The ScrollZone can be positioned anywhere in-world like a normal game object, re-act to physics, collision, etc.
|
||||
* The image within it is scrolled via ScrollRegions and their scrollSpeed.x/y properties.
|
||||
* If you create a scroll zone larger than the given source image it will create a DynamicTexture and fill it with a pattern of the source image.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var ScrollZone = (function (_super) {
|
||||
__extends(ScrollZone, _super);
|
||||
/**
|
||||
* ScrollZone constructor
|
||||
* Create a new <code>ScrollZone</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param key {string} Asset key for image texture of this object.
|
||||
* @param x {number} X position in world coordinate.
|
||||
* @param y {number} Y position in world coordinate.
|
||||
* @param [width] {number} width of this object.
|
||||
* @param [height] {number} height of this object.
|
||||
*/
|
||||
function ScrollZone(game, key, x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
_super.call(this, game, x, y, key);
|
||||
this.type = Phaser.Types.SCROLLZONE;
|
||||
this.regions = [];
|
||||
if(this.texture.loaded) {
|
||||
if(width > this.width || height > this.height) {
|
||||
// Create our repeating texture (as the source image wasn't large enough for the requested size)
|
||||
this.createRepeatingTexture(width, height);
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
// Create a default ScrollRegion at the requested size
|
||||
this.addRegion(0, 0, this.width, this.height);
|
||||
// If the zone is smaller than the image itself then shrink the bounds
|
||||
if((width < this.width || height < this.height) && width !== 0 && height !== 0) {
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
}
|
||||
}
|
||||
ScrollZone.prototype.addRegion = /**
|
||||
* Add a new region to this zone.
|
||||
* @param x {number} X position of the new region.
|
||||
* @param y {number} Y position of the new region.
|
||||
* @param width {number} Width of the new region.
|
||||
* @param height {number} Height of the new region.
|
||||
* @param [speedX] {number} x-axis scrolling speed.
|
||||
* @param [speedY] {number} y-axis scrolling speed.
|
||||
* @return {ScrollRegion} The newly added region.
|
||||
*/
|
||||
function (x, y, width, height, speedX, speedY) {
|
||||
if (typeof speedX === "undefined") { speedX = 0; }
|
||||
if (typeof speedY === "undefined") { speedY = 0; }
|
||||
if(x > this.width || y > this.height || x < 0 || y < 0 || (x + width) > this.width || (y + height) > this.height) {
|
||||
throw Error('Invalid ScrollRegion defined. Cannot be larger than parent ScrollZone');
|
||||
return null;
|
||||
}
|
||||
this.currentRegion = new Phaser.ScrollRegion(x, y, width, height, speedX, speedY);
|
||||
this.regions.push(this.currentRegion);
|
||||
return this.currentRegion;
|
||||
};
|
||||
ScrollZone.prototype.setSpeed = /**
|
||||
* Set scrolling speed of current region.
|
||||
* @param x {number} X speed of current region.
|
||||
* @param y {number} Y speed of current region.
|
||||
*/
|
||||
function (x, y) {
|
||||
if(this.currentRegion) {
|
||||
this.currentRegion.scrollSpeed.setTo(x, y);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
ScrollZone.prototype.update = /**
|
||||
* Update regions.
|
||||
*/
|
||||
function () {
|
||||
for(var i = 0; i < this.regions.length; i++) {
|
||||
this.regions[i].update(this.game.time.delta);
|
||||
}
|
||||
};
|
||||
ScrollZone.prototype.createRepeatingTexture = /**
|
||||
* Create repeating texture with _texture, and store it into the _dynamicTexture.
|
||||
* Used to create texture when texture image is small than size of the zone.
|
||||
*/
|
||||
function (regionWidth, regionHeight) {
|
||||
// Work out how many we'll need of the source image to make it tile properly
|
||||
var tileWidth = Math.ceil(this.width / regionWidth) * regionWidth;
|
||||
var tileHeight = Math.ceil(this.height / regionHeight) * regionHeight;
|
||||
var dt = new Phaser.Display.DynamicTexture(this.game, tileWidth, tileHeight);
|
||||
dt.context.rect(0, 0, tileWidth, tileHeight);
|
||||
dt.context.fillStyle = dt.context.createPattern(this.texture.imageTexture, "repeat");
|
||||
dt.context.fill();
|
||||
this.texture.loadDynamicTexture(dt);
|
||||
};
|
||||
return ScrollZone;
|
||||
})(Phaser.Sprite);
|
||||
Phaser.ScrollZone = ScrollZone;
|
||||
})(Phaser || (Phaser = {}));
|
263
TS Source/gameobjects/Sprite.js
Normal file
263
TS Source/gameobjects/Sprite.js
Normal file
|
@ -0,0 +1,263 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Sprite
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Sprite = (function () {
|
||||
/**
|
||||
* Create a new <code>Sprite</code>.
|
||||
*
|
||||
* @param game {Phaser.Game} Current game instance.
|
||||
* @param [x] {number} the initial x position of the sprite.
|
||||
* @param [y] {number} the initial y position of the sprite.
|
||||
* @param [key] {string} Key of the graphic you want to load for this sprite.
|
||||
*/
|
||||
function Sprite(game, x, y, key, frame) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof key === "undefined") { key = null; }
|
||||
if (typeof frame === "undefined") { frame = null; }
|
||||
/**
|
||||
* A bool representing if the Sprite has been modified in any way via a scale, rotate, flip or skew.
|
||||
*/
|
||||
this.modified = false;
|
||||
/**
|
||||
* x value of the object.
|
||||
*/
|
||||
this.x = 0;
|
||||
/**
|
||||
* y value of the object.
|
||||
*/
|
||||
this.y = 0;
|
||||
/**
|
||||
* z order value of the object.
|
||||
*/
|
||||
this.z = -1;
|
||||
/**
|
||||
* Render iteration counter
|
||||
*/
|
||||
this.renderOrderID = 0;
|
||||
this.game = game;
|
||||
this.type = Phaser.Types.SPRITE;
|
||||
this.exists = true;
|
||||
this.active = true;
|
||||
this.visible = true;
|
||||
this.alive = true;
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = -1;
|
||||
this.group = null;
|
||||
this.name = '';
|
||||
this.events = new Phaser.Components.Events(this);
|
||||
this.animations = new Phaser.Components.AnimationManager(this);
|
||||
this.input = new Phaser.Components.InputHandler(this);
|
||||
this.texture = new Phaser.Display.Texture(this);
|
||||
this.transform = new Phaser.Components.TransformManager(this);
|
||||
if(key !== null) {
|
||||
this.texture.loadImage(key, false);
|
||||
} else {
|
||||
this.texture.opaque = true;
|
||||
}
|
||||
if(frame !== null) {
|
||||
if(typeof frame == 'string') {
|
||||
this.frameName = frame;
|
||||
} else {
|
||||
this.frame = frame;
|
||||
}
|
||||
}
|
||||
this.worldView = new Phaser.Rectangle(x, y, this.width, this.height);
|
||||
this.cameraView = new Phaser.Rectangle(x, y, this.width, this.height);
|
||||
this.transform.setCache();
|
||||
this.body = new Phaser.Physics.Body(this, 0);
|
||||
this.outOfBounds = false;
|
||||
this.outOfBoundsAction = Phaser.Types.OUT_OF_BOUNDS_PERSIST;
|
||||
// Handy proxies
|
||||
this.scale = this.transform.scale;
|
||||
this.alpha = this.texture.alpha;
|
||||
this.origin = this.transform.origin;
|
||||
this.crop = this.texture.crop;
|
||||
}
|
||||
Object.defineProperty(Sprite.prototype, "rotation", {
|
||||
get: /**
|
||||
* The rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
*/
|
||||
function () {
|
||||
return this.transform.rotation;
|
||||
},
|
||||
set: /**
|
||||
* Set the rotation of the sprite in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
* The value is automatically wrapped to be between 0 and 360.
|
||||
*/
|
||||
function (value) {
|
||||
this.transform.rotation = this.game.math.wrap(value, 360, 0);
|
||||
if(this.body) {
|
||||
//this.body.angle = this.game.math.degreesToRadians(this.game.math.wrap(value, 360, 0));
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Sprite.prototype.bringToTop = /**
|
||||
* Brings this Sprite to the top of its current Group, if set.
|
||||
*/
|
||||
function () {
|
||||
if(this.group) {
|
||||
this.group.bringToTop(this);
|
||||
}
|
||||
};
|
||||
Object.defineProperty(Sprite.prototype, "alpha", {
|
||||
get: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
*/
|
||||
function () {
|
||||
return this.texture.alpha;
|
||||
},
|
||||
set: /**
|
||||
* The alpha of the Sprite between 0 and 1, a value of 1 being fully opaque.
|
||||
*/
|
||||
function (value) {
|
||||
this.texture.alpha = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Sprite.prototype, "frame", {
|
||||
get: /**
|
||||
* Get the animation frame number.
|
||||
*/
|
||||
function () {
|
||||
return this.animations.frame;
|
||||
},
|
||||
set: /**
|
||||
* Set the animation frame by frame number.
|
||||
*/
|
||||
function (value) {
|
||||
this.animations.frame = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Sprite.prototype, "frameName", {
|
||||
get: /**
|
||||
* Get the animation frame name.
|
||||
*/
|
||||
function () {
|
||||
return this.animations.frameName;
|
||||
},
|
||||
set: /**
|
||||
* Set the animation frame by frame name.
|
||||
*/
|
||||
function (value) {
|
||||
this.animations.frameName = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Sprite.prototype, "width", {
|
||||
get: function () {
|
||||
return this.texture.width * this.transform.scale.x;
|
||||
},
|
||||
set: function (value) {
|
||||
this.transform.scale.x = value / this.texture.width;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Sprite.prototype, "height", {
|
||||
get: function () {
|
||||
return this.texture.height * this.transform.scale.y;
|
||||
},
|
||||
set: function (value) {
|
||||
this.transform.scale.y = value / this.texture.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Sprite.prototype.preUpdate = /**
|
||||
* Pre-update is called right before update() on each object in the game loop.
|
||||
*/
|
||||
function () {
|
||||
this.transform.update();
|
||||
if(this.transform.scrollFactor.x != 1 && this.transform.scrollFactor.x != 0) {
|
||||
this.worldView.x = (this.x * this.transform.scrollFactor.x) - (this.width * this.transform.origin.x);
|
||||
} else {
|
||||
this.worldView.x = this.x - (this.width * this.transform.origin.x);
|
||||
}
|
||||
if(this.transform.scrollFactor.y != 1 && this.transform.scrollFactor.y != 0) {
|
||||
this.worldView.y = (this.y * this.transform.scrollFactor.y) - (this.height * this.transform.origin.y);
|
||||
} else {
|
||||
this.worldView.y = this.y - (this.height * this.transform.origin.y);
|
||||
}
|
||||
this.worldView.width = this.width;
|
||||
this.worldView.height = this.height;
|
||||
if(this.modified == false && (!this.transform.scale.equals(1) || !this.transform.skew.equals(0) || this.transform.rotation != 0 || this.transform.rotationOffset != 0 || this.texture.flippedX || this.texture.flippedY)) {
|
||||
this.modified = true;
|
||||
}
|
||||
};
|
||||
Sprite.prototype.update = /**
|
||||
* Override this function to update your sprites position and appearance.
|
||||
*/
|
||||
function () {
|
||||
};
|
||||
Sprite.prototype.postUpdate = /**
|
||||
* Automatically called after update() by the game loop for all 'alive' objects.
|
||||
*/
|
||||
function () {
|
||||
this.animations.update();
|
||||
this.checkBounds();
|
||||
//this.transform.centerOn(this.body.aabb.pos.x, this.body.aabb.pos.y);
|
||||
if(this.modified == true && this.transform.scale.equals(1) && this.transform.skew.equals(0) && this.transform.rotation == 0 && this.transform.rotationOffset == 0 && this.texture.flippedX == false && this.texture.flippedY == false) {
|
||||
this.modified = false;
|
||||
}
|
||||
};
|
||||
Sprite.prototype.checkBounds = function () {
|
||||
if(Phaser.RectangleUtils.intersects(this.worldView, this.game.world.bounds)) {
|
||||
this.outOfBounds = false;
|
||||
} else {
|
||||
if(this.outOfBounds == false) {
|
||||
this.events.onOutOfBounds.dispatch(this);
|
||||
}
|
||||
this.outOfBounds = true;
|
||||
if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_KILL) {
|
||||
this.kill();
|
||||
} else if(this.outOfBoundsAction == Phaser.Types.OUT_OF_BOUNDS_DESTROY) {
|
||||
this.destroy();
|
||||
}
|
||||
}
|
||||
};
|
||||
Sprite.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
this.input.destroy();
|
||||
};
|
||||
Sprite.prototype.kill = /**
|
||||
* Handy for "killing" game objects.
|
||||
* Default behavior is to flag them as nonexistent AND dead.
|
||||
* However, if you want the "corpse" to remain in the game,
|
||||
* like to animate an effect or whatever, you should override this,
|
||||
* setting only alive to false, and leaving exists true.
|
||||
*/
|
||||
function (removeFromGroup) {
|
||||
if (typeof removeFromGroup === "undefined") { removeFromGroup = false; }
|
||||
this.alive = false;
|
||||
this.exists = false;
|
||||
if(removeFromGroup && this.group) {
|
||||
//this.group.remove(this);
|
||||
}
|
||||
this.events.onKilled.dispatch(this);
|
||||
};
|
||||
Sprite.prototype.revive = /**
|
||||
* Handy for bringing game objects "back to life". Just sets alive and exists back to true.
|
||||
* In practice, this is most often called by <code>Object.reset()</code>.
|
||||
*/
|
||||
function () {
|
||||
this.alive = true;
|
||||
this.exists = true;
|
||||
this.events.onRevived.dispatch(this);
|
||||
};
|
||||
return Sprite;
|
||||
})();
|
||||
Phaser.Sprite = Sprite;
|
||||
})(Phaser || (Phaser = {}));
|
251
TS Source/gameobjects/TransformManager.js
Normal file
251
TS Source/gameobjects/TransformManager.js
Normal file
|
@ -0,0 +1,251 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Components - TransformManager
|
||||
*/
|
||||
(function (Components) {
|
||||
var TransformManager = (function () {
|
||||
/**
|
||||
* Creates a new TransformManager component
|
||||
* @param parent The game object using this transform
|
||||
*/
|
||||
function TransformManager(parent) {
|
||||
this._dirty = false;
|
||||
/**
|
||||
* This value is added to the rotation of the object.
|
||||
* For example if you had a texture drawn facing straight up then you could set
|
||||
* rotationOffset to 90 and it would correspond correctly with Phasers right-handed coordinate system.
|
||||
* @type {number}
|
||||
*/
|
||||
this.rotationOffset = 0;
|
||||
/**
|
||||
* The rotation of the object in degrees. Phaser uses a right-handed coordinate system, where 0 points to the right.
|
||||
*/
|
||||
this.rotation = 0;
|
||||
this.game = parent.game;
|
||||
this.parent = parent;
|
||||
this.local = new Phaser.Mat3();
|
||||
this.scrollFactor = new Phaser.Vec2(1, 1);
|
||||
this.origin = new Phaser.Vec2();
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.skew = new Phaser.Vec2();
|
||||
this.center = new Phaser.Point();
|
||||
this.upperLeft = new Phaser.Point();
|
||||
this.upperRight = new Phaser.Point();
|
||||
this.bottomLeft = new Phaser.Point();
|
||||
this.bottomRight = new Phaser.Point();
|
||||
this._pos = new Phaser.Point();
|
||||
this._scale = new Phaser.Point();
|
||||
this._size = new Phaser.Point();
|
||||
this._halfSize = new Phaser.Point();
|
||||
this._offset = new Phaser.Point();
|
||||
this._origin = new Phaser.Point();
|
||||
this._sc = new Phaser.Point();
|
||||
this._scA = new Phaser.Point();
|
||||
}
|
||||
Object.defineProperty(TransformManager.prototype, "distance", {
|
||||
get: /**
|
||||
* The distance from the center of the transform to the rotation origin.
|
||||
*/
|
||||
function () {
|
||||
return this._distance;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "angleToCenter", {
|
||||
get: /**
|
||||
* The angle between the center of the transform to the rotation origin.
|
||||
*/
|
||||
function () {
|
||||
return this._angle;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "offsetX", {
|
||||
get: /**
|
||||
* The offset on the X axis of the origin That is the difference between the top left of the Sprite and the origin.x.
|
||||
* So if the origin.x is 0 the offsetX will be 0. If the origin.x is 0.5 then offsetX will be sprite width / 2, and so on.
|
||||
*/
|
||||
function () {
|
||||
return this._offset.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "offsetY", {
|
||||
get: /**
|
||||
* The offset on the Y axis of the origin
|
||||
*/
|
||||
function () {
|
||||
return this._offset.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "halfWidth", {
|
||||
get: /**
|
||||
* Half the width of the parent sprite, taking into consideration scaling
|
||||
*/
|
||||
function () {
|
||||
return this._halfSize.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "halfHeight", {
|
||||
get: /**
|
||||
* Half the height of the parent sprite, taking into consideration scaling
|
||||
*/
|
||||
function () {
|
||||
return this._halfSize.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "sin", {
|
||||
get: /**
|
||||
* The equivalent of Math.sin(rotation + rotationOffset)
|
||||
*/
|
||||
function () {
|
||||
return this._sc.x;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(TransformManager.prototype, "cos", {
|
||||
get: /**
|
||||
* The equivalent of Math.cos(rotation + rotationOffset)
|
||||
*/
|
||||
function () {
|
||||
return this._sc.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
TransformManager.prototype.centerOn = /**
|
||||
* Moves the sprite so its center is located on the given x and y coordinates.
|
||||
* Doesn't change the origin of the sprite.
|
||||
*/
|
||||
function (x, y) {
|
||||
this.parent.x = x + (this.parent.x - this.center.x);
|
||||
this.parent.y = y + (this.parent.y - this.center.y);
|
||||
//this.setCache();
|
||||
};
|
||||
TransformManager.prototype.setCache = /**
|
||||
* Populates the transform cache. Called by the parent object on creation.
|
||||
*/
|
||||
function () {
|
||||
this._pos.x = this.parent.x;
|
||||
this._pos.y = this.parent.y;
|
||||
this._halfSize.x = this.parent.width / 2;
|
||||
this._halfSize.y = this.parent.height / 2;
|
||||
this._offset.x = this.origin.x * this.parent.width;
|
||||
this._offset.y = this.origin.y * this.parent.height;
|
||||
this._angle = Math.atan2(this.halfHeight - this._offset.x, this.halfWidth - this._offset.y);
|
||||
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
|
||||
this._size.x = this.parent.width;
|
||||
this._size.y = this.parent.height;
|
||||
this._origin.x = this.origin.x;
|
||||
this._origin.y = this.origin.y;
|
||||
this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
this._prevRotation = this.rotation;
|
||||
if(this.parent.texture && this.parent.texture.renderRotation) {
|
||||
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
} else {
|
||||
this._sc.x = 0;
|
||||
this._sc.y = 1;
|
||||
}
|
||||
this.center.x = this.parent.x + this._distance * this._scA.y;
|
||||
this.center.y = this.parent.y + this._distance * this._scA.x;
|
||||
this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
this._pos.x = this.parent.x;
|
||||
this._pos.y = this.parent.y;
|
||||
this._flippedX = this.parent.texture.flippedX;
|
||||
this._flippedY = this.parent.texture.flippedY;
|
||||
};
|
||||
TransformManager.prototype.update = /**
|
||||
* Updates the local transform matrix and the cache values if anything has changed in the parent.
|
||||
*/
|
||||
function () {
|
||||
// Check cache
|
||||
this._dirty = false;
|
||||
// 1) Height or Width change (also triggered by a change in scale) or an Origin change
|
||||
if(this.parent.width !== this._size.x || this.parent.height !== this._size.y || this.origin.x !== this._origin.x || this.origin.y !== this._origin.y) {
|
||||
this._halfSize.x = this.parent.width / 2;
|
||||
this._halfSize.y = this.parent.height / 2;
|
||||
this._offset.x = this.origin.x * this.parent.width;
|
||||
this._offset.y = this.origin.y * this.parent.height;
|
||||
this._angle = Math.atan2(this.halfHeight - this._offset.y, this.halfWidth - this._offset.x);
|
||||
this._distance = Math.sqrt(((this._offset.x - this._halfSize.x) * (this._offset.x - this._halfSize.x)) + ((this._offset.y - this._halfSize.y) * (this._offset.y - this._halfSize.y)));
|
||||
// Store
|
||||
this._size.x = this.parent.width;
|
||||
this._size.y = this.parent.height;
|
||||
this._origin.x = this.origin.x;
|
||||
this._origin.y = this.origin.y;
|
||||
this._dirty = true;
|
||||
}
|
||||
// 2) Rotation change
|
||||
if(this.rotation != this._prevRotation || this._dirty) {
|
||||
this._scA.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
this._scA.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD + this._angle);
|
||||
if(this.parent.texture.renderRotation) {
|
||||
this._sc.x = Math.sin((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
this._sc.y = Math.cos((this.rotation + this.rotationOffset) * Phaser.GameMath.DEG_TO_RAD);
|
||||
} else {
|
||||
this._sc.x = 0;
|
||||
this._sc.y = 1;
|
||||
}
|
||||
// Store
|
||||
this._prevRotation = this.rotation;
|
||||
this._dirty = true;
|
||||
}
|
||||
// 3) If it has moved (or any of the above) then update the edges and center
|
||||
if(this._dirty || this.parent.x != this._pos.x || this.parent.y != this._pos.y) {
|
||||
this.center.x = this.parent.x + this._distance * this._scA.y;
|
||||
this.center.y = this.parent.y + this._distance * this._scA.x;
|
||||
this.upperLeft.setTo(this.center.x - this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.upperRight.setTo(this.center.x + this._halfSize.x * this._sc.y + this._halfSize.y * this._sc.x, this.center.y - this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
this.bottomLeft.setTo(this.center.x - this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y - this._halfSize.x * this._sc.x);
|
||||
this.bottomRight.setTo(this.center.x + this._halfSize.x * this._sc.y - this._halfSize.y * this._sc.x, this.center.y + this._halfSize.y * this._sc.y + this._halfSize.x * this._sc.x);
|
||||
this._pos.x = this.parent.x;
|
||||
this._pos.y = this.parent.y;
|
||||
// Translate
|
||||
this.local.data[2] = this.parent.x;
|
||||
this.local.data[5] = this.parent.y;
|
||||
}
|
||||
// Scale and Skew
|
||||
if(this._dirty || this._flippedX != this.parent.texture.flippedX) {
|
||||
this._flippedX = this.parent.texture.flippedX;
|
||||
if(this._flippedX) {
|
||||
this.local.data[0] = this._sc.y * -this.scale.x;
|
||||
this.local.data[3] = (this._sc.x * -this.scale.x) + this.skew.x;
|
||||
} else {
|
||||
this.local.data[0] = this._sc.y * this.scale.x;
|
||||
this.local.data[3] = (this._sc.x * this.scale.x) + this.skew.x;
|
||||
}
|
||||
}
|
||||
if(this._dirty || this._flippedY != this.parent.texture.flippedY) {
|
||||
this._flippedY = this.parent.texture.flippedY;
|
||||
if(this._flippedY) {
|
||||
this.local.data[4] = this._sc.y * -this.scale.y;
|
||||
this.local.data[1] = -(this._sc.x * -this.scale.y) + this.skew.y;
|
||||
} else {
|
||||
this.local.data[4] = this._sc.y * this.scale.y;
|
||||
this.local.data[1] = -(this._sc.x * this.scale.y) + this.skew.y;
|
||||
}
|
||||
}
|
||||
};
|
||||
return TransformManager;
|
||||
})();
|
||||
Components.TransformManager = TransformManager;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
285
TS Source/geom/Circle.js
Normal file
285
TS Source/geom/Circle.js
Normal file
|
@ -0,0 +1,285 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Circle
|
||||
*
|
||||
* A Circle object is an area defined by its position, as indicated by its center point (x,y) and diameter.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Circle = (function () {
|
||||
/**
|
||||
* Creates a new Circle object with the center coordinate specified by the x and y parameters and the diameter specified by the diameter parameter. If you call this function without parameters, a circle with x, y, diameter and radius properties set to 0 is created.
|
||||
* @class Circle
|
||||
* @constructor
|
||||
* @param {Number} [x] The x coordinate of the center of the circle.
|
||||
* @param {Number} [y] The y coordinate of the center of the circle.
|
||||
* @param {Number} [diameter] The diameter of the circle.
|
||||
* @return {Circle} This circle object
|
||||
**/
|
||||
function Circle(x, y, diameter) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof diameter === "undefined") { diameter = 0; }
|
||||
this._diameter = 0;
|
||||
this._radius = 0;
|
||||
/**
|
||||
* The x coordinate of the center of the circle
|
||||
* @property x
|
||||
* @type Number
|
||||
**/
|
||||
this.x = 0;
|
||||
/**
|
||||
* The y coordinate of the center of the circle
|
||||
* @property y
|
||||
* @type Number
|
||||
**/
|
||||
this.y = 0;
|
||||
this.setTo(x, y, diameter);
|
||||
}
|
||||
Object.defineProperty(Circle.prototype, "diameter", {
|
||||
get: /**
|
||||
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
||||
* @method diameter
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this._diameter;
|
||||
},
|
||||
set: /**
|
||||
* The diameter of the circle. The largest distance between any two points on the circle. The same as the radius * 2.
|
||||
* @method diameter
|
||||
* @param {Number} The diameter of the circle.
|
||||
**/
|
||||
function (value) {
|
||||
if(value > 0) {
|
||||
this._diameter = value;
|
||||
this._radius = value * 0.5;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Circle.prototype, "radius", {
|
||||
get: /**
|
||||
* The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
|
||||
* @method radius
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this._radius;
|
||||
},
|
||||
set: /**
|
||||
* The radius of the circle. The length of a line extending from the center of the circle to any point on the circle itself. The same as half the diameter.
|
||||
* @method radius
|
||||
* @param {Number} The radius of the circle.
|
||||
**/
|
||||
function (value) {
|
||||
if(value > 0) {
|
||||
this._radius = value;
|
||||
this._diameter = value * 2;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Circle.prototype.circumference = /**
|
||||
* The circumference of the circle.
|
||||
* @method circumference
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return 2 * (Math.PI * this._radius);
|
||||
};
|
||||
Object.defineProperty(Circle.prototype, "bottom", {
|
||||
get: /**
|
||||
* The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.y + this._radius;
|
||||
},
|
||||
set: /**
|
||||
* The sum of the y and radius properties. Changing the bottom property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @param {Number} The value to adjust the height of the circle by.
|
||||
**/
|
||||
function (value) {
|
||||
if(value < this.y) {
|
||||
this._radius = 0;
|
||||
this._diameter = 0;
|
||||
} else {
|
||||
this.radius = value - this.y;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Circle.prototype, "left", {
|
||||
get: /**
|
||||
* The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
|
||||
* @method left
|
||||
* @return {Number} The x coordinate of the leftmost point of the circle.
|
||||
**/
|
||||
function () {
|
||||
return this.x - this._radius;
|
||||
},
|
||||
set: /**
|
||||
* The x coordinate of the leftmost point of the circle. Changing the left property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
|
||||
* @method left
|
||||
* @param {Number} The value to adjust the position of the leftmost point of the circle by.
|
||||
**/
|
||||
function (value) {
|
||||
if(value > this.x) {
|
||||
this._radius = 0;
|
||||
this._diameter = 0;
|
||||
} else {
|
||||
this.radius = this.x - value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Circle.prototype, "right", {
|
||||
get: /**
|
||||
* The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
|
||||
* @method right
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.x + this._radius;
|
||||
},
|
||||
set: /**
|
||||
* The x coordinate of the rightmost point of the circle. Changing the right property of a Circle object has no effect on the x and y properties. However it does affect the diameter, whereas changing the x value does not affect the diameter property.
|
||||
* @method right
|
||||
* @param {Number} The amount to adjust the diameter of the circle by.
|
||||
**/
|
||||
function (value) {
|
||||
if(value < this.x) {
|
||||
this._radius = 0;
|
||||
this._diameter = 0;
|
||||
} else {
|
||||
this.radius = value - this.x;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Circle.prototype, "top", {
|
||||
get: /**
|
||||
* The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.y - this._radius;
|
||||
},
|
||||
set: /**
|
||||
* The sum of the y minus the radius property. Changing the top property of a Circle object has no effect on the x and y properties, but does change the diameter.
|
||||
* @method bottom
|
||||
* @param {Number} The amount to adjust the height of the circle by.
|
||||
**/
|
||||
function (value) {
|
||||
if(value > this.y) {
|
||||
this._radius = 0;
|
||||
this._diameter = 0;
|
||||
} else {
|
||||
this.radius = this.y - value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Circle.prototype, "area", {
|
||||
get: /**
|
||||
* Gets the area of this Circle.
|
||||
* @method area
|
||||
* @return {Number} This area of this circle.
|
||||
**/
|
||||
function () {
|
||||
if(this._radius > 0) {
|
||||
return Math.PI * this._radius * this._radius;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Circle.prototype.setTo = /**
|
||||
* Sets the members of Circle to the specified values.
|
||||
* @method setTo
|
||||
* @param {Number} x The x coordinate of the center of the circle.
|
||||
* @param {Number} y The y coordinate of the center of the circle.
|
||||
* @param {Number} diameter The diameter of the circle in pixels.
|
||||
* @return {Circle} This circle object
|
||||
**/
|
||||
function (x, y, diameter) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this._diameter = diameter;
|
||||
this._radius = diameter * 0.5;
|
||||
return this;
|
||||
};
|
||||
Circle.prototype.copyFrom = /**
|
||||
* Copies the x, y and diameter properties from any given object to this Circle.
|
||||
* @method copyFrom
|
||||
* @param {any} source - The object to copy from.
|
||||
* @return {Circle} This Circle object.
|
||||
**/
|
||||
function (source) {
|
||||
return this.setTo(source.x, source.y, source.diameter);
|
||||
};
|
||||
Object.defineProperty(Circle.prototype, "empty", {
|
||||
get: /**
|
||||
* Determines whether or not this Circle object is empty.
|
||||
* @method empty
|
||||
* @return {bool} A value of true if the Circle objects diameter is less than or equal to 0; otherwise false.
|
||||
**/
|
||||
function () {
|
||||
return (this._diameter == 0);
|
||||
},
|
||||
set: /**
|
||||
* Sets all of the Circle objects properties to 0. A Circle object is empty if its diameter is less than or equal to 0.
|
||||
* @method setEmpty
|
||||
* @return {Circle} This Circle object
|
||||
**/
|
||||
function (value) {
|
||||
this.setTo(0, 0, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Circle.prototype.offset = /**
|
||||
* Adjusts the location of the Circle object, as determined by its center coordinate, by the specified amounts.
|
||||
* @method offset
|
||||
* @param {Number} dx Moves the x value of the Circle object by this amount.
|
||||
* @param {Number} dy Moves the y value of the Circle object by this amount.
|
||||
* @return {Circle} This Circle object.
|
||||
**/
|
||||
function (dx, dy) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
return this;
|
||||
};
|
||||
Circle.prototype.offsetPoint = /**
|
||||
* Adjusts the location of the Circle object using a Point object as a parameter. This method is similar to the Circle.offset() method, except that it takes a Point object as a parameter.
|
||||
* @method offsetPoint
|
||||
* @param {Point} point A Point object to use to offset this Circle object.
|
||||
* @return {Circle} This Circle object.
|
||||
**/
|
||||
function (point) {
|
||||
return this.offset(point.x, point.y);
|
||||
};
|
||||
Circle.prototype.toString = /**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the instance.
|
||||
**/
|
||||
function () {
|
||||
return "[{Circle (x=" + this.x + " y=" + this.y + " diameter=" + this.diameter + " radius=" + this.radius + ")}]";
|
||||
};
|
||||
return Circle;
|
||||
})();
|
||||
Phaser.Circle = Circle;
|
||||
})(Phaser || (Phaser = {}));
|
279
TS Source/geom/Line.js
Normal file
279
TS Source/geom/Line.js
Normal file
|
@ -0,0 +1,279 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Line
|
||||
*
|
||||
* A Line object is an infinte line through space. The two sets of x/y coordinates define the Line Segment.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Line = (function () {
|
||||
/**
|
||||
*
|
||||
* @constructor
|
||||
* @param {Number} x1
|
||||
* @param {Number} y1
|
||||
* @param {Number} x2
|
||||
* @param {Number} y2
|
||||
* @return {Phaser.Line} This Object
|
||||
*/
|
||||
function Line(x1, y1, x2, y2) {
|
||||
if (typeof x1 === "undefined") { x1 = 0; }
|
||||
if (typeof y1 === "undefined") { y1 = 0; }
|
||||
if (typeof x2 === "undefined") { x2 = 0; }
|
||||
if (typeof y2 === "undefined") { y2 = 0; }
|
||||
/**
|
||||
*
|
||||
* @property x1
|
||||
* @type {Number}
|
||||
*/
|
||||
this.x1 = 0;
|
||||
/**
|
||||
*
|
||||
* @property y1
|
||||
* @type {Number}
|
||||
*/
|
||||
this.y1 = 0;
|
||||
/**
|
||||
*
|
||||
* @property x2
|
||||
* @type {Number}
|
||||
*/
|
||||
this.x2 = 0;
|
||||
/**
|
||||
*
|
||||
* @property y2
|
||||
* @type {Number}
|
||||
*/
|
||||
this.y2 = 0;
|
||||
this.setTo(x1, y1, x2, y2);
|
||||
}
|
||||
Line.prototype.clone = /**
|
||||
*
|
||||
* @method clone
|
||||
* @param {Phaser.Line} [output]
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
function (output) {
|
||||
if (typeof output === "undefined") { output = new Line(); }
|
||||
return output.setTo(this.x1, this.y1, this.x2, this.y2);
|
||||
};
|
||||
Line.prototype.copyFrom = /**
|
||||
*
|
||||
* @method copyFrom
|
||||
* @param {Phaser.Line} source
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
function (source) {
|
||||
return this.setTo(source.x1, source.y1, source.x2, source.y2);
|
||||
};
|
||||
Line.prototype.copyTo = /**
|
||||
*
|
||||
* @method copyTo
|
||||
* @param {Phaser.Line} target
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
function (target) {
|
||||
return target.copyFrom(this);
|
||||
};
|
||||
Line.prototype.setTo = /**
|
||||
*
|
||||
* @method setTo
|
||||
* @param {Number} x1
|
||||
* @param {Number} y1
|
||||
* @param {Number} x2
|
||||
* @param {Number} y2
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
function (x1, y1, x2, y2) {
|
||||
if (typeof x1 === "undefined") { x1 = 0; }
|
||||
if (typeof y1 === "undefined") { y1 = 0; }
|
||||
if (typeof x2 === "undefined") { x2 = 0; }
|
||||
if (typeof y2 === "undefined") { y2 = 0; }
|
||||
this.x1 = x1;
|
||||
this.y1 = y1;
|
||||
this.x2 = x2;
|
||||
this.y2 = y2;
|
||||
return this;
|
||||
};
|
||||
Object.defineProperty(Line.prototype, "width", {
|
||||
get: function () {
|
||||
return Math.max(this.x1, this.x2) - Math.min(this.x1, this.x2);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Line.prototype, "height", {
|
||||
get: function () {
|
||||
return Math.max(this.y1, this.y2) - Math.min(this.y1, this.y2);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Line.prototype, "length", {
|
||||
get: /**
|
||||
*
|
||||
* @method length
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return Math.sqrt((this.x2 - this.x1) * (this.x2 - this.x1) + (this.y2 - this.y1) * (this.y2 - this.y1));
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Line.prototype.getY = /**
|
||||
*
|
||||
* @method getY
|
||||
* @param {Number} x
|
||||
* @return {Number}
|
||||
*/
|
||||
function (x) {
|
||||
return this.slope * x + this.yIntercept;
|
||||
};
|
||||
Object.defineProperty(Line.prototype, "angle", {
|
||||
get: /**
|
||||
*
|
||||
* @method angle
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return Math.atan2(this.x2 - this.x1, this.y2 - this.y1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Line.prototype, "slope", {
|
||||
get: /**
|
||||
*
|
||||
* @method slope
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return (this.y2 - this.y1) / (this.x2 - this.x1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Line.prototype, "perpSlope", {
|
||||
get: /**
|
||||
*
|
||||
* @method perpSlope
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return -((this.x2 - this.x1) / (this.y2 - this.y1));
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Line.prototype, "yIntercept", {
|
||||
get: /**
|
||||
*
|
||||
* @method yIntercept
|
||||
* @return {Number}
|
||||
*/
|
||||
function () {
|
||||
return (this.y1 - this.slope * this.x1);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Line.prototype.isPointOnLine = /**
|
||||
*
|
||||
* @method isPointOnLine
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {bool}
|
||||
*/
|
||||
function (x, y) {
|
||||
if((x - this.x1) * (this.y2 - this.y1) === (this.x2 - this.x1) * (y - this.y1)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Line.prototype.isPointOnLineSegment = /**
|
||||
*
|
||||
* @method isPointOnLineSegment
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @return {bool}
|
||||
*/
|
||||
function (x, y) {
|
||||
var xMin = Math.min(this.x1, this.x2);
|
||||
var xMax = Math.max(this.x1, this.x2);
|
||||
var yMin = Math.min(this.y1, this.y2);
|
||||
var yMax = Math.max(this.y1, this.y2);
|
||||
if(this.isPointOnLine(x, y) && (x >= xMin && x <= xMax) && (y >= yMin && y <= yMax)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Line.prototype.intersectLineLine = /**
|
||||
*
|
||||
* @method intersectLineLine
|
||||
* @param {Any} line
|
||||
* @return {Any}
|
||||
*/
|
||||
function (line) {
|
||||
//return Phaser.intersectLineLine(this,line);
|
||||
};
|
||||
Line.prototype.toString = /**
|
||||
*
|
||||
* @method perp
|
||||
* @param {Number} x
|
||||
* @param {Number} y
|
||||
* @param {Phaser.Line} [output]
|
||||
* @return {Phaser.Line}
|
||||
*/
|
||||
/*
|
||||
public perp(x: number, y: number, output: Line): Line {
|
||||
|
||||
if (this.y1 === this.y2)
|
||||
{
|
||||
if (output)
|
||||
{
|
||||
output.setTo(x, y, x, this.y1);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Line(x, y, x, this.y1);
|
||||
}
|
||||
}
|
||||
|
||||
var yInt: number = (y - this.perpSlope * x);
|
||||
|
||||
var pt = this.intersectLineLine({ x1: x, y1: y, x2: 0, y2: yInt });
|
||||
|
||||
if (output)
|
||||
{
|
||||
output.setTo(x, y, pt.x, pt.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Line(x, y, pt.x, pt.y);
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
intersectLineCircle (circle:Circle)
|
||||
{
|
||||
var perp = this.perp()
|
||||
return Phaser.intersectLineCircle(this,circle);
|
||||
|
||||
}
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* @method toString
|
||||
* @return {String}
|
||||
*/
|
||||
function () {
|
||||
return "[{Line (x1=" + this.x1 + " y1=" + this.y1 + " x2=" + this.x2 + " y2=" + this.y2 + ")}]";
|
||||
};
|
||||
return Line;
|
||||
})();
|
||||
Phaser.Line = Line;
|
||||
})(Phaser || (Phaser = {}));
|
63
TS Source/geom/Point.js
Normal file
63
TS Source/geom/Point.js
Normal file
|
@ -0,0 +1,63 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Point
|
||||
*
|
||||
* The Point object represents a location in a two-dimensional coordinate system, where x represents the horizontal axis and y represents the vertical axis.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Point = (function () {
|
||||
/**
|
||||
* Creates a new Point. If you pass no parameters a Point is created set to (0,0).
|
||||
* @class Point
|
||||
* @constructor
|
||||
* @param {Number} x The horizontal position of this Point (default 0)
|
||||
* @param {Number} y The vertical position of this Point (default 0)
|
||||
**/
|
||||
function Point(x, y) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
Point.prototype.copyFrom = /**
|
||||
* Copies the x and y properties from any given object to this Point.
|
||||
* @method copyFrom
|
||||
* @param {any} source - The object to copy from.
|
||||
* @return {Point} This Point object.
|
||||
**/
|
||||
function (source) {
|
||||
return this.setTo(source.x, source.y);
|
||||
};
|
||||
Point.prototype.invert = /**
|
||||
* Inverts the x and y values of this Point
|
||||
* @method invert
|
||||
* @return {Point} This Point object.
|
||||
**/
|
||||
function () {
|
||||
return this.setTo(this.y, this.x);
|
||||
};
|
||||
Point.prototype.setTo = /**
|
||||
* Sets the x and y values of this MicroPoint object to the given coordinates.
|
||||
* @method setTo
|
||||
* @param {Number} x - The horizontal position of this point.
|
||||
* @param {Number} y - The vertical position of this point.
|
||||
* @return {MicroPoint} This MicroPoint object. Useful for chaining method calls.
|
||||
**/
|
||||
function (x, y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
return this;
|
||||
};
|
||||
Point.prototype.toString = /**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the instance.
|
||||
**/
|
||||
function () {
|
||||
return '[{Point (x=' + this.x + ' y=' + this.y + ')}]';
|
||||
};
|
||||
return Point;
|
||||
})();
|
||||
Phaser.Point = Point;
|
||||
})(Phaser || (Phaser = {}));
|
295
TS Source/geom/Rectangle.js
Normal file
295
TS Source/geom/Rectangle.js
Normal file
|
@ -0,0 +1,295 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Rectangle
|
||||
*
|
||||
* @desc A Rectangle object is an area defined by its position, as indicated by its top-left corner (x,y) and width and height.
|
||||
*
|
||||
* @version 1.6 - 24th May 2013
|
||||
* @author Richard Davey
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Rectangle = (function () {
|
||||
/**
|
||||
* Creates a new Rectangle object with the top-left corner specified by the x and y parameters and with the specified width and height parameters. If you call this function without parameters, a Rectangle with x, y, width, and height properties set to 0 is created.
|
||||
* @class Rectangle
|
||||
* @constructor
|
||||
* @param {Number} x The x coordinate of the top-left corner of the Rectangle.
|
||||
* @param {Number} y The y coordinate of the top-left corner of the Rectangle.
|
||||
* @param {Number} width The width of the Rectangle in pixels.
|
||||
* @param {Number} height The height of the Rectangle in pixels.
|
||||
* @return {Rectangle} This Rectangle object
|
||||
**/
|
||||
function Rectangle(x, y, width, height) {
|
||||
if (typeof x === "undefined") { x = 0; }
|
||||
if (typeof y === "undefined") { y = 0; }
|
||||
if (typeof width === "undefined") { width = 0; }
|
||||
if (typeof height === "undefined") { height = 0; }
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
}
|
||||
Object.defineProperty(Rectangle.prototype, "halfWidth", {
|
||||
get: /**
|
||||
* Half of the width of the Rectangle
|
||||
* @property halfWidth
|
||||
* @type Number
|
||||
**/
|
||||
function () {
|
||||
return Math.round(this.width / 2);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "halfHeight", {
|
||||
get: /**
|
||||
* Half of the height of the Rectangle
|
||||
* @property halfHeight
|
||||
* @type Number
|
||||
**/
|
||||
function () {
|
||||
return Math.round(this.height / 2);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "bottom", {
|
||||
get: /**
|
||||
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
||||
* @method bottom
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.y + this.height;
|
||||
},
|
||||
set: /**
|
||||
* The sum of the y and height properties. Changing the bottom property of a Rectangle object has no effect on the x, y and width properties, but does change the height property.
|
||||
* @method bottom
|
||||
* @param {Number} value
|
||||
**/
|
||||
function (value) {
|
||||
if(value <= this.y) {
|
||||
this.height = 0;
|
||||
} else {
|
||||
this.height = (this.y - value);
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "bottomRight", {
|
||||
set: /**
|
||||
* Sets the bottom-right corner of the Rectangle, determined by the values of the given Point object.
|
||||
* @method bottomRight
|
||||
* @param {Point} value
|
||||
**/
|
||||
function (value) {
|
||||
this.right = value.x;
|
||||
this.bottom = value.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "left", {
|
||||
get: /**
|
||||
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties. However it does affect the width property, whereas changing the x value does not affect the width property.
|
||||
* @method left
|
||||
* @ return {number}
|
||||
**/
|
||||
function () {
|
||||
return this.x;
|
||||
},
|
||||
set: /**
|
||||
* The x coordinate of the left of the Rectangle. Changing the left property of a Rectangle object has no effect on the y and height properties.
|
||||
* However it does affect the width, whereas changing the x value does not affect the width property.
|
||||
* @method left
|
||||
* @param {Number} value
|
||||
**/
|
||||
function (value) {
|
||||
if(value >= this.right) {
|
||||
this.width = 0;
|
||||
} else {
|
||||
this.width = this.right - value;
|
||||
}
|
||||
this.x = value;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "right", {
|
||||
get: /**
|
||||
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
||||
* However it does affect the width property.
|
||||
* @method right
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.x + this.width;
|
||||
},
|
||||
set: /**
|
||||
* The sum of the x and width properties. Changing the right property of a Rectangle object has no effect on the x, y and height properties.
|
||||
* However it does affect the width property.
|
||||
* @method right
|
||||
* @param {Number} value
|
||||
**/
|
||||
function (value) {
|
||||
if(value <= this.x) {
|
||||
this.width = 0;
|
||||
} else {
|
||||
this.width = this.x + value;
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "volume", {
|
||||
get: /**
|
||||
* The volume of the Rectangle derived from width * height
|
||||
* @method volume
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.width * this.height;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "perimeter", {
|
||||
get: /**
|
||||
* The perimeter size of the Rectangle. This is the sum of all 4 sides.
|
||||
* @method perimeter
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return (this.width * 2) + (this.height * 2);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "top", {
|
||||
get: /**
|
||||
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
|
||||
* However it does affect the height property, whereas changing the y value does not affect the height property.
|
||||
* @method top
|
||||
* @return {Number}
|
||||
**/
|
||||
function () {
|
||||
return this.y;
|
||||
},
|
||||
set: /**
|
||||
* The y coordinate of the top of the Rectangle. Changing the top property of a Rectangle object has no effect on the x and width properties.
|
||||
* However it does affect the height property, whereas changing the y value does not affect the height property.
|
||||
* @method top
|
||||
* @param {Number} value
|
||||
**/
|
||||
function (value) {
|
||||
if(value >= this.bottom) {
|
||||
this.height = 0;
|
||||
this.y = value;
|
||||
} else {
|
||||
this.height = (this.bottom - value);
|
||||
}
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "topLeft", {
|
||||
set: /**
|
||||
* The location of the Rectangles top-left corner, determined by the x and y coordinates of the Point.
|
||||
* @method topLeft
|
||||
* @param {Point} value
|
||||
**/
|
||||
function (value) {
|
||||
this.x = value.x;
|
||||
this.y = value.y;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Rectangle.prototype, "empty", {
|
||||
get: /**
|
||||
* Determines whether or not this Rectangle object is empty.
|
||||
* @method isEmpty
|
||||
* @return {bool} A value of true if the Rectangle objects width or height is less than or equal to 0; otherwise false.
|
||||
**/
|
||||
function () {
|
||||
return (!this.width || !this.height);
|
||||
},
|
||||
set: /**
|
||||
* Sets all of the Rectangle object's properties to 0. A Rectangle object is empty if its width or height is less than or equal to 0.
|
||||
* @method setEmpty
|
||||
* @return {Rectangle} This Rectangle object
|
||||
**/
|
||||
function (value) {
|
||||
this.setTo(0, 0, 0, 0);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Rectangle.prototype.offset = /**
|
||||
* Adjusts the location of the Rectangle object, as determined by its top-left corner, by the specified amounts.
|
||||
* @method offset
|
||||
* @param {Number} dx Moves the x value of the Rectangle object by this amount.
|
||||
* @param {Number} dy Moves the y value of the Rectangle object by this amount.
|
||||
* @return {Rectangle} This Rectangle object.
|
||||
**/
|
||||
function (dx, dy) {
|
||||
this.x += dx;
|
||||
this.y += dy;
|
||||
return this;
|
||||
};
|
||||
Rectangle.prototype.offsetPoint = /**
|
||||
* Adjusts the location of the Rectangle object using a Point object as a parameter. This method is similar to the Rectangle.offset() method, except that it takes a Point object as a parameter.
|
||||
* @method offsetPoint
|
||||
* @param {Point} point A Point object to use to offset this Rectangle object.
|
||||
* @return {Rectangle} This Rectangle object.
|
||||
**/
|
||||
function (point) {
|
||||
return this.offset(point.x, point.y);
|
||||
};
|
||||
Rectangle.prototype.setTo = /**
|
||||
* Sets the members of Rectangle to the specified values.
|
||||
* @method setTo
|
||||
* @param {Number} x The x coordinate of the top-left corner of the Rectangle.
|
||||
* @param {Number} y The y coordinate of the top-left corner of the Rectangle.
|
||||
* @param {Number} width The width of the Rectangle in pixels.
|
||||
* @param {Number} height The height of the Rectangle in pixels.
|
||||
* @return {Rectangle} This Rectangle object
|
||||
**/
|
||||
function (x, y, width, height) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
return this;
|
||||
};
|
||||
Rectangle.prototype.floor = /**
|
||||
* Runs Math.floor() on both the x and y values of this Rectangle.
|
||||
* @method floor
|
||||
**/
|
||||
function () {
|
||||
this.x = Math.floor(this.x);
|
||||
this.y = Math.floor(this.y);
|
||||
};
|
||||
Rectangle.prototype.copyFrom = /**
|
||||
* Copies the x, y, width and height properties from any given object to this Rectangle.
|
||||
* @method copyFrom
|
||||
* @param {any} source - The object to copy from.
|
||||
* @return {Rectangle} This Rectangle object.
|
||||
**/
|
||||
function (source) {
|
||||
return this.setTo(source.x, source.y, source.width, source.height);
|
||||
};
|
||||
Rectangle.prototype.toString = /**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {string} a string representation of the instance.
|
||||
**/
|
||||
function () {
|
||||
return "[{Rectangle (x=" + this.x + " y=" + this.y + " width=" + this.width + " height=" + this.height + " empty=" + this.empty + ")}]";
|
||||
};
|
||||
return Rectangle;
|
||||
})();
|
||||
Phaser.Rectangle = Rectangle;
|
||||
})(Phaser || (Phaser = {}));
|
574
TS Source/input/InputHandler.js
Normal file
574
TS Source/input/InputHandler.js
Normal file
|
@ -0,0 +1,574 @@
|
|||
var Phaser;
|
||||
(function (Phaser) {
|
||||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Components - InputHandler
|
||||
*
|
||||
* Input detection component
|
||||
*/
|
||||
(function (Components) {
|
||||
var InputHandler = (function () {
|
||||
/**
|
||||
* Sprite Input component constructor
|
||||
* @param parent The Sprite using this Input component
|
||||
*/
|
||||
function InputHandler(parent) {
|
||||
/**
|
||||
* The PriorityID controls which Sprite receives an Input event first if they should overlap.
|
||||
*/
|
||||
this.priorityID = 0;
|
||||
/**
|
||||
* The index of this Input component entry in the Game.Input manager.
|
||||
*/
|
||||
this.indexID = 0;
|
||||
this.isDragged = false;
|
||||
this.dragPixelPerfect = false;
|
||||
this.allowHorizontalDrag = true;
|
||||
this.allowVerticalDrag = true;
|
||||
this.bringToTop = false;
|
||||
this.snapOnDrag = false;
|
||||
this.snapOnRelease = false;
|
||||
this.snapX = 0;
|
||||
this.snapY = 0;
|
||||
/**
|
||||
* Is this sprite allowed to be dragged by the mouse? true = yes, false = no
|
||||
* @default false
|
||||
*/
|
||||
this.draggable = false;
|
||||
/**
|
||||
* A region of the game world within which the sprite is restricted during drag
|
||||
* @default null
|
||||
*/
|
||||
this.boundsRect = null;
|
||||
/**
|
||||
* An Sprite the bounds of which this sprite is restricted during drag
|
||||
* @default null
|
||||
*/
|
||||
this.boundsSprite = null;
|
||||
/**
|
||||
* If this object is set to consume the pointer event then it will stop all propogation from this object on.
|
||||
* For example if you had a stack of 6 sprites with the same priority IDs and one consumed the event, none of the others would receive it.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.consumePointerEvent = false;
|
||||
this.game = parent.game;
|
||||
this._parent = parent;
|
||||
this.enabled = false;
|
||||
}
|
||||
InputHandler.prototype.pointerX = /**
|
||||
* The x coordinate of the Input pointer, relative to the top-left of the parent Sprite.
|
||||
* This value is only set when the pointer is over this Sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].x;
|
||||
};
|
||||
InputHandler.prototype.pointerY = /**
|
||||
* The y coordinate of the Input pointer, relative to the top-left of the parent Sprite
|
||||
* This value is only set when the pointer is over this Sprite.
|
||||
* @type {number}
|
||||
*/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].y;
|
||||
};
|
||||
InputHandler.prototype.pointerDown = /**
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||
* @property isDown
|
||||
* @type {bool}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isDown;
|
||||
};
|
||||
InputHandler.prototype.pointerUp = /**
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||
* @property isUp
|
||||
* @type {bool}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isUp;
|
||||
};
|
||||
InputHandler.prototype.pointerTimeDown = /**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeDown;
|
||||
};
|
||||
InputHandler.prototype.pointerTimeUp = /**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeUp;
|
||||
};
|
||||
InputHandler.prototype.pointerOver = /**
|
||||
* Is the Pointer over this Sprite
|
||||
* @property isOver
|
||||
* @type {bool}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isOver;
|
||||
};
|
||||
InputHandler.prototype.pointerOut = /**
|
||||
* Is the Pointer outside of this Sprite
|
||||
* @property isOut
|
||||
* @type {bool}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isOut;
|
||||
};
|
||||
InputHandler.prototype.pointerTimeOver = /**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeOver;
|
||||
};
|
||||
InputHandler.prototype.pointerTimeOut = /**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].timeOut;
|
||||
};
|
||||
InputHandler.prototype.pointerDragged = /**
|
||||
* Is this sprite being dragged by the mouse or not?
|
||||
* @default false
|
||||
*/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
return this._pointerData[pointer].isDragged;
|
||||
};
|
||||
InputHandler.prototype.start = function (priority, checkBody, useHandCursor) {
|
||||
if (typeof priority === "undefined") { priority = 0; }
|
||||
if (typeof checkBody === "undefined") { checkBody = false; }
|
||||
if (typeof useHandCursor === "undefined") { useHandCursor = false; }
|
||||
// Turning on
|
||||
if(this.enabled == false) {
|
||||
// Register, etc
|
||||
this.checkBody = checkBody;
|
||||
this.useHandCursor = useHandCursor;
|
||||
this.priorityID = priority;
|
||||
this._pointerData = [];
|
||||
for(var i = 0; i < 10; i++) {
|
||||
this._pointerData.push({
|
||||
id: i,
|
||||
x: 0,
|
||||
y: 0,
|
||||
isDown: false,
|
||||
isUp: false,
|
||||
isOver: false,
|
||||
isOut: false,
|
||||
timeOver: 0,
|
||||
timeOut: 0,
|
||||
timeDown: 0,
|
||||
timeUp: 0,
|
||||
downDuration: 0,
|
||||
isDragged: false
|
||||
});
|
||||
}
|
||||
this.snapOffset = new Phaser.Point();
|
||||
this.enabled = true;
|
||||
this.game.input.addGameObject(this._parent);
|
||||
// Create the signals the Input component will emit
|
||||
if(this._parent.events.onInputOver == null) {
|
||||
this._parent.events.onInputOver = new Phaser.Signal();
|
||||
this._parent.events.onInputOut = new Phaser.Signal();
|
||||
this._parent.events.onInputDown = new Phaser.Signal();
|
||||
this._parent.events.onInputUp = new Phaser.Signal();
|
||||
this._parent.events.onDragStart = new Phaser.Signal();
|
||||
this._parent.events.onDragStop = new Phaser.Signal();
|
||||
}
|
||||
}
|
||||
return this._parent;
|
||||
};
|
||||
InputHandler.prototype.reset = function () {
|
||||
this.enabled = false;
|
||||
for(var i = 0; i < 10; i++) {
|
||||
this._pointerData[i] = {
|
||||
id: i,
|
||||
x: 0,
|
||||
y: 0,
|
||||
isDown: false,
|
||||
isUp: false,
|
||||
isOver: false,
|
||||
isOut: false,
|
||||
timeOver: 0,
|
||||
timeOut: 0,
|
||||
timeDown: 0,
|
||||
timeUp: 0,
|
||||
downDuration: 0,
|
||||
isDragged: false
|
||||
};
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.stop = function () {
|
||||
// Turning off
|
||||
if(this.enabled == false) {
|
||||
return;
|
||||
} else {
|
||||
// De-register, etc
|
||||
this.enabled = false;
|
||||
this.game.input.removeGameObject(this.indexID);
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.destroy = /**
|
||||
* Clean up memory.
|
||||
*/
|
||||
function () {
|
||||
if(this.enabled) {
|
||||
this.enabled = false;
|
||||
this.game.input.removeGameObject(this.indexID);
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.checkPointerOver = /**
|
||||
* Checks if the given pointer is over this Sprite. All checks are done in world coordinates.
|
||||
*/
|
||||
function (pointer) {
|
||||
if(this.enabled == false || this._parent.visible == false) {
|
||||
return false;
|
||||
} else {
|
||||
//return SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY);
|
||||
//return SpriteUtils.overlapsXY(this._parent, pointer.screenX, pointer.screenY);
|
||||
return Phaser.SpriteUtils.overlapsPointer(this._parent, pointer);
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.update = /**
|
||||
* Update
|
||||
*/
|
||||
function (pointer) {
|
||||
if(this.enabled == false || this._parent.visible == false) {
|
||||
this._pointerOutHandler(pointer);
|
||||
return false;
|
||||
}
|
||||
if(this.draggable && this._draggedPointerID == pointer.id) {
|
||||
return this.updateDrag(pointer);
|
||||
} else if(this._pointerData[pointer.id].isOver == true) {
|
||||
//if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
|
||||
if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
|
||||
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
|
||||
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
|
||||
return true;
|
||||
} else {
|
||||
this._pointerOutHandler(pointer);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
InputHandler.prototype._pointerOverHandler = function (pointer) {
|
||||
if(this._pointerData[pointer.id].isOver == false) {
|
||||
this._pointerData[pointer.id].isOver = true;
|
||||
this._pointerData[pointer.id].isOut = false;
|
||||
this._pointerData[pointer.id].timeOver = this.game.time.now;
|
||||
this._pointerData[pointer.id].x = pointer.x - this._parent.x;
|
||||
this._pointerData[pointer.id].y = pointer.y - this._parent.y;
|
||||
if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
|
||||
this.game.stage.canvas.style.cursor = "pointer";
|
||||
}
|
||||
this._parent.events.onInputOver.dispatch(this._parent, pointer);
|
||||
}
|
||||
};
|
||||
InputHandler.prototype._pointerOutHandler = function (pointer) {
|
||||
this._pointerData[pointer.id].isOver = false;
|
||||
this._pointerData[pointer.id].isOut = true;
|
||||
this._pointerData[pointer.id].timeOut = this.game.time.now;
|
||||
if(this.useHandCursor && this._pointerData[pointer.id].isDragged == false) {
|
||||
this.game.stage.canvas.style.cursor = "default";
|
||||
}
|
||||
this._parent.events.onInputOut.dispatch(this._parent, pointer);
|
||||
};
|
||||
InputHandler.prototype._touchedHandler = function (pointer) {
|
||||
if(this._pointerData[pointer.id].isDown == false && this._pointerData[pointer.id].isOver == true) {
|
||||
this._pointerData[pointer.id].isDown = true;
|
||||
this._pointerData[pointer.id].isUp = false;
|
||||
this._pointerData[pointer.id].timeDown = this.game.time.now;
|
||||
//console.log('touchedHandler: ' + Date.now());
|
||||
this._parent.events.onInputDown.dispatch(this._parent, pointer);
|
||||
// Start drag
|
||||
//if (this.draggable && this.isDragged == false && pointer.targetObject == null)
|
||||
if(this.draggable && this.isDragged == false) {
|
||||
this.startDrag(pointer);
|
||||
}
|
||||
if(this.bringToTop) {
|
||||
this._parent.bringToTop();
|
||||
//this._parent.game.world.group.bringToTop(this._parent);
|
||||
}
|
||||
}
|
||||
// Consume the event?
|
||||
return this.consumePointerEvent;
|
||||
};
|
||||
InputHandler.prototype._releasedHandler = function (pointer) {
|
||||
// If was previously touched by this Pointer, check if still is AND still over this item
|
||||
if(this._pointerData[pointer.id].isDown && pointer.isUp) {
|
||||
this._pointerData[pointer.id].isDown = false;
|
||||
this._pointerData[pointer.id].isUp = true;
|
||||
this._pointerData[pointer.id].timeUp = this.game.time.now;
|
||||
this._pointerData[pointer.id].downDuration = this._pointerData[pointer.id].timeUp - this._pointerData[pointer.id].timeDown;
|
||||
// Only release the InputUp signal if the pointer is still over this sprite
|
||||
//if (SpriteUtils.overlapsXY(this._parent, pointer.worldX, pointer.worldY))
|
||||
if(Phaser.SpriteUtils.overlapsPointer(this._parent, pointer)) {
|
||||
//console.log('releasedHandler: ' + Date.now());
|
||||
this._parent.events.onInputUp.dispatch(this._parent, pointer);
|
||||
} else {
|
||||
// Pointer outside the sprite? Reset the cursor
|
||||
if(this.useHandCursor) {
|
||||
this.game.stage.canvas.style.cursor = "default";
|
||||
}
|
||||
}
|
||||
// Stop drag
|
||||
if(this.draggable && this.isDragged && this._draggedPointerID == pointer.id) {
|
||||
this.stopDrag(pointer);
|
||||
}
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.updateDrag = /**
|
||||
* Updates the Pointer drag on this Sprite.
|
||||
*/
|
||||
function (pointer) {
|
||||
if(pointer.isUp) {
|
||||
this.stopDrag(pointer);
|
||||
return false;
|
||||
}
|
||||
if(this.allowHorizontalDrag) {
|
||||
this._parent.x = pointer.x + this._dragPoint.x + this.dragOffset.x;
|
||||
}
|
||||
if(this.allowVerticalDrag) {
|
||||
this._parent.y = pointer.y + this._dragPoint.y + this.dragOffset.y;
|
||||
}
|
||||
if(this.boundsRect) {
|
||||
this.checkBoundsRect();
|
||||
}
|
||||
if(this.boundsSprite) {
|
||||
this.checkBoundsSprite();
|
||||
}
|
||||
if(this.snapOnDrag) {
|
||||
this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
|
||||
this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
InputHandler.prototype.justOver = /**
|
||||
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just over.
|
||||
* @returns {bool}
|
||||
*/
|
||||
function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { delay = 500; }
|
||||
return (this._pointerData[pointer].isOver && this.overDuration(pointer) < delay);
|
||||
};
|
||||
InputHandler.prototype.justOut = /**
|
||||
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just out.
|
||||
* @returns {bool}
|
||||
*/
|
||||
function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { delay = 500; }
|
||||
return (this._pointerData[pointer].isOut && (this.game.time.now - this._pointerData[pointer].timeOut < delay));
|
||||
};
|
||||
InputHandler.prototype.justPressed = /**
|
||||
* Returns true if the pointer has entered the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just over.
|
||||
* @returns {bool}
|
||||
*/
|
||||
function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { delay = 500; }
|
||||
return (this._pointerData[pointer].isDown && this.downDuration(pointer) < delay);
|
||||
};
|
||||
InputHandler.prototype.justReleased = /**
|
||||
* Returns true if the pointer has left the Sprite within the specified delay time (defaults to 500ms, half a second)
|
||||
* @param delay The time below which the pointer is considered as just out.
|
||||
* @returns {bool}
|
||||
*/
|
||||
function (pointer, delay) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if (typeof delay === "undefined") { delay = 500; }
|
||||
return (this._pointerData[pointer].isUp && (this.game.time.now - this._pointerData[pointer].timeUp < delay));
|
||||
};
|
||||
InputHandler.prototype.overDuration = /**
|
||||
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
||||
* @returns {number} The number of milliseconds the pointer has been over the Sprite, or -1 if not over.
|
||||
*/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if(this._pointerData[pointer].isOver) {
|
||||
return this.game.time.now - this._pointerData[pointer].timeOver;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
InputHandler.prototype.downDuration = /**
|
||||
* If the pointer is currently over this Sprite this returns how long it has been there for in milliseconds.
|
||||
* @returns {number} The number of milliseconds the pointer has been pressed down on the Sprite, or -1 if not over.
|
||||
*/
|
||||
function (pointer) {
|
||||
if (typeof pointer === "undefined") { pointer = 0; }
|
||||
if(this._pointerData[pointer].isDown) {
|
||||
return this.game.time.now - this._pointerData[pointer].timeDown;
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
InputHandler.prototype.enableDrag = /**
|
||||
* Make this Sprite draggable by the mouse. You can also optionally set mouseStartDragCallback and mouseStopDragCallback
|
||||
*
|
||||
* @param lockCenter If false the Sprite will drag from where you click it minus the dragOffset. If true it will center itself to the tip of the mouse pointer.
|
||||
* @param bringToTop If true the Sprite will be bought to the top of the rendering list in its current Group.
|
||||
* @param pixelPerfect If true it will use a pixel perfect test to see if you clicked the Sprite. False uses the bounding box.
|
||||
* @param alphaThreshold If using pixel perfect collision this specifies the alpha level from 0 to 255 above which a collision is processed (default 255)
|
||||
* @param boundsRect If you want to restrict the drag of this sprite to a specific FlxRect, pass the FlxRect here, otherwise it's free to drag anywhere
|
||||
* @param boundsSprite If you want to restrict the drag of this sprite to within the bounding box of another sprite, pass it here
|
||||
*/
|
||||
function (lockCenter, bringToTop, pixelPerfect, alphaThreshold, boundsRect, boundsSprite) {
|
||||
if (typeof lockCenter === "undefined") { lockCenter = false; }
|
||||
if (typeof bringToTop === "undefined") { bringToTop = false; }
|
||||
if (typeof pixelPerfect === "undefined") { pixelPerfect = false; }
|
||||
if (typeof alphaThreshold === "undefined") { alphaThreshold = 255; }
|
||||
if (typeof boundsRect === "undefined") { boundsRect = null; }
|
||||
if (typeof boundsSprite === "undefined") { boundsSprite = null; }
|
||||
this._dragPoint = new Phaser.Point();
|
||||
this.draggable = true;
|
||||
this.bringToTop = bringToTop;
|
||||
this.dragOffset = new Phaser.Point();
|
||||
this.dragFromCenter = lockCenter;
|
||||
this.dragPixelPerfect = pixelPerfect;
|
||||
this.dragPixelPerfectAlpha = alphaThreshold;
|
||||
if(boundsRect) {
|
||||
this.boundsRect = boundsRect;
|
||||
}
|
||||
if(boundsSprite) {
|
||||
this.boundsSprite = boundsSprite;
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.disableDrag = /**
|
||||
* Stops this sprite from being able to be dragged. If it is currently the target of an active drag it will be stopped immediately. Also disables any set callbacks.
|
||||
*/
|
||||
function () {
|
||||
if(this._pointerData) {
|
||||
for(var i = 0; i < 10; i++) {
|
||||
this._pointerData[i].isDragged = false;
|
||||
}
|
||||
}
|
||||
this.draggable = false;
|
||||
this.isDragged = false;
|
||||
this._draggedPointerID = -1;
|
||||
};
|
||||
InputHandler.prototype.startDrag = /**
|
||||
* Called by Pointer when drag starts on this Sprite. Should not usually be called directly.
|
||||
*/
|
||||
function (pointer) {
|
||||
this.isDragged = true;
|
||||
this._draggedPointerID = pointer.id;
|
||||
this._pointerData[pointer.id].isDragged = true;
|
||||
if(this.dragFromCenter) {
|
||||
this._parent.transform.centerOn(pointer.worldX, pointer.worldY);
|
||||
this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
|
||||
} else {
|
||||
this._dragPoint.setTo(this._parent.x - pointer.x, this._parent.y - pointer.y);
|
||||
}
|
||||
this.updateDrag(pointer);
|
||||
if(this.bringToTop) {
|
||||
this._parent.bringToTop();
|
||||
}
|
||||
this._parent.events.onDragStart.dispatch(this._parent, pointer);
|
||||
};
|
||||
InputHandler.prototype.stopDrag = /**
|
||||
* Called by Pointer when drag is stopped on this Sprite. Should not usually be called directly.
|
||||
*/
|
||||
function (pointer) {
|
||||
this.isDragged = false;
|
||||
this._draggedPointerID = -1;
|
||||
this._pointerData[pointer.id].isDragged = false;
|
||||
if(this.snapOnRelease) {
|
||||
this._parent.x = Math.floor(this._parent.x / this.snapX) * this.snapX;
|
||||
this._parent.y = Math.floor(this._parent.y / this.snapY) * this.snapY;
|
||||
}
|
||||
this._parent.events.onDragStop.dispatch(this._parent, pointer);
|
||||
this._parent.events.onInputUp.dispatch(this._parent, pointer);
|
||||
};
|
||||
InputHandler.prototype.setDragLock = /**
|
||||
* Restricts this sprite to drag movement only on the given axis. Note: If both are set to false the sprite will never move!
|
||||
*
|
||||
* @param allowHorizontal To enable the sprite to be dragged horizontally set to true, otherwise false
|
||||
* @param allowVertical To enable the sprite to be dragged vertically set to true, otherwise false
|
||||
*/
|
||||
function (allowHorizontal, allowVertical) {
|
||||
if (typeof allowHorizontal === "undefined") { allowHorizontal = true; }
|
||||
if (typeof allowVertical === "undefined") { allowVertical = true; }
|
||||
this.allowHorizontalDrag = allowHorizontal;
|
||||
this.allowVerticalDrag = allowVertical;
|
||||
};
|
||||
InputHandler.prototype.enableSnap = /**
|
||||
* Make this Sprite snap to the given grid either during drag or when it's released.
|
||||
* For example 16x16 as the snapX and snapY would make the sprite snap to every 16 pixels.
|
||||
*
|
||||
* @param snapX The width of the grid cell in pixels
|
||||
* @param snapY The height of the grid cell in pixels
|
||||
* @param onDrag If true the sprite will snap to the grid while being dragged
|
||||
* @param onRelease If true the sprite will snap to the grid when released
|
||||
*/
|
||||
function (snapX, snapY, onDrag, onRelease) {
|
||||
if (typeof onDrag === "undefined") { onDrag = true; }
|
||||
if (typeof onRelease === "undefined") { onRelease = false; }
|
||||
this.snapOnDrag = onDrag;
|
||||
this.snapOnRelease = onRelease;
|
||||
this.snapX = snapX;
|
||||
this.snapY = snapY;
|
||||
};
|
||||
InputHandler.prototype.disableSnap = /**
|
||||
* Stops the sprite from snapping to a grid during drag or release.
|
||||
*/
|
||||
function () {
|
||||
this.snapOnDrag = false;
|
||||
this.snapOnRelease = false;
|
||||
};
|
||||
InputHandler.prototype.checkBoundsRect = /**
|
||||
* Bounds Rect check for the sprite drag
|
||||
*/
|
||||
function () {
|
||||
if(this._parent.x < this.boundsRect.left) {
|
||||
this._parent.x = this.boundsRect.x;
|
||||
} else if((this._parent.x + this._parent.width) > this.boundsRect.right) {
|
||||
this._parent.x = this.boundsRect.right - this._parent.width;
|
||||
}
|
||||
if(this._parent.y < this.boundsRect.top) {
|
||||
this._parent.y = this.boundsRect.top;
|
||||
} else if((this._parent.y + this._parent.height) > this.boundsRect.bottom) {
|
||||
this._parent.y = this.boundsRect.bottom - this._parent.height;
|
||||
}
|
||||
};
|
||||
InputHandler.prototype.checkBoundsSprite = /**
|
||||
* Parent Sprite Bounds check for the sprite drag
|
||||
*/
|
||||
function () {
|
||||
if(this._parent.x < this.boundsSprite.x) {
|
||||
this._parent.x = this.boundsSprite.x;
|
||||
} else if((this._parent.x + this._parent.width) > (this.boundsSprite.x + this.boundsSprite.width)) {
|
||||
this._parent.x = (this.boundsSprite.x + this.boundsSprite.width) - this._parent.width;
|
||||
}
|
||||
if(this._parent.y < this.boundsSprite.y) {
|
||||
this._parent.y = this.boundsSprite.y;
|
||||
} else if((this._parent.y + this._parent.height) > (this.boundsSprite.y + this.boundsSprite.height)) {
|
||||
this._parent.y = (this.boundsSprite.y + this.boundsSprite.height) - this._parent.height;
|
||||
}
|
||||
};
|
||||
return InputHandler;
|
||||
})();
|
||||
Components.InputHandler = InputHandler;
|
||||
})(Phaser.Components || (Phaser.Components = {}));
|
||||
var Components = Phaser.Components;
|
||||
})(Phaser || (Phaser = {}));
|
604
TS Source/input/InputManager.js
Normal file
604
TS Source/input/InputManager.js
Normal file
|
@ -0,0 +1,604 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - InputManager
|
||||
*
|
||||
* A game specific Input manager that looks after the mouse, keyboard and touch objects.
|
||||
* This is updated by the core game loop.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var InputManager = (function () {
|
||||
function InputManager(game) {
|
||||
/**
|
||||
* How often should the input pointers be checked for updates?
|
||||
* A value of 0 means every single frame (60fps), a value of 1 means every other frame (30fps) and so on.
|
||||
* @type {number}
|
||||
*/
|
||||
this.pollRate = 0;
|
||||
this._pollCounter = 0;
|
||||
/**
|
||||
* A vector object representing the previous position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this._oldPosition = null;
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
this._x = 0;
|
||||
/**
|
||||
* X coordinate of the most recent Pointer event
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
this._y = 0;
|
||||
/**
|
||||
* You can disable all Input by setting Input.disabled = true. While set all new input related events will be ignored.
|
||||
* If you need to disable just one type of input, for example mouse, use Input.mouse.disabled = true instead
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disabled = false;
|
||||
/**
|
||||
* Controls the expected behaviour when using a mouse and touch together on a multi-input device
|
||||
*/
|
||||
this.multiInputOverride = InputManager.MOUSE_TOUCH_COMBINE;
|
||||
/**
|
||||
* Phaser.Gestures handler
|
||||
* @type {Gestures}
|
||||
*/
|
||||
//public gestures: Gestures;
|
||||
/**
|
||||
* A vector object representing the current position of the Pointer.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.position = null;
|
||||
/**
|
||||
* A vector object representing the speed of the Pointer. Only really useful in single Pointer games,
|
||||
* otherwise see the Pointer objects directly.
|
||||
* @property vector
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.speed = null;
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Input.
|
||||
* Default size of 44px (Apples recommended "finger tip" size) but can be changed to anything
|
||||
* @property circle
|
||||
* @type {Circle}
|
||||
**/
|
||||
this.circle = null;
|
||||
/**
|
||||
* The scale by which all input coordinates are multiplied, calculated by the StageScaleMode.
|
||||
* In an un-scaled game the values will be x: 1 and y: 1.
|
||||
* @type {Vec2}
|
||||
*/
|
||||
this.scale = null;
|
||||
/**
|
||||
* The maximum number of Pointers allowed to be active at any one time.
|
||||
* For lots of games it's useful to set this to 1
|
||||
* @type {Number}
|
||||
*/
|
||||
this.maxPointers = 10;
|
||||
/**
|
||||
* The current number of active Pointers.
|
||||
* @type {Number}
|
||||
*/
|
||||
this.currentPointers = 0;
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down and then released to be considered a tap or click
|
||||
* @property tapRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.tapRate = 200;
|
||||
/**
|
||||
* The number of milliseconds between taps of the same Pointer for it to be considered a double tap / click
|
||||
* @property doubleTapRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.doubleTapRate = 300;
|
||||
/**
|
||||
* The number of milliseconds that the Pointer has to be pressed down for it to fire a onHold event
|
||||
* @property holdRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.holdRate = 2000;
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justPressed
|
||||
* @property justPressedRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.justPressedRate = 200;
|
||||
/**
|
||||
* The number of milliseconds below which the Pointer is considered justReleased
|
||||
* @property justReleasedRate
|
||||
* @type {Number}
|
||||
**/
|
||||
this.justReleasedRate = 200;
|
||||
/**
|
||||
* Sets if the Pointer objects should record a history of x/y coordinates they have passed through.
|
||||
* The history is cleared each time the Pointer is pressed down.
|
||||
* The history is updated at the rate specified in Input.pollRate
|
||||
* @property recordPointerHistory
|
||||
* @type {bool}
|
||||
**/
|
||||
this.recordPointerHistory = false;
|
||||
/**
|
||||
* The rate in milliseconds at which the Pointer objects should update their tracking history
|
||||
* @property recordRate
|
||||
* @type {Number}
|
||||
*/
|
||||
this.recordRate = 100;
|
||||
/**
|
||||
* The total number of entries that can be recorded into the Pointer objects tracking history.
|
||||
* If the Pointer is tracking one event every 100ms, then a trackLimit of 100 would store the last 10 seconds worth of history.
|
||||
* @property recordLimit
|
||||
* @type {Number}
|
||||
*/
|
||||
this.recordLimit = 100;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer3
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer3 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer4
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer4 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer5
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer5 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer6
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer6 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer7
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer7 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer8
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer8 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer9
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer9 = null;
|
||||
/**
|
||||
* A Pointer object
|
||||
* @property pointer10
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.pointer10 = null;
|
||||
/**
|
||||
* The most recently active Pointer object.
|
||||
* When you've limited max pointers to 1 this will accurately be either the first finger touched or mouse.
|
||||
* @property activePointer
|
||||
* @type {Pointer}
|
||||
**/
|
||||
this.activePointer = null;
|
||||
this.inputObjects = [];
|
||||
this.totalTrackedObjects = 0;
|
||||
this.game = game;
|
||||
this.mousePointer = new Phaser.Pointer(this.game, 0);
|
||||
this.pointer1 = new Phaser.Pointer(this.game, 1);
|
||||
this.pointer2 = new Phaser.Pointer(this.game, 2);
|
||||
this.mouse = new Phaser.Mouse(this.game);
|
||||
this.keyboard = new Phaser.Keyboard(this.game);
|
||||
this.touch = new Phaser.Touch(this.game);
|
||||
this.mspointer = new Phaser.MSPointer(this.game);
|
||||
//this.gestures = new Gestures(this.game);
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
this.scale = new Phaser.Vec2(1, 1);
|
||||
this.speed = new Phaser.Vec2();
|
||||
this.position = new Phaser.Vec2();
|
||||
this._oldPosition = new Phaser.Vec2();
|
||||
this.circle = new Phaser.Circle(0, 0, 44);
|
||||
this.activePointer = this.mousePointer;
|
||||
this.currentPointers = 0;
|
||||
this.hitCanvas = document.createElement('canvas');
|
||||
this.hitCanvas.width = 1;
|
||||
this.hitCanvas.height = 1;
|
||||
this.hitContext = this.hitCanvas.getContext('2d');
|
||||
}
|
||||
InputManager.MOUSE_OVERRIDES_TOUCH = 0;
|
||||
InputManager.TOUCH_OVERRIDES_MOUSE = 1;
|
||||
InputManager.MOUSE_TOUCH_COMBINE = 2;
|
||||
Object.defineProperty(InputManager.prototype, "camera", {
|
||||
get: /**
|
||||
* The camera being used for mouse and touch based pointers to calculate their world coordinates.
|
||||
* This is only ever the camera set by the most recently active Pointer.
|
||||
* If you need to know exactly which camera a specific Pointer is over then see Pointer.camera instead.
|
||||
* @property camera
|
||||
* @type {Camera}
|
||||
**/
|
||||
function () {
|
||||
return this.activePointer.camera;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(InputManager.prototype, "x", {
|
||||
get: /**
|
||||
* The X coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenX/clientX for source values.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
**/
|
||||
function () {
|
||||
return this._x;
|
||||
},
|
||||
set: function (value) {
|
||||
this._x = Math.floor(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(InputManager.prototype, "y", {
|
||||
get: /**
|
||||
* The Y coordinate of the most recently active pointer.
|
||||
* This value takes game scaling into account automatically. See Pointer.screenY/clientY for source values.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
**/
|
||||
function () {
|
||||
return this._y;
|
||||
},
|
||||
set: function (value) {
|
||||
this._y = Math.floor(value);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
InputManager.prototype.addPointer = /**
|
||||
* Add a new Pointer object to the Input Manager. By default Input creates 2 pointer objects for you. If you need more
|
||||
* use this to create a new one, up to a maximum of 10.
|
||||
* @method addPointer
|
||||
* @return {Pointer} A reference to the new Pointer object
|
||||
**/
|
||||
function () {
|
||||
var next = 0;
|
||||
for(var i = 10; i > 0; i--) {
|
||||
if(this['pointer' + i] === null) {
|
||||
next = i;
|
||||
}
|
||||
}
|
||||
if(next == 0) {
|
||||
throw new Error("You can only have 10 Pointer objects");
|
||||
return null;
|
||||
} else {
|
||||
this['pointer' + next] = new Phaser.Pointer(this.game, next);
|
||||
return this['pointer' + next];
|
||||
}
|
||||
};
|
||||
InputManager.prototype.boot = /**
|
||||
* Starts the Input Manager running
|
||||
* @method start
|
||||
**/
|
||||
function () {
|
||||
this.mouse.start();
|
||||
this.keyboard.start();
|
||||
this.touch.start();
|
||||
this.mspointer.start();
|
||||
//this.gestures.start();
|
||||
this.mousePointer.active = true;
|
||||
};
|
||||
InputManager.prototype.addGameObject = /**
|
||||
* Adds a new game object to be tracked by the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
|
||||
* @method addGameObject
|
||||
**/
|
||||
function (object) {
|
||||
// Find a spare slot
|
||||
for(var i = 0; i < this.inputObjects.length; i++) {
|
||||
if(this.inputObjects[i] == null) {
|
||||
this.inputObjects[i] = object;
|
||||
object.input.indexID = i;
|
||||
this.totalTrackedObjects++;
|
||||
return;
|
||||
}
|
||||
}
|
||||
// If we got this far we need to push a new entry into the array
|
||||
object.input.indexID = this.inputObjects.length;
|
||||
this.inputObjects.push(object);
|
||||
this.totalTrackedObjects++;
|
||||
};
|
||||
InputManager.prototype.removeGameObject = /**
|
||||
* Removes a game object from the Input Manager. Called by the Sprite.Input component, should not usually be called directly.
|
||||
* @method removeGameObject
|
||||
**/
|
||||
function (index) {
|
||||
if(this.inputObjects[index]) {
|
||||
this.inputObjects[index] = null;
|
||||
}
|
||||
};
|
||||
Object.defineProperty(InputManager.prototype, "pollLocked", {
|
||||
get: function () {
|
||||
return (this.pollRate > 0 && this._pollCounter < this.pollRate);
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
InputManager.prototype.update = /**
|
||||
* Updates the Input Manager. Called by the core Game loop.
|
||||
* @method update
|
||||
**/
|
||||
function () {
|
||||
if(this.pollRate > 0 && this._pollCounter < this.pollRate) {
|
||||
this._pollCounter++;
|
||||
return;
|
||||
}
|
||||
this.speed.x = this.position.x - this._oldPosition.x;
|
||||
this.speed.y = this.position.y - this._oldPosition.y;
|
||||
this._oldPosition.copyFrom(this.position);
|
||||
this.mousePointer.update();
|
||||
this.pointer1.update();
|
||||
this.pointer2.update();
|
||||
if(this.pointer3) {
|
||||
this.pointer3.update();
|
||||
}
|
||||
if(this.pointer4) {
|
||||
this.pointer4.update();
|
||||
}
|
||||
if(this.pointer5) {
|
||||
this.pointer5.update();
|
||||
}
|
||||
if(this.pointer6) {
|
||||
this.pointer6.update();
|
||||
}
|
||||
if(this.pointer7) {
|
||||
this.pointer7.update();
|
||||
}
|
||||
if(this.pointer8) {
|
||||
this.pointer8.update();
|
||||
}
|
||||
if(this.pointer9) {
|
||||
this.pointer9.update();
|
||||
}
|
||||
if(this.pointer10) {
|
||||
this.pointer10.update();
|
||||
}
|
||||
this._pollCounter = 0;
|
||||
};
|
||||
InputManager.prototype.reset = /**
|
||||
* Reset all of the Pointers and Input states
|
||||
* @method reset
|
||||
* @param hard {bool} A soft reset (hard = false) won't reset any signals that might be bound. A hard reset will.
|
||||
**/
|
||||
function (hard) {
|
||||
if (typeof hard === "undefined") { hard = false; }
|
||||
this.keyboard.reset();
|
||||
this.mousePointer.reset();
|
||||
for(var i = 1; i <= 10; i++) {
|
||||
if(this['pointer' + i]) {
|
||||
this['pointer' + i].reset();
|
||||
}
|
||||
}
|
||||
this.currentPointers = 0;
|
||||
this.game.stage.canvas.style.cursor = "default";
|
||||
if(hard == true) {
|
||||
this.onDown.dispose();
|
||||
this.onUp.dispose();
|
||||
this.onTap.dispose();
|
||||
this.onHold.dispose();
|
||||
this.onDown = new Phaser.Signal();
|
||||
this.onUp = new Phaser.Signal();
|
||||
this.onTap = new Phaser.Signal();
|
||||
this.onHold = new Phaser.Signal();
|
||||
for(var i = 0; i < this.totalTrackedObjects; i++) {
|
||||
if(this.inputObjects[i] && this.inputObjects[i].input) {
|
||||
this.inputObjects[i].input.reset();
|
||||
}
|
||||
}
|
||||
this.inputObjects.length = 0;
|
||||
this.totalTrackedObjects = 0;
|
||||
}
|
||||
this._pollCounter = 0;
|
||||
};
|
||||
InputManager.prototype.resetSpeed = function (x, y) {
|
||||
this._oldPosition.setTo(x, y);
|
||||
this.speed.setTo(0, 0);
|
||||
};
|
||||
Object.defineProperty(InputManager.prototype, "totalInactivePointers", {
|
||||
get: /**
|
||||
* Get the total number of inactive Pointers
|
||||
* @method totalInactivePointers
|
||||
* @return {Number} The number of Pointers currently inactive
|
||||
**/
|
||||
function () {
|
||||
return 10 - this.currentPointers;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(InputManager.prototype, "totalActivePointers", {
|
||||
get: /**
|
||||
* Recalculates the total number of active Pointers
|
||||
* @method totalActivePointers
|
||||
* @return {Number} The number of Pointers currently active
|
||||
**/
|
||||
function () {
|
||||
this.currentPointers = 0;
|
||||
for(var i = 1; i <= 10; i++) {
|
||||
if(this['pointer' + i] && this['pointer' + i].active) {
|
||||
this.currentPointers++;
|
||||
}
|
||||
}
|
||||
return this.currentPointers;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
InputManager.prototype.startPointer = /**
|
||||
* Find the first free Pointer object and start it, passing in the event data.
|
||||
* @method startPointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was started or null if no Pointer object is available
|
||||
**/
|
||||
function (event) {
|
||||
if(this.maxPointers < 10 && this.totalActivePointers == this.maxPointers) {
|
||||
return null;
|
||||
}
|
||||
// Unrolled for speed
|
||||
if(this.pointer1.active == false) {
|
||||
return this.pointer1.start(event);
|
||||
} else if(this.pointer2.active == false) {
|
||||
return this.pointer2.start(event);
|
||||
} else {
|
||||
for(var i = 3; i <= 10; i++) {
|
||||
if(this['pointer' + i] && this['pointer' + i].active == false) {
|
||||
return this['pointer' + i].start(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
InputManager.prototype.updatePointer = /**
|
||||
* Updates the matching Pointer object, passing in the event data.
|
||||
* @method updatePointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was updated or null if no Pointer object is available
|
||||
**/
|
||||
function (event) {
|
||||
// Unrolled for speed
|
||||
if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
|
||||
return this.pointer1.move(event);
|
||||
} else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
|
||||
return this.pointer2.move(event);
|
||||
} else {
|
||||
for(var i = 3; i <= 10; i++) {
|
||||
if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
|
||||
return this['pointer' + i].move(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
InputManager.prototype.stopPointer = /**
|
||||
* Stops the matching Pointer object, passing in the event data.
|
||||
* @method stopPointer
|
||||
* @param {Any} event The event data from the Touch event
|
||||
* @return {Pointer} The Pointer object that was stopped or null if no Pointer object is available
|
||||
**/
|
||||
function (event) {
|
||||
// Unrolled for speed
|
||||
if(this.pointer1.active && this.pointer1.identifier == event.identifier) {
|
||||
return this.pointer1.stop(event);
|
||||
} else if(this.pointer2.active && this.pointer2.identifier == event.identifier) {
|
||||
return this.pointer2.stop(event);
|
||||
} else {
|
||||
for(var i = 3; i <= 10; i++) {
|
||||
if(this['pointer' + i] && this['pointer' + i].active && this['pointer' + i].identifier == event.identifier) {
|
||||
return this['pointer' + i].stop(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
InputManager.prototype.getPointer = /**
|
||||
* Get the next Pointer object whos active property matches the given state
|
||||
* @method getPointer
|
||||
* @param {bool} state The state the Pointer should be in (false for inactive, true for active)
|
||||
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested state.
|
||||
**/
|
||||
function (state) {
|
||||
if (typeof state === "undefined") { state = false; }
|
||||
// Unrolled for speed
|
||||
if(this.pointer1.active == state) {
|
||||
return this.pointer1;
|
||||
} else if(this.pointer2.active == state) {
|
||||
return this.pointer2;
|
||||
} else {
|
||||
for(var i = 3; i <= 10; i++) {
|
||||
if(this['pointer' + i] && this['pointer' + i].active == state) {
|
||||
return this['pointer' + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
InputManager.prototype.getPointerFromIdentifier = /**
|
||||
* Get the Pointer object whos identified property matches the given identifier value
|
||||
* @method getPointerFromIdentifier
|
||||
* @param {Number} identifier The Pointer.identifier value to search for
|
||||
* @return {Pointer} A Pointer object or null if no Pointer object matches the requested identifier.
|
||||
**/
|
||||
function (identifier) {
|
||||
// Unrolled for speed
|
||||
if(this.pointer1.identifier == identifier) {
|
||||
return this.pointer1;
|
||||
} else if(this.pointer2.identifier == identifier) {
|
||||
return this.pointer2;
|
||||
} else {
|
||||
for(var i = 3; i <= 10; i++) {
|
||||
if(this['pointer' + i] && this['pointer' + i].identifier == identifier) {
|
||||
return this['pointer' + i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
Object.defineProperty(InputManager.prototype, "worldX", {
|
||||
get: function () {
|
||||
if(this.camera) {
|
||||
return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(InputManager.prototype, "worldY", {
|
||||
get: function () {
|
||||
if(this.camera) {
|
||||
return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
InputManager.prototype.getDistance = /**
|
||||
* Get the distance between two Pointer objects
|
||||
* @method getDistance
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
function (pointer1, pointer2) {
|
||||
return Phaser.Vec2Utils.distance(pointer1.position, pointer2.position);
|
||||
};
|
||||
InputManager.prototype.getAngle = /**
|
||||
* Get the angle between two Pointer objects
|
||||
* @method getAngle
|
||||
* @param {Pointer} pointer1
|
||||
* @param {Pointer} pointer2
|
||||
**/
|
||||
function (pointer1, pointer2) {
|
||||
return Phaser.Vec2Utils.angle(pointer1.position, pointer2.position);
|
||||
};
|
||||
InputManager.prototype.pixelPerfectCheck = function (sprite, pointer, alpha) {
|
||||
if (typeof alpha === "undefined") { alpha = 255; }
|
||||
this.hitContext.clearRect(0, 0, 1, 1);
|
||||
return true;
|
||||
};
|
||||
return InputManager;
|
||||
})();
|
||||
Phaser.InputManager = InputManager;
|
||||
})(Phaser || (Phaser = {}));
|
250
TS Source/input/Keyboard.js
Normal file
250
TS Source/input/Keyboard.js
Normal file
|
@ -0,0 +1,250 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Keyboard
|
||||
*
|
||||
* The Keyboard class handles keyboard interactions with the game and the resulting events.
|
||||
* The avoid stealing all browser input we don't use event.preventDefault. If you would like to trap a specific key however
|
||||
* then use the addKeyCapture() method.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Keyboard = (function () {
|
||||
function Keyboard(game) {
|
||||
this._keys = {
|
||||
};
|
||||
this._capture = {
|
||||
};
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.game = game;
|
||||
}
|
||||
Keyboard.prototype.start = function () {
|
||||
var _this = this;
|
||||
this._onKeyDown = function (event) {
|
||||
return _this.onKeyDown(event);
|
||||
};
|
||||
this._onKeyUp = function (event) {
|
||||
return _this.onKeyUp(event);
|
||||
};
|
||||
document.body.addEventListener('keydown', this._onKeyDown, false);
|
||||
document.body.addEventListener('keyup', this._onKeyUp, false);
|
||||
};
|
||||
Keyboard.prototype.stop = function () {
|
||||
document.body.removeEventListener('keydown', this._onKeyDown);
|
||||
document.body.removeEventListener('keyup', this._onKeyUp);
|
||||
};
|
||||
Keyboard.prototype.addKeyCapture = /**
|
||||
* By default when a key is pressed Phaser will not stop the event from propagating up to the browser.
|
||||
* There are some keys this can be annoying for, like the arrow keys or space bar, which make the browser window scroll.
|
||||
* You can use addKeyCapture to consume the keyboard event for specific keys so it doesn't bubble up to the the browser.
|
||||
* Pass in either a single keycode or an array of keycodes.
|
||||
* @param {Any} keycode
|
||||
*/
|
||||
function (keycode) {
|
||||
if(typeof keycode === 'object') {
|
||||
for(var i = 0; i < keycode.length; i++) {
|
||||
this._capture[keycode[i]] = true;
|
||||
}
|
||||
} else {
|
||||
this._capture[keycode] = true;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.removeKeyCapture = /**
|
||||
* @param {Number} keycode
|
||||
*/
|
||||
function (keycode) {
|
||||
delete this._capture[keycode];
|
||||
};
|
||||
Keyboard.prototype.clearCaptures = function () {
|
||||
this._capture = {
|
||||
};
|
||||
};
|
||||
Keyboard.prototype.onKeyDown = /**
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
if(this._capture[event.keyCode]) {
|
||||
event.preventDefault();
|
||||
}
|
||||
if(!this._keys[event.keyCode]) {
|
||||
this._keys[event.keyCode] = {
|
||||
isDown: true,
|
||||
timeDown: this.game.time.now,
|
||||
timeUp: 0
|
||||
};
|
||||
} else {
|
||||
this._keys[event.keyCode].isDown = true;
|
||||
this._keys[event.keyCode].timeDown = this.game.time.now;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.onKeyUp = /**
|
||||
* @param {KeyboardEvent} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
if(this._capture[event.keyCode]) {
|
||||
event.preventDefault();
|
||||
}
|
||||
if(!this._keys[event.keyCode]) {
|
||||
this._keys[event.keyCode] = {
|
||||
isDown: false,
|
||||
timeDown: 0,
|
||||
timeUp: this.game.time.now
|
||||
};
|
||||
} else {
|
||||
this._keys[event.keyCode].isDown = false;
|
||||
this._keys[event.keyCode].timeUp = this.game.time.now;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.reset = function () {
|
||||
for(var key in this._keys) {
|
||||
this._keys[key].isDown = false;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.justPressed = /**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
* @return {bool}
|
||||
*/
|
||||
function (keycode, duration) {
|
||||
if (typeof duration === "undefined") { duration = 250; }
|
||||
if(this._keys[keycode] && this._keys[keycode].isDown === true && (this.game.time.now - this._keys[keycode].timeDown < duration)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.justReleased = /**
|
||||
* @param {Number} keycode
|
||||
* @param {Number} [duration]
|
||||
* @return {bool}
|
||||
*/
|
||||
function (keycode, duration) {
|
||||
if (typeof duration === "undefined") { duration = 250; }
|
||||
if(this._keys[keycode] && this._keys[keycode].isDown === false && (this.game.time.now - this._keys[keycode].timeUp < duration)) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Keyboard.prototype.isDown = /**
|
||||
* @param {Number} keycode
|
||||
* @return {bool}
|
||||
*/
|
||||
function (keycode) {
|
||||
if(this._keys[keycode]) {
|
||||
return this._keys[keycode].isDown;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Keyboard.A = "A".charCodeAt(0);
|
||||
Keyboard.B = "B".charCodeAt(0);
|
||||
Keyboard.C = "C".charCodeAt(0);
|
||||
Keyboard.D = "D".charCodeAt(0);
|
||||
Keyboard.E = "E".charCodeAt(0);
|
||||
Keyboard.F = "F".charCodeAt(0);
|
||||
Keyboard.G = "G".charCodeAt(0);
|
||||
Keyboard.H = "H".charCodeAt(0);
|
||||
Keyboard.I = "I".charCodeAt(0);
|
||||
Keyboard.J = "J".charCodeAt(0);
|
||||
Keyboard.K = "K".charCodeAt(0);
|
||||
Keyboard.L = "L".charCodeAt(0);
|
||||
Keyboard.M = "M".charCodeAt(0);
|
||||
Keyboard.N = "N".charCodeAt(0);
|
||||
Keyboard.O = "O".charCodeAt(0);
|
||||
Keyboard.P = "P".charCodeAt(0);
|
||||
Keyboard.Q = "Q".charCodeAt(0);
|
||||
Keyboard.R = "R".charCodeAt(0);
|
||||
Keyboard.S = "S".charCodeAt(0);
|
||||
Keyboard.T = "T".charCodeAt(0);
|
||||
Keyboard.U = "U".charCodeAt(0);
|
||||
Keyboard.V = "V".charCodeAt(0);
|
||||
Keyboard.W = "W".charCodeAt(0);
|
||||
Keyboard.X = "X".charCodeAt(0);
|
||||
Keyboard.Y = "Y".charCodeAt(0);
|
||||
Keyboard.Z = "Z".charCodeAt(0);
|
||||
Keyboard.ZERO = "0".charCodeAt(0);
|
||||
Keyboard.ONE = "1".charCodeAt(0);
|
||||
Keyboard.TWO = "2".charCodeAt(0);
|
||||
Keyboard.THREE = "3".charCodeAt(0);
|
||||
Keyboard.FOUR = "4".charCodeAt(0);
|
||||
Keyboard.FIVE = "5".charCodeAt(0);
|
||||
Keyboard.SIX = "6".charCodeAt(0);
|
||||
Keyboard.SEVEN = "7".charCodeAt(0);
|
||||
Keyboard.EIGHT = "8".charCodeAt(0);
|
||||
Keyboard.NINE = "9".charCodeAt(0);
|
||||
Keyboard.NUMPAD_0 = 96;
|
||||
Keyboard.NUMPAD_1 = 97;
|
||||
Keyboard.NUMPAD_2 = 98;
|
||||
Keyboard.NUMPAD_3 = 99;
|
||||
Keyboard.NUMPAD_4 = 100;
|
||||
Keyboard.NUMPAD_5 = 101;
|
||||
Keyboard.NUMPAD_6 = 102;
|
||||
Keyboard.NUMPAD_7 = 103;
|
||||
Keyboard.NUMPAD_8 = 104;
|
||||
Keyboard.NUMPAD_9 = 105;
|
||||
Keyboard.NUMPAD_MULTIPLY = 106;
|
||||
Keyboard.NUMPAD_ADD = 107;
|
||||
Keyboard.NUMPAD_ENTER = 108;
|
||||
Keyboard.NUMPAD_SUBTRACT = 109;
|
||||
Keyboard.NUMPAD_DECIMAL = 110;
|
||||
Keyboard.NUMPAD_DIVIDE = 111;
|
||||
Keyboard.F1 = 112;
|
||||
Keyboard.F2 = 113;
|
||||
Keyboard.F3 = 114;
|
||||
Keyboard.F4 = 115;
|
||||
Keyboard.F5 = 116;
|
||||
Keyboard.F6 = 117;
|
||||
Keyboard.F7 = 118;
|
||||
Keyboard.F8 = 119;
|
||||
Keyboard.F9 = 120;
|
||||
Keyboard.F10 = 121;
|
||||
Keyboard.F11 = 122;
|
||||
Keyboard.F12 = 123;
|
||||
Keyboard.F13 = 124;
|
||||
Keyboard.F14 = 125;
|
||||
Keyboard.F15 = 126;
|
||||
Keyboard.COLON = 186;
|
||||
Keyboard.EQUALS = 187;
|
||||
Keyboard.UNDERSCORE = 189;
|
||||
Keyboard.QUESTION_MARK = 191;
|
||||
Keyboard.TILDE = 192;
|
||||
Keyboard.OPEN_BRACKET = 219;
|
||||
Keyboard.BACKWARD_SLASH = 220;
|
||||
Keyboard.CLOSED_BRACKET = 221;
|
||||
Keyboard.QUOTES = 222;
|
||||
Keyboard.BACKSPACE = 8;
|
||||
Keyboard.TAB = 9;
|
||||
Keyboard.CLEAR = 12;
|
||||
Keyboard.ENTER = 13;
|
||||
Keyboard.SHIFT = 16;
|
||||
Keyboard.CONTROL = 17;
|
||||
Keyboard.ALT = 18;
|
||||
Keyboard.CAPS_LOCK = 20;
|
||||
Keyboard.ESC = 27;
|
||||
Keyboard.SPACEBAR = 32;
|
||||
Keyboard.PAGE_UP = 33;
|
||||
Keyboard.PAGE_DOWN = 34;
|
||||
Keyboard.END = 35;
|
||||
Keyboard.HOME = 36;
|
||||
Keyboard.LEFT = 37;
|
||||
Keyboard.UP = 38;
|
||||
Keyboard.RIGHT = 39;
|
||||
Keyboard.DOWN = 40;
|
||||
Keyboard.INSERT = 45;
|
||||
Keyboard.DELETE = 46;
|
||||
Keyboard.HELP = 47;
|
||||
Keyboard.NUM_LOCK = 144;
|
||||
return Keyboard;
|
||||
})();
|
||||
Phaser.Keyboard = Keyboard;
|
||||
})(Phaser || (Phaser = {}));
|
99
TS Source/input/MSPointer.js
Normal file
99
TS Source/input/MSPointer.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - MSPointer
|
||||
*
|
||||
* The MSPointer class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* It will work only in Internet Explorer 10 and Windows Store or Windows Phone 8 apps using JavaScript.
|
||||
* http://msdn.microsoft.com/en-us/library/ie/hh673557(v=vs.85).aspx
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var MSPointer = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {MSPointer} This object.
|
||||
*/
|
||||
function MSPointer(game) {
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.game = game;
|
||||
}
|
||||
MSPointer.prototype.start = /**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
function () {
|
||||
var _this = this;
|
||||
if(this.game.device.mspointer == true) {
|
||||
this._onMSPointerDown = function (event) {
|
||||
return _this.onPointerDown(event);
|
||||
};
|
||||
this._onMSPointerMove = function (event) {
|
||||
return _this.onPointerMove(event);
|
||||
};
|
||||
this._onMSPointerUp = function (event) {
|
||||
return _this.onPointerUp(event);
|
||||
};
|
||||
this.game.stage.canvas.addEventListener('MSPointerDown', this._onMSPointerDown, false);
|
||||
this.game.stage.canvas.addEventListener('MSPointerMove', this._onMSPointerMove, false);
|
||||
this.game.stage.canvas.addEventListener('MSPointerUp', this._onMSPointerUp, false);
|
||||
}
|
||||
};
|
||||
MSPointer.prototype.onPointerDown = /**
|
||||
*
|
||||
* @method onPointerDown
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.identifier = event.pointerId;
|
||||
this.game.input.startPointer(event);
|
||||
};
|
||||
MSPointer.prototype.onPointerMove = /**
|
||||
*
|
||||
* @method onPointerMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.identifier = event.pointerId;
|
||||
this.game.input.updatePointer(event);
|
||||
};
|
||||
MSPointer.prototype.onPointerUp = /**
|
||||
*
|
||||
* @method onPointerUp
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
event.identifier = event.pointerId;
|
||||
this.game.input.stopPointer(event);
|
||||
};
|
||||
MSPointer.prototype.stop = /**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
function () {
|
||||
if(this.game.device.mspointer == true) {
|
||||
this.game.stage.canvas.removeEventListener('MSPointerDown', this._onMSPointerDown);
|
||||
this.game.stage.canvas.removeEventListener('MSPointerMove', this._onMSPointerMove);
|
||||
this.game.stage.canvas.removeEventListener('MSPointerUp', this._onMSPointerUp);
|
||||
}
|
||||
};
|
||||
return MSPointer;
|
||||
})();
|
||||
Phaser.MSPointer = MSPointer;
|
||||
})(Phaser || (Phaser = {}));
|
99
TS Source/input/Mouse.js
Normal file
99
TS Source/input/Mouse.js
Normal file
|
@ -0,0 +1,99 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Mouse
|
||||
*
|
||||
* The Mouse class handles mouse interactions with the game and the resulting events.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Mouse = (function () {
|
||||
function Mouse(game) {
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.mouseDownCallback = null;
|
||||
this.mouseMoveCallback = null;
|
||||
this.mouseUpCallback = null;
|
||||
this.game = game;
|
||||
this.callbackContext = this.game;
|
||||
}
|
||||
Mouse.LEFT_BUTTON = 0;
|
||||
Mouse.MIDDLE_BUTTON = 1;
|
||||
Mouse.RIGHT_BUTTON = 2;
|
||||
Mouse.prototype.start = /**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
function () {
|
||||
var _this = this;
|
||||
if(this.game.device.android && this.game.device.chrome == false) {
|
||||
// Android stock browser fires mouse events even if you preventDefault on the touchStart, so ...
|
||||
return;
|
||||
}
|
||||
this._onMouseDown = function (event) {
|
||||
return _this.onMouseDown(event);
|
||||
};
|
||||
this._onMouseMove = function (event) {
|
||||
return _this.onMouseMove(event);
|
||||
};
|
||||
this._onMouseUp = function (event) {
|
||||
return _this.onMouseUp(event);
|
||||
};
|
||||
this.game.stage.canvas.addEventListener('mousedown', this._onMouseDown, true);
|
||||
this.game.stage.canvas.addEventListener('mousemove', this._onMouseMove, true);
|
||||
this.game.stage.canvas.addEventListener('mouseup', this._onMouseUp, true);
|
||||
};
|
||||
Mouse.prototype.onMouseDown = /**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this.mouseDownCallback) {
|
||||
this.mouseDownCallback.call(this.callbackContext, event);
|
||||
}
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event['identifier'] = 0;
|
||||
this.game.input.mousePointer.start(event);
|
||||
};
|
||||
Mouse.prototype.onMouseMove = /**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this.mouseMoveCallback) {
|
||||
this.mouseMoveCallback.call(this.callbackContext, event);
|
||||
}
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event['identifier'] = 0;
|
||||
this.game.input.mousePointer.move(event);
|
||||
};
|
||||
Mouse.prototype.onMouseUp = /**
|
||||
* @param {MouseEvent} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this.mouseUpCallback) {
|
||||
this.mouseUpCallback.call(this.callbackContext, event);
|
||||
}
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event['identifier'] = 0;
|
||||
this.game.input.mousePointer.stop(event);
|
||||
};
|
||||
Mouse.prototype.stop = /**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
function () {
|
||||
this.game.stage.canvas.removeEventListener('mousedown', this._onMouseDown);
|
||||
this.game.stage.canvas.removeEventListener('mousemove', this._onMouseMove);
|
||||
this.game.stage.canvas.removeEventListener('mouseup', this._onMouseUp);
|
||||
};
|
||||
return Mouse;
|
||||
})();
|
||||
Phaser.Mouse = Mouse;
|
||||
})(Phaser || (Phaser = {}));
|
497
TS Source/input/Pointer.js
Normal file
497
TS Source/input/Pointer.js
Normal file
|
@ -0,0 +1,497 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Pointer
|
||||
*
|
||||
* A Pointer object is used by the Touch and MSPoint managers and represents a single finger on the touch screen.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Pointer = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Phaser.Game} game.
|
||||
* @return {Phaser.Pointer} This object.
|
||||
*/
|
||||
function Pointer(game, id) {
|
||||
/**
|
||||
* Local private variable to store the status of dispatching a hold event
|
||||
* @property _holdSent
|
||||
* @type {bool}
|
||||
* @private
|
||||
*/
|
||||
this._holdSent = false;
|
||||
/**
|
||||
* Local private variable storing the short-term history of pointer movements
|
||||
* @property _history
|
||||
* @type {Array}
|
||||
* @private
|
||||
*/
|
||||
this._history = [];
|
||||
/**
|
||||
* Local private variable storing the time at which the next history drop should occur
|
||||
* @property _lastDrop
|
||||
* @type {Number}
|
||||
* @private
|
||||
*/
|
||||
this._nextDrop = 0;
|
||||
// Monitor events outside of a state reset loop
|
||||
this._stateReset = false;
|
||||
/**
|
||||
* A Vector object containing the initial position when the Pointer was engaged with the screen.
|
||||
* @property positionDown
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.positionDown = null;
|
||||
/**
|
||||
* A Vector object containing the current position of the Pointer on the screen.
|
||||
* @property position
|
||||
* @type {Vec2}
|
||||
**/
|
||||
this.position = null;
|
||||
/**
|
||||
* A Circle object centered on the x/y screen coordinates of the Pointer.
|
||||
* Default size of 44px (Apple's recommended "finger tip" size)
|
||||
* @property circle
|
||||
* @type {Circle}
|
||||
**/
|
||||
this.circle = null;
|
||||
/**
|
||||
*
|
||||
* @property withinGame
|
||||
* @type {bool}
|
||||
*/
|
||||
this.withinGame = false;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientX
|
||||
* @type {Number}
|
||||
*/
|
||||
this.clientX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, excluding any scroll offset
|
||||
* @property clientY
|
||||
* @type {Number}
|
||||
*/
|
||||
this.clientY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageX
|
||||
* @type {Number}
|
||||
*/
|
||||
this.pageX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the viewport in pixels, including any scroll offset
|
||||
* @property pageY
|
||||
* @type {Number}
|
||||
*/
|
||||
this.pageY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the screen in pixels
|
||||
* @property screenX
|
||||
* @type {Number}
|
||||
*/
|
||||
this.screenX = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the screen in pixels
|
||||
* @property screenY
|
||||
* @type {Number}
|
||||
*/
|
||||
this.screenY = -1;
|
||||
/**
|
||||
* The horizontal coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property x
|
||||
* @type {Number}
|
||||
*/
|
||||
this.x = -1;
|
||||
/**
|
||||
* The vertical coordinate of point relative to the game element. This value is automatically scaled based on game size.
|
||||
* @property y
|
||||
* @type {Number}
|
||||
*/
|
||||
this.y = -1;
|
||||
/**
|
||||
* If the Pointer is a mouse this is true, otherwise false
|
||||
* @property isMouse
|
||||
* @type {bool}
|
||||
**/
|
||||
this.isMouse = false;
|
||||
/**
|
||||
* If the Pointer is touching the touchscreen, or the mouse button is held down, isDown is set to true
|
||||
* @property isDown
|
||||
* @type {bool}
|
||||
**/
|
||||
this.isDown = false;
|
||||
/**
|
||||
* If the Pointer is not touching the touchscreen, or the mouse button is up, isUp is set to true
|
||||
* @property isUp
|
||||
* @type {bool}
|
||||
**/
|
||||
this.isUp = true;
|
||||
/**
|
||||
* A timestamp representing when the Pointer first touched the touchscreen.
|
||||
* @property timeDown
|
||||
* @type {Number}
|
||||
**/
|
||||
this.timeDown = 0;
|
||||
/**
|
||||
* A timestamp representing when the Pointer left the touchscreen.
|
||||
* @property timeUp
|
||||
* @type {Number}
|
||||
**/
|
||||
this.timeUp = 0;
|
||||
/**
|
||||
* A timestamp representing when the Pointer was last tapped or clicked
|
||||
* @property previousTapTime
|
||||
* @type {Number}
|
||||
**/
|
||||
this.previousTapTime = 0;
|
||||
/**
|
||||
* The total number of times this Pointer has been touched to the touchscreen
|
||||
* @property totalTouches
|
||||
* @type {Number}
|
||||
**/
|
||||
this.totalTouches = 0;
|
||||
/**
|
||||
* The number of miliseconds since the last click
|
||||
* @property msSinceLastClick
|
||||
* @type {Number}
|
||||
**/
|
||||
this.msSinceLastClick = Number.MAX_VALUE;
|
||||
/**
|
||||
* The Game Object this Pointer is currently over / touching / dragging.
|
||||
* @property targetObject
|
||||
* @type {Any}
|
||||
**/
|
||||
this.targetObject = null;
|
||||
/**
|
||||
* The top-most Camera that this Pointer is over (if any, null if none).
|
||||
* If the Pointer is over several cameras that are stacked on-top of each other this is only ever set to the top-most rendered camera.
|
||||
* @property camera
|
||||
* @type {Phaser.Camera}
|
||||
**/
|
||||
this.camera = null;
|
||||
this.game = game;
|
||||
this.id = id;
|
||||
this.active = false;
|
||||
this.position = new Phaser.Vec2();
|
||||
this.positionDown = new Phaser.Vec2();
|
||||
this.circle = new Phaser.Circle(0, 0, 44);
|
||||
if(id == 0) {
|
||||
this.isMouse = true;
|
||||
}
|
||||
}
|
||||
Object.defineProperty(Pointer.prototype, "duration", {
|
||||
get: /**
|
||||
* How long the Pointer has been depressed on the touchscreen. If not currently down it returns -1.
|
||||
* @property duration
|
||||
* @type {Number}
|
||||
**/
|
||||
function () {
|
||||
if(this.isUp) {
|
||||
return -1;
|
||||
}
|
||||
return this.game.time.now - this.timeDown;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Pointer.prototype, "worldX", {
|
||||
get: /**
|
||||
* Gets the X value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
function () {
|
||||
if(this.camera) {
|
||||
return (this.camera.worldView.x - this.camera.screenView.x) + this.x;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Object.defineProperty(Pointer.prototype, "worldY", {
|
||||
get: /**
|
||||
* Gets the Y value of this Pointer in world coordinates based on the given camera.
|
||||
* @param {Camera} [camera]
|
||||
*/
|
||||
function () {
|
||||
if(this.camera) {
|
||||
return (this.camera.worldView.y - this.camera.screenView.y) + this.y;
|
||||
}
|
||||
return null;
|
||||
},
|
||||
enumerable: true,
|
||||
configurable: true
|
||||
});
|
||||
Pointer.prototype.start = /**
|
||||
* Called when the Pointer is pressed onto the touchscreen
|
||||
* @method start
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
this.identifier = event.identifier;
|
||||
this.target = event.target;
|
||||
if(event.button) {
|
||||
this.button = event.button;
|
||||
}
|
||||
// Fix to stop rogue browser plugins from blocking the visibility state event
|
||||
if(this.game.paused == true && this.game.stage.scale.incorrectOrientation == false) {
|
||||
this.game.stage.resumeGame();
|
||||
return this;
|
||||
}
|
||||
this._history.length = 0;
|
||||
this.active = true;
|
||||
this.withinGame = true;
|
||||
this.isDown = true;
|
||||
this.isUp = false;
|
||||
// Work out how long it has been since the last click
|
||||
this.msSinceLastClick = this.game.time.now - this.timeDown;
|
||||
this.timeDown = this.game.time.now;
|
||||
this._holdSent = false;
|
||||
// This sets the x/y and other local values
|
||||
this.move(event);
|
||||
// x and y are the old values here?
|
||||
this.positionDown.setTo(this.x, this.y);
|
||||
if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
//this.game.input.x = this.x * this.game.input.scale.x;
|
||||
//this.game.input.y = this.y * this.game.input.scale.y;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.position.setTo(this.x, this.y);
|
||||
this.game.input.onDown.dispatch(this);
|
||||
this.game.input.resetSpeed(this.x, this.y);
|
||||
}
|
||||
this._stateReset = false;
|
||||
this.totalTouches++;
|
||||
if(this.isMouse == false) {
|
||||
this.game.input.currentPointers++;
|
||||
}
|
||||
if(this.targetObject !== null) {
|
||||
this.targetObject.input._touchedHandler(this);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Pointer.prototype.update = function () {
|
||||
if(this.active) {
|
||||
if(this._holdSent == false && this.duration >= this.game.input.holdRate) {
|
||||
if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
this.game.input.onHold.dispatch(this);
|
||||
}
|
||||
this._holdSent = true;
|
||||
}
|
||||
// Update the droppings history
|
||||
if(this.game.input.recordPointerHistory && this.game.time.now >= this._nextDrop) {
|
||||
this._nextDrop = this.game.time.now + this.game.input.recordRate;
|
||||
this._history.push({
|
||||
x: this.position.x,
|
||||
y: this.position.y
|
||||
});
|
||||
if(this._history.length > this.game.input.recordLimit) {
|
||||
this._history.shift();
|
||||
}
|
||||
}
|
||||
// Check which camera they are over
|
||||
this.camera = this.game.world.cameras.getCameraUnderPoint(this.x, this.y);
|
||||
}
|
||||
};
|
||||
Pointer.prototype.move = /**
|
||||
* Called when the Pointer is moved on the touchscreen
|
||||
* @method move
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this.game.input.pollLocked) {
|
||||
return;
|
||||
}
|
||||
if(event.button) {
|
||||
this.button = event.button;
|
||||
}
|
||||
this.clientX = event.clientX;
|
||||
this.clientY = event.clientY;
|
||||
this.pageX = event.pageX;
|
||||
this.pageY = event.pageY;
|
||||
this.screenX = event.screenX;
|
||||
this.screenY = event.screenY;
|
||||
this.x = (this.pageX - this.game.stage.offset.x) * this.game.input.scale.x;
|
||||
this.y = (this.pageY - this.game.stage.offset.y) * this.game.input.scale.y;
|
||||
this.position.setTo(this.x, this.y);
|
||||
this.circle.x = this.x;
|
||||
this.circle.y = this.y;
|
||||
if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
this.game.input.activePointer = this;
|
||||
this.game.input.x = this.x;
|
||||
this.game.input.y = this.y;
|
||||
this.game.input.position.setTo(this.game.input.x, this.game.input.y);
|
||||
this.game.input.circle.x = this.game.input.x;
|
||||
this.game.input.circle.y = this.game.input.y;
|
||||
}
|
||||
// If the game is paused we don't process any target objects
|
||||
if(this.game.paused) {
|
||||
return this;
|
||||
}
|
||||
// Easy out if we're dragging something and it still exists
|
||||
if(this.targetObject !== null && this.targetObject.input && this.targetObject.input.isDragged == true) {
|
||||
if(this.targetObject.input.update(this) == false) {
|
||||
this.targetObject = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
// Work out which object is on the top
|
||||
this._highestRenderOrderID = -1;
|
||||
this._highestRenderObject = -1;
|
||||
this._highestInputPriorityID = -1;
|
||||
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
|
||||
if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.checkPointerOver(this)) {
|
||||
// If the object has a higher InputManager.PriorityID OR if the priority ID is the same as the current highest AND it has a higher renderOrderID, then set it to the top
|
||||
if(this.game.input.inputObjects[i].input.priorityID > this._highestInputPriorityID || (this.game.input.inputObjects[i].input.priorityID == this._highestInputPriorityID && this.game.input.inputObjects[i].renderOrderID > this._highestRenderOrderID)) {
|
||||
this._highestRenderOrderID = this.game.input.inputObjects[i].renderOrderID;
|
||||
this._highestRenderObject = i;
|
||||
this._highestInputPriorityID = this.game.input.inputObjects[i].input.priorityID;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(this._highestRenderObject == -1) {
|
||||
// The pointer isn't over anything, check if we've got a lingering previous target
|
||||
if(this.targetObject !== null) {
|
||||
this.targetObject.input._pointerOutHandler(this);
|
||||
this.targetObject = null;
|
||||
}
|
||||
} else {
|
||||
if(this.targetObject == null) {
|
||||
// And now set the new one
|
||||
this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
|
||||
this.targetObject.input._pointerOverHandler(this);
|
||||
} else {
|
||||
// We've got a target from the last update
|
||||
if(this.targetObject == this.game.input.inputObjects[this._highestRenderObject]) {
|
||||
// Same target as before, so update it
|
||||
if(this.targetObject.input.update(this) == false) {
|
||||
this.targetObject = null;
|
||||
}
|
||||
} else {
|
||||
// The target has changed, so tell the old one we've left it
|
||||
this.targetObject.input._pointerOutHandler(this);
|
||||
// And now set the new one
|
||||
this.targetObject = this.game.input.inputObjects[this._highestRenderObject];
|
||||
this.targetObject.input._pointerOverHandler(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
return this;
|
||||
};
|
||||
Pointer.prototype.leave = /**
|
||||
* Called when the Pointer leaves the target area
|
||||
* @method leave
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
this.withinGame = false;
|
||||
this.move(event);
|
||||
};
|
||||
Pointer.prototype.stop = /**
|
||||
* Called when the Pointer leaves the touchscreen
|
||||
* @method stop
|
||||
* @param {Any} event
|
||||
*/
|
||||
function (event) {
|
||||
if(this._stateReset) {
|
||||
event.preventDefault();
|
||||
return;
|
||||
}
|
||||
this.timeUp = this.game.time.now;
|
||||
if(this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_OVERRIDES_TOUCH || this.game.input.multiInputOverride == Phaser.InputManager.MOUSE_TOUCH_COMBINE || (this.game.input.multiInputOverride == Phaser.InputManager.TOUCH_OVERRIDES_MOUSE && this.game.input.currentPointers == 0)) {
|
||||
this.game.input.onUp.dispatch(this);
|
||||
// Was it a tap?
|
||||
if(this.duration >= 0 && this.duration <= this.game.input.tapRate) {
|
||||
// Was it a double-tap?
|
||||
if(this.timeUp - this.previousTapTime < this.game.input.doubleTapRate) {
|
||||
// Yes, let's dispatch the signal then with the 2nd parameter set to true
|
||||
this.game.input.onTap.dispatch(this, true);
|
||||
} else {
|
||||
// Wasn't a double-tap, so dispatch a single tap signal
|
||||
this.game.input.onTap.dispatch(this, false);
|
||||
}
|
||||
this.previousTapTime = this.timeUp;
|
||||
}
|
||||
}
|
||||
// Mouse is always active
|
||||
if(this.id > 0) {
|
||||
this.active = false;
|
||||
}
|
||||
this.withinGame = false;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
if(this.isMouse == false) {
|
||||
this.game.input.currentPointers--;
|
||||
}
|
||||
for(var i = 0; i < this.game.input.totalTrackedObjects; i++) {
|
||||
if(this.game.input.inputObjects[i] && this.game.input.inputObjects[i].input && this.game.input.inputObjects[i].input.enabled) {
|
||||
this.game.input.inputObjects[i].input._releasedHandler(this);
|
||||
}
|
||||
}
|
||||
if(this.targetObject) {
|
||||
this.targetObject.input._releasedHandler(this);
|
||||
}
|
||||
this.targetObject = null;
|
||||
return this;
|
||||
};
|
||||
Pointer.prototype.justPressed = /**
|
||||
* The Pointer is considered justPressed if the time it was pressed onto the touchscreen or clicked is less than justPressedRate
|
||||
* @method justPressed
|
||||
* @param {Number} [duration].
|
||||
* @return {bool}
|
||||
*/
|
||||
function (duration) {
|
||||
if (typeof duration === "undefined") { duration = this.game.input.justPressedRate; }
|
||||
if(this.isDown === true && (this.timeDown + duration) > this.game.time.now) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Pointer.prototype.justReleased = /**
|
||||
* The Pointer is considered justReleased if the time it left the touchscreen is less than justReleasedRate
|
||||
* @method justReleased
|
||||
* @param {Number} [duration].
|
||||
* @return {bool}
|
||||
*/
|
||||
function (duration) {
|
||||
if (typeof duration === "undefined") { duration = this.game.input.justReleasedRate; }
|
||||
if(this.isUp === true && (this.timeUp + duration) > this.game.time.now) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
Pointer.prototype.reset = /**
|
||||
* Resets the Pointer properties. Called by InputManager.reset when you perform a State change.
|
||||
* @method reset
|
||||
*/
|
||||
function () {
|
||||
if(this.isMouse == false) {
|
||||
this.active = false;
|
||||
}
|
||||
this.identifier = null;
|
||||
this.isDown = false;
|
||||
this.isUp = true;
|
||||
this.totalTouches = 0;
|
||||
this._holdSent = false;
|
||||
this._history.length = 0;
|
||||
this._stateReset = true;
|
||||
if(this.targetObject && this.targetObject.input) {
|
||||
this.targetObject.input._releasedHandler(this);
|
||||
}
|
||||
this.targetObject = null;
|
||||
};
|
||||
Pointer.prototype.toString = /**
|
||||
* Returns a string representation of this object.
|
||||
* @method toString
|
||||
* @return {String} a string representation of the instance.
|
||||
**/
|
||||
function () {
|
||||
return "[{Pointer (id=" + this.id + " identifer=" + this.identifier + " active=" + this.active + " duration=" + this.duration + " withinGame=" + this.withinGame + " x=" + this.x + " y=" + this.y + " clientX=" + this.clientX + " clientY=" + this.clientY + " screenX=" + this.screenX + " screenY=" + this.screenY + " pageX=" + this.pageX + " pageY=" + this.pageY + ")}]";
|
||||
};
|
||||
return Pointer;
|
||||
})();
|
||||
Phaser.Pointer = Pointer;
|
||||
})(Phaser || (Phaser = {}));
|
201
TS Source/input/Touch.js
Normal file
201
TS Source/input/Touch.js
Normal file
|
@ -0,0 +1,201 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - Touch
|
||||
*
|
||||
* The Touch class handles touch interactions with the game and the resulting Pointer objects.
|
||||
* http://www.w3.org/TR/touch-events/
|
||||
* https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
* http://www.html5rocks.com/en/mobile/touchandmouse/
|
||||
* Note: Android 2.x only supports 1 touch event at once, no multi-touch
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var Touch = (function () {
|
||||
/**
|
||||
* Constructor
|
||||
* @param {Game} game.
|
||||
* @return {Touch} This object.
|
||||
*/
|
||||
function Touch(game) {
|
||||
/**
|
||||
* You can disable all Input by setting disabled = true. While set all new input related events will be ignored.
|
||||
* @type {bool}
|
||||
*/
|
||||
this.disabled = false;
|
||||
this.touchStartCallback = null;
|
||||
this.touchMoveCallback = null;
|
||||
this.touchEndCallback = null;
|
||||
this.touchEnterCallback = null;
|
||||
this.touchLeaveCallback = null;
|
||||
this.touchCancelCallback = null;
|
||||
this.game = game;
|
||||
this.callbackContext = this.game;
|
||||
}
|
||||
Touch.prototype.start = /**
|
||||
* Starts the event listeners running
|
||||
* @method start
|
||||
*/
|
||||
function () {
|
||||
var _this = this;
|
||||
if(this.game.device.touch) {
|
||||
this._onTouchStart = function (event) {
|
||||
return _this.onTouchStart(event);
|
||||
};
|
||||
this._onTouchMove = function (event) {
|
||||
return _this.onTouchMove(event);
|
||||
};
|
||||
this._onTouchEnd = function (event) {
|
||||
return _this.onTouchEnd(event);
|
||||
};
|
||||
this._onTouchEnter = function (event) {
|
||||
return _this.onTouchEnter(event);
|
||||
};
|
||||
this._onTouchLeave = function (event) {
|
||||
return _this.onTouchLeave(event);
|
||||
};
|
||||
this._onTouchCancel = function (event) {
|
||||
return _this.onTouchCancel(event);
|
||||
};
|
||||
this._documentTouchMove = function (event) {
|
||||
return _this.consumeTouchMove(event);
|
||||
};
|
||||
this.game.stage.canvas.addEventListener('touchstart', this._onTouchStart, false);
|
||||
this.game.stage.canvas.addEventListener('touchmove', this._onTouchMove, false);
|
||||
this.game.stage.canvas.addEventListener('touchend', this._onTouchEnd, false);
|
||||
this.game.stage.canvas.addEventListener('touchenter', this._onTouchEnter, false);
|
||||
this.game.stage.canvas.addEventListener('touchleave', this._onTouchLeave, false);
|
||||
this.game.stage.canvas.addEventListener('touchcancel', this._onTouchCancel, false);
|
||||
document.addEventListener('touchmove', this._documentTouchMove, false);
|
||||
}
|
||||
};
|
||||
Touch.prototype.consumeTouchMove = /**
|
||||
* Prevent iOS bounce-back (doesn't work?)
|
||||
* @method consumeTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
event.preventDefault();
|
||||
};
|
||||
Touch.prototype.onTouchStart = /**
|
||||
*
|
||||
* @method onTouchStart
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.touchStartCallback) {
|
||||
this.touchStartCallback.call(this.callbackContext, event);
|
||||
}
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
// event.targetTouches = list of all touches on the TARGET ELEMENT (i.e. game dom element)
|
||||
// event.touches = list of all touches on the ENTIRE DOCUMENT, not just the target element
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.startPointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchCancel = /**
|
||||
* Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||
* Occurs for example on iOS when you put down 4 fingers and the app selector UI appears
|
||||
* @method onTouchCancel
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.touchCancelCallback) {
|
||||
this.touchCancelCallback.call(this.callbackContext, event);
|
||||
}
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
// Touch cancel - touches that were disrupted (perhaps by moving into a plugin or browser chrome)
|
||||
// http://www.w3.org/TR/touch-events/#dfn-touchcancel
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.stopPointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchEnter = /**
|
||||
* For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchEnter
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.touchEnterCallback) {
|
||||
this.touchEnterCallback.call(this.callbackContext, event);
|
||||
}
|
||||
if(this.game.input.disabled || this.disabled) {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
//console.log('touch enter');
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchLeave = /**
|
||||
* For touch enter and leave its a list of the touch points that have entered or left the target
|
||||
* Doesn't appear to be supported by most browsers yet
|
||||
* @method onTouchLeave
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.touchLeaveCallback) {
|
||||
this.touchLeaveCallback.call(this.callbackContext, event);
|
||||
}
|
||||
event.preventDefault();
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
//console.log('touch leave');
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchMove = /**
|
||||
*
|
||||
* @method onTouchMove
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.touchMoveCallback) {
|
||||
this.touchMoveCallback.call(this.callbackContext, event);
|
||||
}
|
||||
event.preventDefault();
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.updatePointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
Touch.prototype.onTouchEnd = /**
|
||||
*
|
||||
* @method onTouchEnd
|
||||
* @param {Any} event
|
||||
**/
|
||||
function (event) {
|
||||
if(this.touchEndCallback) {
|
||||
this.touchEndCallback.call(this.callbackContext, event);
|
||||
}
|
||||
event.preventDefault();
|
||||
// For touch end its a list of the touch points that have been removed from the surface
|
||||
// https://developer.mozilla.org/en-US/docs/DOM/TouchList
|
||||
// event.changedTouches = the touches that CHANGED in this event, not the total number of them
|
||||
for(var i = 0; i < event.changedTouches.length; i++) {
|
||||
this.game.input.stopPointer(event.changedTouches[i]);
|
||||
}
|
||||
};
|
||||
Touch.prototype.stop = /**
|
||||
* Stop the event listeners
|
||||
* @method stop
|
||||
*/
|
||||
function () {
|
||||
if(this.game.device.touch) {
|
||||
this.game.stage.canvas.removeEventListener('touchstart', this._onTouchStart);
|
||||
this.game.stage.canvas.removeEventListener('touchmove', this._onTouchMove);
|
||||
this.game.stage.canvas.removeEventListener('touchend', this._onTouchEnd);
|
||||
this.game.stage.canvas.removeEventListener('touchenter', this._onTouchEnter);
|
||||
this.game.stage.canvas.removeEventListener('touchleave', this._onTouchLeave);
|
||||
this.game.stage.canvas.removeEventListener('touchcancel', this._onTouchCancel);
|
||||
document.removeEventListener('touchmove', this._documentTouchMove);
|
||||
}
|
||||
};
|
||||
return Touch;
|
||||
})();
|
||||
Phaser.Touch = Touch;
|
||||
})(Phaser || (Phaser = {}));
|
96
TS Source/loader/AnimationLoader.js
Normal file
96
TS Source/loader/AnimationLoader.js
Normal file
|
@ -0,0 +1,96 @@
|
|||
/// <reference path="../_definitions.ts" />
|
||||
/**
|
||||
* Phaser - AnimationLoader
|
||||
*
|
||||
* Responsible for parsing sprite sheet and JSON data into the internal FrameData format that Phaser uses for animations.
|
||||
*/
|
||||
var Phaser;
|
||||
(function (Phaser) {
|
||||
var AnimationLoader = (function () {
|
||||
function AnimationLoader() { }
|
||||
AnimationLoader.parseSpriteSheet = /**
|
||||
* Parse a sprite sheet from asset data.
|
||||
* @param key {string} Asset key for the sprite sheet data.
|
||||
* @param frameWidth {number} Width of animation frame.
|
||||
* @param frameHeight {number} Height of animation frame.
|
||||
* @param frameMax {number} Number of animation frames.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
function parseSpriteSheet(game, key, frameWidth, frameHeight, frameMax) {
|
||||
// How big is our image?
|
||||
var img = game.cache.getImage(key);
|
||||
if(img == null) {
|
||||
return null;
|
||||
}
|
||||
var width = img.width;
|
||||
var height = img.height;
|
||||
var row = Math.round(width / frameWidth);
|
||||
var column = Math.round(height / frameHeight);
|
||||
var total = row * column;
|
||||
if(frameMax !== -1) {
|
||||
total = frameMax;
|
||||
}
|
||||
// Zero or smaller than frame sizes?
|
||||
if(width == 0 || height == 0 || width < frameWidth || height < frameHeight || total === 0) {
|
||||
throw new Error("AnimationLoader.parseSpriteSheet: width/height zero or width/height < given frameWidth/frameHeight");
|
||||
return null;
|
||||
}
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
var x = 0;
|
||||
var y = 0;
|
||||
for(var i = 0; i < total; i++) {
|
||||
data.addFrame(new Phaser.Frame(x, y, frameWidth, frameHeight, ''));
|
||||
x += frameWidth;
|
||||
if(x === width) {
|
||||
x = 0;
|
||||
y += frameHeight;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
AnimationLoader.parseJSONData = /**
|
||||
* Parse frame datas from json.
|
||||
* @param json {object} Json data you want to parse.
|
||||
* @return {FrameData} Generated FrameData object.
|
||||
*/
|
||||
function parseJSONData(game, json) {
|
||||
// Malformed?
|
||||
if(!json['frames']) {
|
||||
console.log(json);
|
||||
throw new Error("Phaser.AnimationLoader.parseJSONData: Invalid Texture Atlas JSON given, missing 'frames' array");
|
||||
}
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
// By this stage frames is a fully parsed array
|
||||
var frames = json['frames'];
|
||||
var newFrame;
|
||||
for(var i = 0; i < frames.length; i++) {
|
||||
newFrame = data.addFrame(new Phaser.Frame(frames[i].frame.x, frames[i].frame.y, frames[i].frame.w, frames[i].frame.h, frames[i].filename));
|
||||
newFrame.setTrim(frames[i].trimmed, frames[i].sourceSize.w, frames[i].sourceSize.h, frames[i].spriteSourceSize.x, frames[i].spriteSourceSize.y, frames[i].spriteSourceSize.w, frames[i].spriteSourceSize.h);
|
||||
}
|
||||
return data;
|
||||
};
|
||||
AnimationLoader.parseXMLData = function parseXMLData(game, xml, format) {
|
||||
// Malformed?
|
||||
if(!xml.getElementsByTagName('TextureAtlas')) {
|
||||
throw new Error("Phaser.AnimationLoader.parseXMLData: Invalid Texture Atlas XML given, missing <TextureAtlas> tag");
|
||||
}
|
||||
// Let's create some frames then
|
||||
var data = new Phaser.FrameData();
|
||||
var frames = xml.getElementsByTagName('SubTexture');
|
||||
var newFrame;
|
||||
for(var i = 0; i < frames.length; i++) {
|
||||
var frame = frames[i].attributes;
|
||||
newFrame = data.addFrame(new Phaser.Frame(frame.x.nodeValue, frame.y.nodeValue, frame.width.nodeValue, frame.height.nodeValue, frame.name.nodeValue));
|
||||
// Trimmed?
|
||||
if(frame.frameX.nodeValue != '-0' || frame.frameY.nodeValue != '-0') {
|
||||
newFrame.setTrim(true, frame.width.nodeValue, frame.height.nodeValue, Math.abs(frame.frameX.nodeValue), Math.abs(frame.frameY.nodeValue), frame.frameWidth.nodeValue, frame.frameHeight.nodeValue);
|
||||
}
|
||||
}
|
||||
return data;
|
||||
};
|
||||
return AnimationLoader;
|
||||
})();
|
||||
Phaser.AnimationLoader = AnimationLoader;
|
||||
})(Phaser || (Phaser = {}));
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue