diff --git a/Docs/API/api.js b/Docs/API/api.js new file mode 100644 index 00000000..12711933 --- /dev/null +++ b/Docs/API/api.js @@ -0,0 +1,16 @@ +YUI.add("yuidoc-meta", function(Y) { + Y.YUIDoc = { meta: { + "classes": [ + "TimeManager" + ], + "modules": [ + "Phaser" + ], + "allModules": [ + { + "displayName": "Phaser", + "name": "Phaser" + } + ] +} }; +}); \ No newline at end of file diff --git a/Docs/API/assets/css/external-small.png b/Docs/API/assets/css/external-small.png new file mode 100644 index 00000000..759a1cdc Binary files /dev/null and b/Docs/API/assets/css/external-small.png differ diff --git a/Docs/API/assets/css/logo.png b/Docs/API/assets/css/logo.png new file mode 100644 index 00000000..609b336c Binary files /dev/null and b/Docs/API/assets/css/logo.png differ diff --git a/Docs/API/assets/css/main.css b/Docs/API/assets/css/main.css new file mode 100644 index 00000000..d745d443 --- /dev/null +++ b/Docs/API/assets/css/main.css @@ -0,0 +1,783 @@ +/* +Font sizes for all selectors other than the body are given in percentages, +with 100% equal to 13px. To calculate a font size percentage, multiply the +desired size in pixels by 7.6923076923. + +Here's a quick lookup table: + +10px - 76.923% +11px - 84.615% +12px - 92.308% +13px - 100% +14px - 107.692% +15px - 115.385% +16px - 123.077% +17px - 130.769% +18px - 138.462% +19px - 146.154% +20px - 153.846% +*/ + +html { + background: #fff; + color: #333; + overflow-y: scroll; +} + +body { + /*font: 13px/1.4 'Lucida Grande', 'Lucida Sans Unicode', 'DejaVu Sans', 'Bitstream Vera Sans', 'Helvetica', 'Arial', sans-serif;*/ + font: 13px/1.4 'Helvetica', 'Arial', sans-serif; + margin: 0; + padding: 0; +} + +/* -- Links ----------------------------------------------------------------- */ +a { + color: #356de4; + text-decoration: none; +} + +.hidden { + display: none; +} + +a:hover { text-decoration: underline; } + +/* "Jump to Table of Contents" link is shown to assistive tools, but hidden from + sight until it's focused. */ +.jump { + position: absolute; + padding: 3px 6px; + left: -99999px; + top: 0; +} + +.jump:focus { left: 40%; } + +/* -- Paragraphs ------------------------------------------------------------ */ +p { margin: 1.3em 0; } +dd p, td p { margin-bottom: 0; } +dd p:first-child, td p:first-child { margin-top: 0; } + +/* -- Headings -------------------------------------------------------------- */ +h1, h2, h3, h4, h5, h6 { + color: #D98527;/*was #f80*/ + font-family: 'Trebuchet MS', sans-serif; + font-weight: bold; + line-height: 1.1; + margin: 1.1em 0 0.5em; +} + +h1 { + font-size: 184.6%; + color: #30418C; + margin: 0.75em 0 0.5em; +} + +h2 { + font-size: 153.846%; + color: #E48A2B; +} + +h3 { font-size: 138.462%; } + +h4 { + border-bottom: 1px solid #DBDFEA; + color: #E48A2B; + font-size: 115.385%; + font-weight: normal; + padding-bottom: 2px; +} + +h5, h6 { font-size: 107.692%; } + +/* -- Code and examples ----------------------------------------------------- */ +code, kbd, pre, samp { + font-family: Menlo, Monaco, 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', Courier, monospace; + font-size: 92.308%; + line-height: 1.35; +} + +p code, p kbd, p samp { + background: #FCFBFA; + border: 1px solid #EFEEED; + padding: 0 3px; +} + +a code, a kbd, a samp, +pre code, pre kbd, pre samp, +table code, table kbd, table samp, +.intro code, .intro kbd, .intro samp, +.toc code, .toc kbd, .toc samp { + background: none; + border: none; + padding: 0; +} + +pre.code, pre.terminal, pre.cmd { + overflow-x: auto; + *overflow-x: scroll; + padding: 0.3em 0.6em; +} + +pre.code { + background: #FCFBFA; + border: 1px solid #EFEEED; + border-left-width: 5px; +} + +pre.terminal, pre.cmd { + background: #F0EFFC; + border: 1px solid #D0CBFB; + border-left: 5px solid #D0CBFB; +} + +/* Don't reduce the font size of // elements inside
+   blocks. */
+pre code, pre kbd, pre samp { font-size: 100%; }
+
+/* Used to denote text that shouldn't be selectable, such as line numbers or
+   shell prompts. Guess which browser this doesn't work in. */
+.noselect {
+    -moz-user-select: -moz-none;
+    -khtml-user-select: none;
+    -webkit-user-select: none;
+    -o-user-select: none;
+    user-select: none;
+}
+
+/* -- Lists ----------------------------------------------------------------- */
+dd { margin: 0.2em 0 0.7em 1em; }
+dl { margin: 1em 0; }
+dt { font-weight: bold; }
+
+/* -- Tables ---------------------------------------------------------------- */
+caption, th { text-align: left; }
+
+table {
+    border-collapse: collapse;
+    width: 100%;
+}
+
+td, th {
+    border: 1px solid #fff;
+    padding: 5px 12px;
+    vertical-align: top;
+}
+
+td { background: #E6E9F5; }
+td dl { margin: 0; }
+td dl dl { margin: 1em 0; }
+td pre:first-child { margin-top: 0; }
+
+th {
+    background: #D2D7E6;/*#97A0BF*/
+    border-bottom: none;
+    border-top: none;
+    color: #000;/*#FFF1D5*/
+    font-family: 'Trebuchet MS', sans-serif;
+    font-weight: bold;
+    line-height: 1.3;
+    white-space: nowrap;
+}
+
+
+/* -- Layout and Content ---------------------------------------------------- */
+#doc {
+    margin: auto;
+    min-width: 1024px;
+}
+
+.content { padding: 0 20px 0 25px; }
+
+.sidebar {
+    padding: 0 15px 0 10px;
+}
+#bd {
+    padding: 7px 0 130px;
+    position: relative;
+    width: 99%;
+}
+
+/* -- Table of Contents ----------------------------------------------------- */
+
+/* The #toc id refers to the single global table of contents, while the .toc
+   class refers to generic TOC lists that could be used throughout the page. */
+
+.toc code, .toc kbd, .toc samp { font-size: 100%; }
+.toc li { font-weight: bold; }
+.toc li li { font-weight: normal; }
+
+/* -- Intro and Example Boxes ----------------------------------------------- */
+/*
+.intro, .example { margin-bottom: 2em; }
+.example {
+    -moz-border-radius: 4px;
+    -webkit-border-radius: 4px;
+    border-radius: 4px;
+    -moz-box-shadow: 0 0 5px #bfbfbf;
+    -webkit-box-shadow: 0 0 5px #bfbfbf;
+    box-shadow: 0 0 5px #bfbfbf;
+    padding: 1em;
+}
+.intro {
+    background: none repeat scroll 0 0 #F0F1F8; border: 1px solid #D4D8EB; padding: 0 1em;
+}
+*/
+
+/* -- Other Styles ---------------------------------------------------------- */
+
+/* These are probably YUI-specific, and should be moved out of Selleck's default
+   theme. */
+
+.button {
+    border: 1px solid #dadada;
+    -moz-border-radius: 3px;
+    -webkit-border-radius: 3px;
+    border-radius: 3px;
+    color: #444;
+    display: inline-block;
+    font-family: Helvetica, Arial, sans-serif;
+    font-size: 92.308%;
+    font-weight: bold;
+    padding: 4px 13px 3px;
+    -moz-text-shadow: 1px 1px 0 #fff;
+    -webkit-text-shadow: 1px 1px 0 #fff;
+    text-shadow: 1px 1px 0 #fff;
+    white-space: nowrap;
+
+    background: #EFEFEF; /* old browsers */
+    background: -moz-linear-gradient(top, #f5f5f5 0%, #efefef 50%, #e5e5e5 51%, #dfdfdf 100%); /* firefox */
+    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#f5f5f5), color-stop(50%,#efefef), color-stop(51%,#e5e5e5), color-stop(100%,#dfdfdf)); /* webkit */
+    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#f5f5f5', endColorstr='#dfdfdf',GradientType=0 ); /* ie */
+}
+
+.button:hover {
+    border-color: #466899;
+    color: #fff;
+    text-decoration: none;
+    -moz-text-shadow: 1px 1px 0 #222;
+    -webkit-text-shadow: 1px 1px 0 #222;
+    text-shadow: 1px 1px 0 #222;
+
+    background: #6396D8; /* old browsers */
+    background: -moz-linear-gradient(top, #6396D8 0%, #5A83BC 50%, #547AB7 51%, #466899 100%); /* firefox */
+    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#6396D8), color-stop(50%,#5A83BC), color-stop(51%,#547AB7), color-stop(100%,#466899)); /* webkit */
+    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#6396D8', endColorstr='#466899',GradientType=0 ); /* ie */
+}
+
+.newwindow { text-align: center; }
+
+.header .version em {
+    display: block;
+    text-align: right;
+}
+
+
+#classdocs .item {
+    border-bottom: 1px solid #466899;
+    margin: 1em 0;
+    padding: 1.5em;
+}
+
+#classdocs .item .params p,
+    #classdocs .item .returns p,{
+    display: inline;
+}
+
+#classdocs .item em code, #classdocs .item em.comment {
+    color: green;
+}
+
+#classdocs .item em.comment a {
+    color: green;
+    text-decoration: underline;
+}
+
+#classdocs .foundat {
+    font-size: 11px;
+    font-style: normal;
+}
+
+.attrs .emits {
+    margin-left: 2em;
+    padding: .5em;
+    border-left: 1px dashed #ccc;
+}
+
+abbr {
+    border-bottom: 1px dashed #ccc;
+    font-size: 80%;
+    cursor: help;
+}
+
+.prettyprint li.L0, 
+.prettyprint li.L1, 
+.prettyprint li.L2, 
+.prettyprint li.L3, 
+.prettyprint li.L5, 
+.prettyprint li.L6, 
+.prettyprint li.L7, 
+.prettyprint li.L8 {
+    list-style: decimal;
+}
+
+ul li p {
+    margin-top: 0;
+}
+
+.method .name {
+    font-size: 110%;
+}
+
+.apidocs .methods .extends .method,
+.apidocs .properties .extends .property,
+.apidocs .attrs .extends .attr,
+.apidocs .events .extends .event {
+    font-weight: bold;
+}
+
+.apidocs .methods .extends .inherited,
+.apidocs .properties .extends .inherited,
+.apidocs .attrs .extends .inherited,
+.apidocs .events .extends .inherited {
+    font-weight: normal;
+}
+
+#hd {
+    background: whiteSmoke;
+    background: -moz-linear-gradient(top,#DCDBD9 0,#F6F5F3 100%);
+    background: -webkit-gradient(linear,left top,left bottom,color-stop(0%,#DCDBD9),color-stop(100%,#F6F5F3));
+    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dcdbd9',endColorstr='#F6F5F3',GradientType=0);
+    border-bottom: 1px solid #DFDFDF;
+    padding: 0 15px 1px 20px;
+    margin-bottom: 15px;
+}
+
+#hd img {
+    margin-right: 10px;
+    vertical-align: middle;
+}
+
+
+/* -- API Docs CSS ---------------------------------------------------------- */
+
+/*
+This file is organized so that more generic styles are nearer the top, and more
+specific styles are nearer the bottom of the file. This allows us to take full
+advantage of the cascade to avoid redundant style rules. Please respect this
+convention when making changes.
+*/
+
+/* -- Generic TabView styles ------------------------------------------------ */
+
+/*
+These styles apply to all API doc tabviews. To change styles only for a
+specific tabview, see the other sections below.
+*/
+
+.yui3-js-enabled .apidocs .tabview {
+    visibility: hidden; /* Hide until the TabView finishes rendering. */
+    _visibility: visible;
+}
+
+.apidocs .tabview.yui3-tabview-content { visibility: visible; }
+.apidocs .tabview .yui3-tabview-panel { background: #fff; }
+
+/* -- Generic Content Styles ------------------------------------------------ */
+
+/* Headings */
+h2, h3, h4, h5, h6 {
+    border: none;
+    color: #30418C;
+    font-weight: bold;
+    text-decoration: none;
+}
+
+.link-docs {
+    float: right;
+    font-size: 15px;
+    margin: 4px 4px 6px;
+    padding: 6px 30px 5px;
+}
+
+.apidocs { zoom: 1; }
+
+/* Generic box styles. */
+.apidocs .box {
+    border: 1px solid;
+    border-radius: 3px;
+    margin: 1em 0;
+    padding: 0 1em;
+}
+
+/* A flag is a compact, capsule-like indicator of some kind. It's used to
+   indicate private and protected items, item return types, etc. in an
+   attractive and unobtrusive way. */
+.apidocs .flag {
+    background: #bababa;
+    border-radius: 3px;
+    color: #fff;
+    font-size: 11px;
+    margin: 0 0.5em;
+    padding: 2px 4px 1px;
+}
+
+/* Class/module metadata such as "Uses", "Extends", "Defined in", etc. */
+.apidocs .meta {
+    background: #f9f9f9;
+    border-color: #efefef;
+    color: #555;
+    font-size: 11px;
+    padding: 3px 6px;
+}
+
+.apidocs .meta p { margin: 0; }
+
+/* Deprecation warning. */
+.apidocs .box.deprecated,
+.apidocs .flag.deprecated {
+    background: #fdac9f;
+    border: 1px solid #fd7775;
+}
+
+.apidocs .box.deprecated p { margin: 0.5em 0; }
+.apidocs .flag.deprecated { color: #333; }
+
+/* Module/Class intro description. */
+.apidocs .intro {
+    background: #f0f1f8;
+    border-color: #d4d8eb;
+}
+
+/* Loading spinners. */
+#bd.loading .apidocs,
+#api-list.loading .yui3-tabview-panel {
+    background: #fff url(../img/spinner.gif) no-repeat center 70px;
+    min-height: 150px;
+}
+
+#bd.loading .apidocs .content,
+#api-list.loading .yui3-tabview-panel .apis {
+    display: none;
+}
+
+.apidocs .no-visible-items { color: #666; }
+
+/* Generic inline list. */
+.apidocs ul.inline {
+    display: inline;
+    list-style: none;
+    margin: 0;
+    padding: 0;
+}
+
+.apidocs ul.inline li { display: inline; }
+
+/* Comma-separated list. */
+.apidocs ul.commas li:after { content: ','; }
+.apidocs ul.commas li:last-child:after { content: ''; }
+
+/* Keyboard shortcuts. */
+kbd .cmd { font-family: Monaco, Helvetica; }
+
+/* -- Generic Access Level styles ------------------------------------------- */
+.apidocs .item.protected,
+.apidocs .item.private,
+.apidocs .index-item.protected,
+.apidocs .index-item.deprecated,
+.apidocs .index-item.private {
+    display: none;
+}
+
+.show-deprecated .item.deprecated,
+.show-deprecated .index-item.deprecated,
+.show-protected .item.protected,
+.show-protected .index-item.protected,
+.show-private .item.private,
+.show-private .index-item.private {
+    display: block;
+}
+
+.hide-inherited .item.inherited,
+.hide-inherited .index-item.inherited {
+    display: none;
+}
+
+/* -- Generic Item Index styles --------------------------------------------- */
+.apidocs .index { margin: 1.5em 0 3em; }
+
+.apidocs .index h3 {
+    border-bottom: 1px solid #efefef;
+    color: #333;
+    font-size: 13px;
+    margin: 2em 0 0.6em;
+    padding-bottom: 2px;
+}
+
+.apidocs .index .no-visible-items { margin-top: 2em; }
+
+.apidocs .index-list {
+    border-color: #efefef;
+    font-size: 12px;
+    list-style: none;
+    margin: 0;
+    padding: 0;
+    -moz-column-count: 4;
+    -moz-column-gap: 10px;
+    -moz-column-width: 170px;
+    -ms-column-count: 4;
+    -ms-column-gap: 10px;
+    -ms-column-width: 170px;
+    -o-column-count: 4;
+    -o-column-gap: 10px;
+    -o-column-width: 170px;
+    -webkit-column-count: 4;
+    -webkit-column-gap: 10px;
+    -webkit-column-width: 170px;
+    column-count: 4;
+    column-gap: 10px;
+    column-width: 170px;
+}
+
+.apidocs .no-columns .index-list {
+    -moz-column-count: 1;
+    -ms-column-count: 1;
+    -o-column-count: 1;
+    -webkit-column-count: 1;
+    column-count: 1;
+}
+
+.apidocs .index-item { white-space: nowrap; }
+
+.apidocs .index-item .flag {
+    background: none;
+    border: none;
+    color: #afafaf;
+    display: inline;
+    margin: 0 0 0 0.2em;
+    padding: 0;
+}
+
+/* -- Generic API item styles ----------------------------------------------- */
+.apidocs .args {
+    display: inline;
+    margin: 0 0.5em;
+}
+
+.apidocs .flag.chainable { background: #46ca3b; }
+.apidocs .flag.protected { background: #9b86fc; }
+.apidocs .flag.private { background: #fd6b1b; }
+.apidocs .flag.async { background: #356de4; }
+.apidocs .flag.required { background: #e60923; }
+
+.apidocs .item {
+    border-bottom: 1px solid #efefef;
+    margin: 1.5em 0 2em;
+    padding-bottom: 2em;
+}
+
+.apidocs .item h4,
+.apidocs .item h5,
+.apidocs .item h6 {
+    color: #333;
+    font-family: inherit;
+    font-size: 100%;
+}
+
+.apidocs .item .description p,
+.apidocs .item pre.code {
+    margin: 1em 0 0;
+}
+
+.apidocs .item .meta {
+    background: none;
+    border: none;
+    padding: 0;
+}
+
+.apidocs .item .name {
+    display: inline;
+    font-size: 14px;
+}
+
+.apidocs .item .type,
+.apidocs .item .type a,
+.apidocs .returns-inline {
+    color: #555;
+}
+
+.apidocs .item .type,
+.apidocs .returns-inline {
+    font-size: 11px;
+    margin: 0 0 0 0;
+}
+
+.apidocs .item .type a { border-bottom: 1px dotted #afafaf; }
+.apidocs .item .type a:hover { border: none; }
+
+/* -- Item Parameter List --------------------------------------------------- */
+.apidocs .params-list {
+    list-style: square;
+    margin: 1em 0 0 2em;
+    padding: 0;
+}
+
+.apidocs .param { margin-bottom: 1em; }
+
+.apidocs .param .type,
+.apidocs .param .type a {
+    color: #666;
+}
+
+.apidocs .param .type {
+    margin: 0 0 0 0.5em;
+    *margin-left: 0.5em;
+}
+
+.apidocs .param-name { font-weight: bold; }
+
+/* -- Item "Emits" block ---------------------------------------------------- */
+.apidocs .item .emits {
+    background: #f9f9f9;
+    border-color: #eaeaea;
+}
+
+/* -- Item "Returns" block -------------------------------------------------- */
+.apidocs .item .returns .type,
+.apidocs .item .returns .type a {
+    font-size: 100%;
+    margin: 0;
+}
+
+/* -- Class Constructor block ----------------------------------------------- */
+.apidocs .constructor .item {
+    border: none;
+    padding-bottom: 0;
+}
+
+/* -- File Source View ------------------------------------------------------ */
+.apidocs .file pre.code,
+#doc .apidocs .file pre.prettyprint {
+    background: inherit;
+    border: none;
+    overflow: visible;
+    padding: 0;
+}
+
+.apidocs .L0,
+.apidocs .L1,
+.apidocs .L2,
+.apidocs .L3,
+.apidocs .L4,
+.apidocs .L5,
+.apidocs .L6,
+.apidocs .L7,
+.apidocs .L8,
+.apidocs .L9 {
+    background: inherit;
+}
+
+/* -- Submodule List -------------------------------------------------------- */
+.apidocs .module-submodule-description {
+    font-size: 12px;
+    margin: 0.3em 0 1em;
+}
+
+.apidocs .module-submodule-description p:first-child { margin-top: 0; }
+
+/* -- Sidebar TabView ------------------------------------------------------- */
+#api-tabview { margin-top: 0.6em; }
+
+#api-tabview-filter,
+#api-tabview-panel {
+    border: 1px solid #dfdfdf;
+}
+
+#api-tabview-filter {
+    border-bottom: none;
+    border-top: none;
+    padding: 0.6em 10px 0 10px;
+}
+
+#api-tabview-panel { border-top: none; }
+#api-filter { width: 97%; }
+
+/* -- Content TabView ------------------------------------------------------- */
+#classdocs .yui3-tabview-panel { border: none; }
+
+/* -- Source File Contents -------------------------------------------------- */
+.prettyprint li.L0,
+.prettyprint li.L1,
+.prettyprint li.L2,
+.prettyprint li.L3,
+.prettyprint li.L5,
+.prettyprint li.L6,
+.prettyprint li.L7,
+.prettyprint li.L8 {
+    list-style: decimal;
+}
+
+/* -- API options ----------------------------------------------------------- */
+#api-options {
+    font-size: 11px;
+    margin-top: 2.2em;
+    position: absolute;
+    right: 1.5em;
+}
+
+/*#api-options label { margin-right: 0.6em; }*/
+
+/* -- API list -------------------------------------------------------------- */
+#api-list {
+    margin-top: 1.5em;
+    *zoom: 1;
+}
+
+.apis {
+    font-size: 12px;
+    line-height: 1.4;
+    list-style: none;
+    margin: 0;
+    padding: 0.5em 0 0.5em 0.4em;
+}
+
+.apis a {
+    border: 1px solid transparent;
+    display: block;
+    margin: 0 0 0 -4px;
+    padding: 1px 4px 0;
+    text-decoration: none;
+    _border: none;
+    _display: inline;
+}
+
+.apis a:hover,
+.apis a:focus {
+    background: #E8EDFC;
+    background: -moz-linear-gradient(top, #e8edfc 0%, #becef7 100%);
+    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#E8EDFC), color-stop(100%,#BECEF7));
+    border-color: #AAC0FA;
+    border-radius: 3px;
+    color: #333;
+    outline: none;
+}
+
+.api-list-item a:hover,
+.api-list-item a:focus {
+    font-weight: bold;
+    text-shadow: 1px 1px 1px #fff;
+}
+
+.apis .message { color: #888; }
+.apis .result a { padding: 3px 5px 2px; }
+
+.apis .result .type {
+    right: 4px;
+    top: 7px;
+}
+
+.api-list-item .yui3-highlight {
+    font-weight: bold;
+}
+
diff --git a/Docs/API/assets/favicon.png b/Docs/API/assets/favicon.png
new file mode 100644
index 00000000..5a95ddab
Binary files /dev/null and b/Docs/API/assets/favicon.png differ
diff --git a/Docs/API/assets/img/spinner.gif b/Docs/API/assets/img/spinner.gif
new file mode 100644
index 00000000..44f96ba6
Binary files /dev/null and b/Docs/API/assets/img/spinner.gif differ
diff --git a/Docs/API/assets/index.html b/Docs/API/assets/index.html
new file mode 100644
index 00000000..487fe15b
--- /dev/null
+++ b/Docs/API/assets/index.html
@@ -0,0 +1,10 @@
+
+
+    
+        Redirector
+        
+    
+    
+        Click here to redirect
+    
+
diff --git a/Docs/API/assets/js/api-filter.js b/Docs/API/assets/js/api-filter.js
new file mode 100644
index 00000000..37aefbab
--- /dev/null
+++ b/Docs/API/assets/js/api-filter.js
@@ -0,0 +1,52 @@
+YUI.add('api-filter', function (Y) {
+
+Y.APIFilter = Y.Base.create('apiFilter', Y.Base, [Y.AutoCompleteBase], {
+    // -- Initializer ----------------------------------------------------------
+    initializer: function () {
+        this._bindUIACBase();
+        this._syncUIACBase();
+    },
+    getDisplayName: function(name) {
+
+        Y.each(Y.YUIDoc.meta.allModules, function(i) {
+            if (i.name === name && i.displayName) {
+                name = i.displayName;
+            }
+        });
+
+        return name;
+    }
+
+}, {
+    // -- Attributes -----------------------------------------------------------
+    ATTRS: {
+        resultHighlighter: {
+            value: 'phraseMatch'
+        },
+
+        // May be set to "classes" or "modules".
+        queryType: {
+            value: 'classes'
+        },
+
+        source: {
+            valueFn: function() {
+                var self = this;
+                return function(q) {
+                    var data = Y.YUIDoc.meta[self.get('queryType')],
+                        out = [];
+                    Y.each(data, function(v) {
+                        if (v.toLowerCase().indexOf(q.toLowerCase()) > -1) {
+                            out.push(v);
+                        }
+                    });
+                    return out;
+                };
+            }
+        }
+    }
+});
+
+}, '3.4.0', {requires: [
+    'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources'
+]});
diff --git a/Docs/API/assets/js/api-list.js b/Docs/API/assets/js/api-list.js
new file mode 100644
index 00000000..88905b52
--- /dev/null
+++ b/Docs/API/assets/js/api-list.js
@@ -0,0 +1,251 @@
+YUI.add('api-list', function (Y) {
+
+var Lang   = Y.Lang,
+    YArray = Y.Array,
+
+    APIList = Y.namespace('APIList'),
+
+    classesNode    = Y.one('#api-classes'),
+    inputNode      = Y.one('#api-filter'),
+    modulesNode    = Y.one('#api-modules'),
+    tabviewNode    = Y.one('#api-tabview'),
+
+    tabs = APIList.tabs = {},
+
+    filter = APIList.filter = new Y.APIFilter({
+        inputNode : inputNode,
+        maxResults: 1000,
+
+        on: {
+            results: onFilterResults
+        }
+    }),
+
+    search = APIList.search = new Y.APISearch({
+        inputNode : inputNode,
+        maxResults: 100,
+
+        on: {
+            clear  : onSearchClear,
+            results: onSearchResults
+        }
+    }),
+
+    tabview = APIList.tabview = new Y.TabView({
+        srcNode  : tabviewNode,
+        panelNode: '#api-tabview-panel',
+        render   : true,
+
+        on: {
+            selectionChange: onTabSelectionChange
+        }
+    }),
+
+    focusManager = APIList.focusManager = tabviewNode.plug(Y.Plugin.NodeFocusManager, {
+        circular   : true,
+        descendants: '#api-filter, .yui3-tab-panel-selected .api-list-item a, .yui3-tab-panel-selected .result a',
+        keys       : {next: 'down:40', previous: 'down:38'}
+    }).focusManager,
+
+    LIST_ITEM_TEMPLATE =
+        '
  • ' + + '{displayName}' + + '
  • '; + +// -- Init --------------------------------------------------------------------- + +// Duckpunch FocusManager's key event handling to prevent it from handling key +// events when a modifier is pressed. +Y.before(function (e, activeDescendant) { + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { + return new Y.Do.Prevent(); + } +}, focusManager, '_focusPrevious', focusManager); + +Y.before(function (e, activeDescendant) { + if (e.altKey || e.ctrlKey || e.metaKey || e.shiftKey) { + return new Y.Do.Prevent(); + } +}, focusManager, '_focusNext', focusManager); + +// Create a mapping of tabs in the tabview so we can refer to them easily later. +tabview.each(function (tab, index) { + var name = tab.get('label').toLowerCase(); + + tabs[name] = { + index: index, + name : name, + tab : tab + }; +}); + +// Switch tabs on Ctrl/Cmd-Left/Right arrows. +tabviewNode.on('key', onTabSwitchKey, 'down:37,39'); + +// Focus the filter input when the `/` key is pressed. +Y.one(Y.config.doc).on('key', onSearchKey, 'down:83'); + +// Keep the Focus Manager up to date. +inputNode.on('focus', function () { + focusManager.set('activeDescendant', inputNode); +}); + +// Update all tabview links to resolved URLs. +tabview.get('panelNode').all('a').each(function (link) { + link.setAttribute('href', link.get('href')); +}); + +// -- Private Functions -------------------------------------------------------- +function getFilterResultNode() { + return filter.get('queryType') === 'classes' ? classesNode : modulesNode; +} + +// -- Event Handlers ----------------------------------------------------------- +function onFilterResults(e) { + var frag = Y.one(Y.config.doc.createDocumentFragment()), + resultNode = getFilterResultNode(), + typePlural = filter.get('queryType'), + typeSingular = typePlural === 'classes' ? 'class' : 'module'; + + if (e.results.length) { + YArray.each(e.results, function (result) { + frag.append(Lang.sub(LIST_ITEM_TEMPLATE, { + rootPath : APIList.rootPath, + displayName : filter.getDisplayName(result.highlighted), + name : result.text, + typePlural : typePlural, + typeSingular: typeSingular + })); + }); + } else { + frag.append( + '
  • ' + + 'No ' + typePlural + ' found.' + + '
  • ' + ); + } + + resultNode.empty(true); + resultNode.append(frag); + + focusManager.refresh(); +} + +function onSearchClear(e) { + + focusManager.refresh(); +} + +function onSearchKey(e) { + var target = e.target; + + if (target.test('input,select,textarea') + || target.get('isContentEditable')) { + return; + } + + e.preventDefault(); + + inputNode.focus(); + focusManager.refresh(); +} + +function onSearchResults(e) { + var frag = Y.one(Y.config.doc.createDocumentFragment()); + + if (e.results.length) { + YArray.each(e.results, function (result) { + frag.append(result.display); + }); + } else { + frag.append( + '
  • ' + + 'No results found. Maybe you\'ll have better luck with a ' + + 'different query?' + + '
  • ' + ); + } + + + focusManager.refresh(); +} + +function onTabSelectionChange(e) { + var tab = e.newVal, + name = tab.get('label').toLowerCase(); + + tabs.selected = { + index: tab.get('index'), + name : name, + tab : tab + }; + + switch (name) { + case 'classes': // fallthru + case 'modules': + filter.setAttrs({ + minQueryLength: 0, + queryType : name + }); + + search.set('minQueryLength', -1); + + // Only send a request if this isn't the initially-selected tab. + if (e.prevVal) { + filter.sendRequest(filter.get('value')); + } + break; + + case 'everything': + filter.set('minQueryLength', -1); + search.set('minQueryLength', 1); + + if (search.get('value')) { + search.sendRequest(search.get('value')); + } else { + inputNode.focus(); + } + break; + + default: + // WTF? We shouldn't be here! + filter.set('minQueryLength', -1); + search.set('minQueryLength', -1); + } + + if (focusManager) { + setTimeout(function () { + focusManager.refresh(); + }, 1); + } +} + +function onTabSwitchKey(e) { + var currentTabIndex = tabs.selected.index; + + if (!(e.ctrlKey || e.metaKey)) { + return; + } + + e.preventDefault(); + + switch (e.keyCode) { + case 37: // left arrow + if (currentTabIndex > 0) { + tabview.selectChild(currentTabIndex - 1); + inputNode.focus(); + } + break; + + case 39: // right arrow + if (currentTabIndex < (Y.Object.size(tabs) - 2)) { + tabview.selectChild(currentTabIndex + 1); + inputNode.focus(); + } + break; + } +} + +}, '3.4.0', {requires: [ + 'api-filter', 'api-search', 'event-key', 'node-focusmanager', 'tabview' +]}); diff --git a/Docs/API/assets/js/api-search.js b/Docs/API/assets/js/api-search.js new file mode 100644 index 00000000..175f6a61 --- /dev/null +++ b/Docs/API/assets/js/api-search.js @@ -0,0 +1,98 @@ +YUI.add('api-search', function (Y) { + +var Lang = Y.Lang, + Node = Y.Node, + YArray = Y.Array; + +Y.APISearch = Y.Base.create('apiSearch', Y.Base, [Y.AutoCompleteBase], { + // -- Public Properties ---------------------------------------------------- + RESULT_TEMPLATE: + '
  • ' + + '' + + '

    {name}

    ' + + '{resultType}' + + '
    {description}
    ' + + '{class}' + + '
    ' + + '
  • ', + + // -- Initializer ---------------------------------------------------------- + initializer: function () { + this._bindUIACBase(); + this._syncUIACBase(); + }, + + // -- Protected Methods ---------------------------------------------------- + _apiResultFilter: function (query, results) { + // Filter components out of the results. + return YArray.filter(results, function (result) { + return result.raw.resultType === 'component' ? false : result; + }); + }, + + _apiResultFormatter: function (query, results) { + return YArray.map(results, function (result) { + var raw = Y.merge(result.raw), // create a copy + desc = raw.description || ''; + + // Convert description to text and truncate it if necessary. + desc = Node.create('
    ' + desc + '
    ').get('text'); + + if (desc.length > 65) { + desc = Y.Escape.html(desc.substr(0, 65)) + ' …'; + } else { + desc = Y.Escape.html(desc); + } + + raw['class'] || (raw['class'] = ''); + raw.description = desc; + + // Use the highlighted result name. + raw.name = result.highlighted; + + return Lang.sub(this.RESULT_TEMPLATE, raw); + }, this); + }, + + _apiTextLocator: function (result) { + return result.displayName || result.name; + } +}, { + // -- Attributes ----------------------------------------------------------- + ATTRS: { + resultFormatter: { + valueFn: function () { + return this._apiResultFormatter; + } + }, + + resultFilters: { + valueFn: function () { + return this._apiResultFilter; + } + }, + + resultHighlighter: { + value: 'phraseMatch' + }, + + resultListLocator: { + value: 'data.results' + }, + + resultTextLocator: { + valueFn: function () { + return this._apiTextLocator; + } + }, + + source: { + value: '/api/v1/search?q={query}&count={maxResults}' + } + } +}); + +}, '3.4.0', {requires: [ + 'autocomplete-base', 'autocomplete-highlighters', 'autocomplete-sources', + 'escape' +]}); diff --git a/Docs/API/assets/js/apidocs.js b/Docs/API/assets/js/apidocs.js new file mode 100644 index 00000000..c64bb463 --- /dev/null +++ b/Docs/API/assets/js/apidocs.js @@ -0,0 +1,370 @@ +YUI().use( + 'yuidoc-meta', + 'api-list', 'history-hash', 'node-screen', 'node-style', 'pjax', +function (Y) { + +var win = Y.config.win, + localStorage = win.localStorage, + + bdNode = Y.one('#bd'), + + pjax, + defaultRoute, + + classTabView, + selectedTab; + +// Kill pjax functionality unless serving over HTTP. +if (!Y.getLocation().protocol.match(/^https?\:/)) { + Y.Router.html5 = false; +} + +// Create the default route with middleware which enables syntax highlighting +// on the loaded content. +defaultRoute = Y.Pjax.defaultRoute.concat(function (req, res, next) { + prettyPrint(); + bdNode.removeClass('loading'); + + next(); +}); + +pjax = new Y.Pjax({ + container : '#docs-main', + contentSelector: '#docs-main > .content', + linkSelector : '#bd a', + titleSelector : '#xhr-title', + + navigateOnHash: true, + root : '/', + routes : [ + // -- / ---------------------------------------------------------------- + { + path : '/(index.html)?', + callbacks: defaultRoute + }, + + // -- /classes/* ------------------------------------------------------- + { + path : '/classes/:class.html*', + callbacks: [defaultRoute, 'handleClasses'] + }, + + // -- /files/* --------------------------------------------------------- + { + path : '/files/*file', + callbacks: [defaultRoute, 'handleFiles'] + }, + + // -- /modules/* ------------------------------------------------------- + { + path : '/modules/:module.html*', + callbacks: defaultRoute + } + ] +}); + +// -- Utility Functions -------------------------------------------------------- + +pjax.checkVisibility = function (tab) { + tab || (tab = selectedTab); + + if (!tab) { return; } + + var panelNode = tab.get('panelNode'), + visibleItems; + + // If no items are visible in the tab panel due to the current visibility + // settings, display a message to that effect. + visibleItems = panelNode.all('.item,.index-item').some(function (itemNode) { + if (itemNode.getComputedStyle('display') !== 'none') { + return true; + } + }); + + panelNode.all('.no-visible-items').remove(); + + if (!visibleItems) { + if (Y.one('#index .index-item')) { + panelNode.append( + '
    ' + + '

    ' + + 'Some items are not shown due to the current visibility ' + + 'settings. Use the checkboxes at the upper right of this ' + + 'page to change the visibility settings.' + + '

    ' + + '
    ' + ); + } else { + panelNode.append( + '
    ' + + '

    ' + + 'This class doesn\'t provide any methods, properties, ' + + 'attributes, or events.' + + '

    ' + + '
    ' + ); + } + } + + // Hide index sections without any visible items. + Y.all('.index-section').each(function (section) { + var items = 0, + visibleItems = 0; + + section.all('.index-item').each(function (itemNode) { + items += 1; + + if (itemNode.getComputedStyle('display') !== 'none') { + visibleItems += 1; + } + }); + + section.toggleClass('hidden', !visibleItems); + section.toggleClass('no-columns', visibleItems < 4); + }); +}; + +pjax.initClassTabView = function () { + if (!Y.all('#classdocs .api-class-tab').size()) { + return; + } + + if (classTabView) { + classTabView.destroy(); + selectedTab = null; + } + + classTabView = new Y.TabView({ + srcNode: '#classdocs', + + on: { + selectionChange: pjax.onTabSelectionChange + } + }); + + pjax.updateTabState(); + classTabView.render(); +}; + +pjax.initLineNumbers = function () { + var hash = win.location.hash.substring(1), + container = pjax.get('container'), + hasLines, node; + + // Add ids for each line number in the file source view. + container.all('.linenums>li').each(function (lineNode, index) { + lineNode.set('id', 'l' + (index + 1)); + lineNode.addClass('file-line'); + hasLines = true; + }); + + // Scroll to the desired line. + if (hasLines && /^l\d+$/.test(hash)) { + if ((node = container.getById(hash))) { + win.scroll(0, node.getY()); + } + } +}; + +pjax.initRoot = function () { + var terminators = /^(?:classes|files|modules)$/, + parts = pjax._getPathRoot().split('/'), + root = [], + i, len, part; + + for (i = 0, len = parts.length; i < len; i += 1) { + part = parts[i]; + + if (part.match(terminators)) { + // Makes sure the path will end with a "/". + root.push(''); + break; + } + + root.push(part); + } + + pjax.set('root', root.join('/')); +}; + +pjax.updateTabState = function (src) { + var hash = win.location.hash.substring(1), + defaultTab, node, tab, tabPanel; + + function scrollToNode() { + if (node.hasClass('protected')) { + Y.one('#api-show-protected').set('checked', true); + pjax.updateVisibility(); + } + + if (node.hasClass('private')) { + Y.one('#api-show-private').set('checked', true); + pjax.updateVisibility(); + } + + setTimeout(function () { + // For some reason, unless we re-get the node instance here, + // getY() always returns 0. + var node = Y.one('#classdocs').getById(hash); + win.scrollTo(0, node.getY() - 70); + }, 1); + } + + if (!classTabView) { + return; + } + + if (src === 'hashchange' && !hash) { + defaultTab = 'index'; + } else { + if (localStorage) { + defaultTab = localStorage.getItem('tab_' + pjax.getPath()) || + 'index'; + } else { + defaultTab = 'index'; + } + } + + if (hash && (node = Y.one('#classdocs').getById(hash))) { + if ((tabPanel = node.ancestor('.api-class-tabpanel', true))) { + if ((tab = Y.one('#classdocs .api-class-tab.' + tabPanel.get('id')))) { + if (classTabView.get('rendered')) { + Y.Widget.getByNode(tab).set('selected', 1); + } else { + tab.addClass('yui3-tab-selected'); + } + } + } + + // Scroll to the desired element if this is a hash URL. + if (node) { + if (classTabView.get('rendered')) { + scrollToNode(); + } else { + classTabView.once('renderedChange', scrollToNode); + } + } + } else { + tab = Y.one('#classdocs .api-class-tab.' + defaultTab); + + // When the `defaultTab` node isn't found, `localStorage` is stale. + if (!tab && defaultTab !== 'index') { + tab = Y.one('#classdocs .api-class-tab.index'); + } + + if (classTabView.get('rendered')) { + Y.Widget.getByNode(tab).set('selected', 1); + } else { + tab.addClass('yui3-tab-selected'); + } + } +}; + +pjax.updateVisibility = function () { + var container = pjax.get('container'); + + container.toggleClass('hide-inherited', + !Y.one('#api-show-inherited').get('checked')); + + container.toggleClass('show-deprecated', + Y.one('#api-show-deprecated').get('checked')); + + container.toggleClass('show-protected', + Y.one('#api-show-protected').get('checked')); + + container.toggleClass('show-private', + Y.one('#api-show-private').get('checked')); + + pjax.checkVisibility(); +}; + +// -- Route Handlers ----------------------------------------------------------- + +pjax.handleClasses = function (req, res, next) { + var status = res.ioResponse.status; + + // Handles success and local filesystem XHRs. + if (!status || (status >= 200 && status < 300)) { + pjax.initClassTabView(); + } + + next(); +}; + +pjax.handleFiles = function (req, res, next) { + var status = res.ioResponse.status; + + // Handles success and local filesystem XHRs. + if (!status || (status >= 200 && status < 300)) { + pjax.initLineNumbers(); + } + + next(); +}; + +// -- Event Handlers ----------------------------------------------------------- + +pjax.onNavigate = function (e) { + var hash = e.hash, + originTarget = e.originEvent && e.originEvent.target, + tab; + + if (hash) { + tab = originTarget && originTarget.ancestor('.yui3-tab', true); + + if (hash === win.location.hash) { + pjax.updateTabState('hashchange'); + } else if (!tab) { + win.location.hash = hash; + } + + e.preventDefault(); + return; + } + + // Only scroll to the top of the page when the URL doesn't have a hash. + this.set('scrollToTop', !e.url.match(/#.+$/)); + + bdNode.addClass('loading'); +}; + +pjax.onOptionClick = function (e) { + pjax.updateVisibility(); +}; + +pjax.onTabSelectionChange = function (e) { + var tab = e.newVal, + tabId = tab.get('contentBox').getAttribute('href').substring(1); + + selectedTab = tab; + + // If switching from a previous tab (i.e., this is not the default tab), + // replace the history entry with a hash URL that will cause this tab to + // be selected if the user navigates away and then returns using the back + // or forward buttons. + if (e.prevVal && localStorage) { + localStorage.setItem('tab_' + pjax.getPath(), tabId); + } + + pjax.checkVisibility(tab); +}; + +// -- Init --------------------------------------------------------------------- + +pjax.on('navigate', pjax.onNavigate); + +pjax.initRoot(); +pjax.upgrade(); +pjax.initClassTabView(); +pjax.initLineNumbers(); +pjax.updateVisibility(); + +Y.APIList.rootPath = pjax.get('root'); + +Y.one('#api-options').delegate('click', pjax.onOptionClick, 'input'); + +Y.on('hashchange', function (e) { + pjax.updateTabState('hashchange'); +}, win); + +}); diff --git a/Docs/API/assets/js/yui-prettify.js b/Docs/API/assets/js/yui-prettify.js new file mode 100644 index 00000000..18de8649 --- /dev/null +++ b/Docs/API/assets/js/yui-prettify.js @@ -0,0 +1,17 @@ +YUI().use('node', function(Y) { + var code = Y.all('.prettyprint.linenums'); + if (code.size()) { + code.each(function(c) { + var lis = c.all('ol li'), + l = 1; + lis.each(function(n) { + n.prepend(''); + l++; + }); + }); + var h = location.hash; + location.hash = ''; + h = h.replace('LINE_', 'LINENUM_'); + location.hash = h; + } +}); diff --git a/Docs/API/assets/vendor/prettify/CHANGES.html b/Docs/API/assets/vendor/prettify/CHANGES.html new file mode 100644 index 00000000..b50b8414 --- /dev/null +++ b/Docs/API/assets/vendor/prettify/CHANGES.html @@ -0,0 +1,130 @@ + + + + Change Log + + + README + +

    Known Issues

    + + +

    Change Log

    +

    29 March 2007

    + +

    4 Jul 2008

    + +

    5 Jul 2008

    +
    +

    14 Jul 2008

    + +

    6 Jan 2009

    + +

    21 May 2009

    + +

    14 August 2009

    + +

    3 October 2009

    + +

    19 July 2010

    + + + diff --git a/Docs/API/assets/vendor/prettify/COPYING b/Docs/API/assets/vendor/prettify/COPYING new file mode 100644 index 00000000..d6456956 --- /dev/null +++ b/Docs/API/assets/vendor/prettify/COPYING @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/Docs/API/assets/vendor/prettify/README.html b/Docs/API/assets/vendor/prettify/README.html new file mode 100644 index 00000000..c6fe1a32 --- /dev/null +++ b/Docs/API/assets/vendor/prettify/README.html @@ -0,0 +1,203 @@ + + + + + Javascript code prettifier + + + + + + + + + + Languages : CH +

    Javascript code prettifier

    + +

    Setup

    +
      +
    1. Download a distribution +
    2. Include the script and stylesheets in your document + (you will need to make sure the css and js file are on your server, and + adjust the paths in the script and link tag) +
      +<link href="prettify.css" type="text/css" rel="stylesheet" />
      +<script type="text/javascript" src="prettify.js"></script>
      +
    3. Add onload="prettyPrint()" to your + document's body tag. +
    4. Modify the stylesheet to get the coloring you prefer
    5. +
    + +

    Usage

    +

    Put code snippets in + <pre class="prettyprint">...</pre> + or <code class="prettyprint">...</code> + and it will automatically be pretty printed. + + + + +
    The original + Prettier +
    class Voila {
    +public:
    +  // Voila
    +  static const string VOILA = "Voila";
    +
    +  // will not interfere with embedded tags.
    +}
    + +
    class Voila {
    +public:
    +  // Voila
    +  static const string VOILA = "Voila";
    +
    +  // will not interfere with embedded tags.
    +}
    +
    + +

    FAQ

    +

    Which languages does it work for?

    +

    The comments in prettify.js are authoritative but the lexer + should work on a number of languages including C and friends, + Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, and Makefiles. + It works passably on Ruby, PHP, VB, and Awk and a decent subset of Perl + and Ruby, but, because of commenting conventions, doesn't work on + Smalltalk, or CAML-like languages.

    + +

    LISPy languages are supported via an extension: + lang-lisp.js.

    +

    And similarly for + CSS, + Haskell, + Lua, + OCAML, SML, F#, + Visual Basic, + SQL, + Protocol Buffers, and + WikiText.. + +

    If you'd like to add an extension for your favorite language, please + look at src/lang-lisp.js and file an + issue including your language extension, and a testcase.

    + +

    How do I specify which language my code is in?

    +

    You don't need to specify the language since prettyprint() + will guess. You can specify a language by specifying the language extension + along with the prettyprint class like so:

    +
    <pre class="prettyprint lang-html">
    +  The lang-* class specifies the language file extensions.
    +  File extensions supported by default include
    +    "bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html",
    +    "java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh",
    +    "xhtml", "xml", "xsl".
    +</pre>
    + +

    It doesn't work on <obfuscated code sample>?

    +

    Yes. Prettifying obfuscated code is like putting lipstick on a pig + — i.e. outside the scope of this tool.

    + +

    Which browsers does it work with?

    +

    It's been tested with IE 6, Firefox 1.5 & 2, and Safari 2.0.4. + Look at the test page to see if it + works in your browser.

    + +

    What's changed?

    +

    See the change log

    + +

    Why doesn't Prettyprinting of strings work on WordPress?

    +

    Apparently wordpress does "smart quoting" which changes close quotes. + This causes end quotes to not match up with open quotes. +

    This breaks prettifying as well as copying and pasting of code samples. + See + WordPress's help center for info on how to stop smart quoting of code + snippets.

    + +

    How do I put line numbers in my code?

    +

    You can use the linenums class to turn on line + numbering. If your code doesn't start at line number 1, you can + add a colon and a line number to the end of that class as in + linenums:52. + +

    For example +

    <pre class="prettyprint linenums:4"
    +>// This is line 4.
    +foo();
    +bar();
    +baz();
    +boo();
    +far();
    +faz();
    +<pre>
    + produces +
    // This is line 4.
    +foo();
    +bar();
    +baz();
    +boo();
    +far();
    +faz();
    +
    + +

    How do I prevent a portion of markup from being marked as code?

    +

    You can use the nocode class to identify a span of markup + that is not code. +

    <pre class=prettyprint>
    +int x = foo();  /* This is a comment  <span class="nocode">This is not code</span>
    +  Continuation of comment */
    +int y = bar();
    +</pre>
    +produces +
    +int x = foo();  /* This is a comment  This is not code
    +  Continuation of comment */
    +int y = bar();
    +
    + +

    For a more complete example see the issue22 + testcase.

    + +

    I get an error message "a is not a function" or "opt_whenDone is not a function"

    +

    If you are calling prettyPrint via an event handler, wrap it in a function. + Instead of doing +

    + addEventListener('load', prettyPrint, false); +
    + wrap it in a closure like +
    + addEventListener('load', function (event) { prettyPrint() }, false); +
    + so that the browser does not pass an event object to prettyPrint which + will confuse it. + +


    + + + + diff --git a/Docs/API/assets/vendor/prettify/prettify-min.css b/Docs/API/assets/vendor/prettify/prettify-min.css new file mode 100644 index 00000000..d44b3a22 --- /dev/null +++ b/Docs/API/assets/vendor/prettify/prettify-min.css @@ -0,0 +1 @@ +.pln{color:#000}@media screen{.str{color:#080}.kwd{color:#008}.com{color:#800}.typ{color:#606}.lit{color:#066}.pun,.opn,.clo{color:#660}.tag{color:#008}.atn{color:#606}.atv{color:#080}.dec,.var{color:#606}.fun{color:red}}@media print,projection{.str{color:#060}.kwd{color:#006;font-weight:bold}.com{color:#600;font-style:italic}.typ{color:#404;font-weight:bold}.lit{color:#044}.pun,.opn,.clo{color:#440}.tag{color:#006;font-weight:bold}.atn{color:#404}.atv{color:#060}}pre.prettyprint{padding:2px;border:1px solid #888}ol.linenums{margin-top:0;margin-bottom:0}li.L0,li.L1,li.L2,li.L3,li.L5,li.L6,li.L7,li.L8{list-style-type:none}li.L1,li.L3,li.L5,li.L7,li.L9{background:#eee} \ No newline at end of file diff --git a/Docs/API/assets/vendor/prettify/prettify-min.js b/Docs/API/assets/vendor/prettify/prettify-min.js new file mode 100644 index 00000000..4845d05d --- /dev/null +++ b/Docs/API/assets/vendor/prettify/prettify-min.js @@ -0,0 +1 @@ +window.PR_SHOULD_USE_CONTINUATION=true;var prettyPrintOne;var prettyPrint;(function(){var O=window;var j=["break,continue,do,else,for,if,return,while"];var v=[j,"auto,case,char,const,default,double,enum,extern,float,goto,int,long,register,short,signed,sizeof,static,struct,switch,typedef,union,unsigned,void,volatile"];var q=[v,"catch,class,delete,false,import,new,operator,private,protected,public,this,throw,true,try,typeof"];var m=[q,"alignof,align_union,asm,axiom,bool,concept,concept_map,const_cast,constexpr,decltype,dynamic_cast,explicit,export,friend,inline,late_check,mutable,namespace,nullptr,reinterpret_cast,static_assert,static_cast,template,typeid,typename,using,virtual,where"];var y=[q,"abstract,boolean,byte,extends,final,finally,implements,import,instanceof,null,native,package,strictfp,super,synchronized,throws,transient"];var T=[y,"as,base,by,checked,decimal,delegate,descending,dynamic,event,fixed,foreach,from,group,implicit,in,interface,internal,into,is,let,lock,object,out,override,orderby,params,partial,readonly,ref,sbyte,sealed,stackalloc,string,select,uint,ulong,unchecked,unsafe,ushort,var,virtual,where"];var s="all,and,by,catch,class,else,extends,false,finally,for,if,in,is,isnt,loop,new,no,not,null,of,off,on,or,return,super,then,throw,true,try,unless,until,when,while,yes";var x=[q,"debugger,eval,export,function,get,null,set,undefined,var,with,Infinity,NaN"];var t="caller,delete,die,do,dump,elsif,eval,exit,foreach,for,goto,if,import,last,local,my,next,no,our,print,package,redo,require,sub,undef,unless,until,use,wantarray,while,BEGIN,END";var J=[j,"and,as,assert,class,def,del,elif,except,exec,finally,from,global,import,in,is,lambda,nonlocal,not,or,pass,print,raise,try,with,yield,False,True,None"];var g=[j,"alias,and,begin,case,class,def,defined,elsif,end,ensure,false,in,module,next,nil,not,or,redo,rescue,retry,self,super,then,true,undef,unless,until,when,yield,BEGIN,END"];var I=[j,"case,done,elif,esac,eval,fi,function,in,local,set,then,until"];var B=[m,T,x,t+J,g,I];var f=/^(DIR|FILE|vector|(de|priority_)?queue|list|stack|(const_)?iterator|(multi)?(set|map)|bitset|u?(int|float)\d*)\b/;var D="str";var A="kwd";var k="com";var Q="typ";var H="lit";var M="pun";var G="pln";var n="tag";var F="dec";var K="src";var R="atn";var o="atv";var P="nocode";var N="(?:^^\\.?|[+-]|[!=]=?=?|\\#|%=?|&&?=?|\\(|\\*=?|[+\\-]=|->|\\/=?|::?|<>?>?=?|,|;|\\?|@|\\[|~|{|\\^\\^?=?|\\|\\|?=?|break|case|continue|delete|do|else|finally|instanceof|return|throw|try|typeof)\\s*";function l(ab){var af=0;var U=false;var ae=false;for(var X=0,W=ab.length;X122)){if(!(am<65||ai>90)){ah.push([Math.max(65,ai)|32,Math.min(am,90)|32])}if(!(am<97||ai>122)){ah.push([Math.max(97,ai)&~32,Math.min(am,122)&~32])}}}}ah.sort(function(aw,av){return(aw[0]-av[0])||(av[1]-aw[1])});var ak=[];var aq=[];for(var at=0;atau[0]){if(au[1]+1>au[0]){ao.push("-")}ao.push(V(au[1]))}}ao.push("]");return ao.join("")}function Y(an){var al=an.source.match(new RegExp("(?:\\[(?:[^\\x5C\\x5D]|\\\\[\\s\\S])*\\]|\\\\u[A-Fa-f0-9]{4}|\\\\x[A-Fa-f0-9]{2}|\\\\[0-9]+|\\\\[^ux0-9]|\\(\\?[:!=]|[\\(\\)\\^]|[^\\x5B\\x5C\\(\\)\\^]+)","g"));var aj=al.length;var ap=[];for(var am=0,ao=0;am=2&&ak==="["){al[am]=Z(ai)}else{if(ak!=="\\"){al[am]=ai.replace(/[a-zA-Z]/g,function(aq){var ar=aq.charCodeAt(0);return"["+String.fromCharCode(ar&~32,ar|32)+"]"})}}}}return al.join("")}var ac=[];for(var X=0,W=ab.length;X=0;){U[ae.charAt(ag)]=aa}}var ah=aa[1];var ac=""+ah;if(!ai.hasOwnProperty(ac)){aj.push(ah);ai[ac]=null}}aj.push(/[\0-\uffff]/);X=l(aj)})();var Z=V.length;var Y=function(aj){var ab=aj.sourceCode,aa=aj.basePos;var af=[aa,G];var ah=0;var ap=ab.match(X)||[];var al={};for(var ag=0,at=ap.length;ag=5&&"lang-"===ar.substring(0,5);if(ao&&!(ak&&typeof ak[1]==="string")){ao=false;ar=K}if(!ao){al[ai]=ar}}var ad=ah;ah+=ai.length;if(!ao){af.push(aa+ad,ar)}else{var an=ak[1];var am=ai.indexOf(an);var ae=am+an.length;if(ak[2]){ae=ai.length-ak[2].length;am=ae-an.length}var au=ar.substring(5);C(aa+ad,ai.substring(0,am),Y,af);C(aa+ad+am,an,r(au,an),af);C(aa+ad+ae,ai.substring(ae),Y,af)}}aj.decorations=af};return Y}function i(V){var Y=[],U=[];if(V.tripleQuotedStrings){Y.push([D,/^(?:\'\'\'(?:[^\'\\]|\\[\s\S]|\'{1,2}(?=[^\']))*(?:\'\'\'|$)|\"\"\"(?:[^\"\\]|\\[\s\S]|\"{1,2}(?=[^\"]))*(?:\"\"\"|$)|\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$))/,null,"'\""])}else{if(V.multiLineStrings){Y.push([D,/^(?:\'(?:[^\\\']|\\[\s\S])*(?:\'|$)|\"(?:[^\\\"]|\\[\s\S])*(?:\"|$)|\`(?:[^\\\`]|\\[\s\S])*(?:\`|$))/,null,"'\"`"])}else{Y.push([D,/^(?:\'(?:[^\\\'\r\n]|\\.)*(?:\'|$)|\"(?:[^\\\"\r\n]|\\.)*(?:\"|$))/,null,"\"'"])}}if(V.verbatimStrings){U.push([D,/^@\"(?:[^\"]|\"\")*(?:\"|$)/,null])}var ab=V.hashComments;if(ab){if(V.cStyleComments){if(ab>1){Y.push([k,/^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/,null,"#"])}else{Y.push([k,/^#(?:(?:define|e(?:l|nd)if|else|error|ifn?def|include|line|pragma|undef|warning)\b|[^\r\n]*)/,null,"#"])}U.push([D,/^<(?:(?:(?:\.\.\/)*|\/?)(?:[\w-]+(?:\/[\w-]+)+)?[\w-]+\.h(?:h|pp|\+\+)?|[a-z]\w*)>/,null])}else{Y.push([k,/^#[^\r\n]*/,null,"#"])}}if(V.cStyleComments){U.push([k,/^\/\/[^\r\n]*/,null]);U.push([k,/^\/\*[\s\S]*?(?:\*\/|$)/,null])}if(V.regexLiterals){var aa=("/(?=[^/*])(?:[^/\\x5B\\x5C]|\\x5C[\\s\\S]|\\x5B(?:[^\\x5C\\x5D]|\\x5C[\\s\\S])*(?:\\x5D|$))+/");U.push(["lang-regex",new RegExp("^"+N+"("+aa+")")])}var X=V.types;if(X){U.push([Q,X])}var W=(""+V.keywords).replace(/^ | $/g,"");if(W.length){U.push([A,new RegExp("^(?:"+W.replace(/[\s,]+/g,"|")+")\\b"),null])}Y.push([G,/^\s+/,null," \r\n\t\xA0"]);var Z=/^.[^\s\w\.$@\'\"\`\/\\]*/;U.push([H,/^@[a-z_$][a-z_$@0-9]*/i,null],[Q,/^(?:[@_]?[A-Z]+[a-z][A-Za-z_$@0-9]*|\w+_t\b)/,null],[G,/^[a-z_$][a-z_$@0-9]*/i,null],[H,new RegExp("^(?:0x[a-f0-9]+|(?:\\d(?:_\\d+)*\\d*(?:\\.\\d*)?|\\.\\d\\+)(?:e[+\\-]?\\d+)?)[a-z]*","i"),null,"0123456789"],[G,/^\\[\s\S]?/,null],[M,Z,null]);return h(Y,U)}var L=i({keywords:B,hashComments:true,cStyleComments:true,multiLineStrings:true,regexLiterals:true});function S(W,ah,aa){var V=/(?:^|\s)nocode(?:\s|$)/;var ac=/\r\n?|\n/;var ad=W.ownerDocument;var ag=ad.createElement("li");while(W.firstChild){ag.appendChild(W.firstChild)}var X=[ag];function af(am){switch(am.nodeType){case 1:if(V.test(am.className)){break}if("br"===am.nodeName){ae(am);if(am.parentNode){am.parentNode.removeChild(am)}}else{for(var ao=am.firstChild;ao;ao=ao.nextSibling){af(ao)}}break;case 3:case 4:if(aa){var an=am.nodeValue;var ak=an.match(ac);if(ak){var aj=an.substring(0,ak.index);am.nodeValue=aj;var ai=an.substring(ak.index+ak[0].length);if(ai){var al=am.parentNode;al.insertBefore(ad.createTextNode(ai),am.nextSibling)}ae(am);if(!aj){am.parentNode.removeChild(am)}}}break}}function ae(al){while(!al.nextSibling){al=al.parentNode;if(!al){return}}function aj(am,at){var ar=at?am.cloneNode(false):am;var ap=am.parentNode;if(ap){var aq=aj(ap,1);var ao=am.nextSibling;aq.appendChild(ar);for(var an=ao;an;an=ao){ao=an.nextSibling;aq.appendChild(an)}}return ar}var ai=aj(al.nextSibling,0);for(var ak;(ak=ai.parentNode)&&ak.nodeType===1;){ai=ak}X.push(ai)}for(var Z=0;Z=U){aj+=2}if(Y>=ar){ac+=2}}}finally{if(au){au.style.display=ak}}}var u={};function d(W,X){for(var U=X.length;--U>=0;){var V=X[U];if(!u.hasOwnProperty(V)){u[V]=W}else{if(O.console){console.warn("cannot override language handler %s",V)}}}}function r(V,U){if(!(V&&u.hasOwnProperty(V))){V=/^\s*]*(?:>|$)/],[k,/^<\!--[\s\S]*?(?:-\->|$)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],[M,/^(?:<[%?]|[%?]>)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i]]),["default-markup","htm","html","mxml","xhtml","xml","xsl"]);d(h([[G,/^[\s]+/,null," \t\r\n"],[o,/^(?:\"[^\"]*\"?|\'[^\']*\'?)/,null,"\"'"]],[[n,/^^<\/?[a-z](?:[\w.:-]*\w)?|\/?>$/i],[R,/^(?!style[\s=]|on)[a-z](?:[\w:-]*\w)?/i],["lang-uq.val",/^=\s*([^>\'\"\s]*(?:[^>\'\"\s\/]|\/(?=\s)))/],[M,/^[=<>\/]+/],["lang-js",/^on\w+\s*=\s*\"([^\"]+)\"/i],["lang-js",/^on\w+\s*=\s*\'([^\']+)\'/i],["lang-js",/^on\w+\s*=\s*([^\"\'>\s]+)/i],["lang-css",/^style\s*=\s*\"([^\"]+)\"/i],["lang-css",/^style\s*=\s*\'([^\']+)\'/i],["lang-css",/^style\s*=\s*([^\"\'>\s]+)/i]]),["in.tag"]);d(h([],[[o,/^[\s\S]+/]]),["uq.val"]);d(i({keywords:m,hashComments:true,cStyleComments:true,types:f}),["c","cc","cpp","cxx","cyc","m"]);d(i({keywords:"null,true,false"}),["json"]);d(i({keywords:T,hashComments:true,cStyleComments:true,verbatimStrings:true,types:f}),["cs"]);d(i({keywords:y,cStyleComments:true}),["java"]);d(i({keywords:I,hashComments:true,multiLineStrings:true}),["bsh","csh","sh"]);d(i({keywords:J,hashComments:true,multiLineStrings:true,tripleQuotedStrings:true}),["cv","py"]);d(i({keywords:t,hashComments:true,multiLineStrings:true,regexLiterals:true}),["perl","pl","pm"]);d(i({keywords:g,hashComments:true,multiLineStrings:true,regexLiterals:true}),["rb"]);d(i({keywords:x,cStyleComments:true,regexLiterals:true}),["js"]);d(i({keywords:s,hashComments:3,cStyleComments:true,multilineStrings:true,tripleQuotedStrings:true,regexLiterals:true}),["coffee"]);d(h([],[[D,/^[\s\S]+/]]),["regex"]);function e(X){var W=X.langExtension;try{var U=b(X.sourceNode,X.pre);var V=U.sourceCode;X.sourceCode=V;X.spans=U.spans;X.basePos=0;r(W,V)(X);E(X)}catch(Y){if(O.console){console.log(Y&&Y.stack?Y.stack:Y)}}}function z(Y,X,W){var U=document.createElement("pre");U.innerHTML=Y;if(W){S(U,W,true)}var V={langExtension:X,numberLines:W,sourceNode:U,pre:1};e(V);return U.innerHTML}function c(aj){function ab(al){return document.getElementsByTagName(al)}var ah=[ab("pre"),ab("code"),ab("xmp")];var V=[];for(var ae=0;ae]*(?:>|$)/],[PR.PR_COMMENT,/^<\!--[\s\S]*?(?:-\->|$)/],[PR.PR_PUNCTUATION,/^(?:<[%?]|[%?]>)/],["lang-",/^<\?([\s\S]+?)(?:\?>|$)/],["lang-",/^<%([\s\S]+?)(?:%>|$)/],["lang-",/^]*>([\s\S]+?)<\/xmp\b[^>]*>/i],["lang-handlebars",/^]*type\s*=\s*['"]?text\/x-handlebars-template['"]?\b[^>]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-js",/^]*>([\s\S]*?)(<\/script\b[^>]*>)/i],["lang-css",/^]*>([\s\S]*?)(<\/style\b[^>]*>)/i],["lang-in.tag",/^(<\/?[a-z][^<>]*>)/i],[PR.PR_DECLARATION,/^{{[#^>/]?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{&?\s*[\w.][^}]*}}/],[PR.PR_DECLARATION,/^{{{>?\s*[\w.][^}]*}}}/],[PR.PR_COMMENT,/^{{![^}]*}}/]]),["handlebars","hbs"]);PR.registerLangHandler(PR.createSimpleLexer([[PR.PR_PLAIN,/^[ \t\r\n\f]+/,null," \t\r\n\f"]],[[PR.PR_STRING,/^\"(?:[^\n\r\f\\\"]|\\(?:\r\n?|\n|\f)|\\[\s\S])*\"/,null],[PR.PR_STRING,/^\'(?:[^\n\r\f\\\']|\\(?:\r\n?|\n|\f)|\\[\s\S])*\'/,null],["lang-css-str",/^url\(([^\)\"\']*)\)/i],[PR.PR_KEYWORD,/^(?:url|rgb|\!important|@import|@page|@media|@charset|inherit)(?=[^\-\w]|$)/i,null],["lang-css-kw",/^(-?(?:[_a-z]|(?:\\[0-9a-f]+ ?))(?:[_a-z0-9\-]|\\(?:\\[0-9a-f]+ ?))*)\s*:/i],[PR.PR_COMMENT,/^\/\*[^*]*\*+(?:[^\/*][^*]*\*+)*\//],[PR.PR_COMMENT,/^(?:)/],[PR.PR_LITERAL,/^(?:\d+|\d*\.\d+)(?:%|[a-z]+)?/i],[PR.PR_LITERAL,/^#(?:[0-9a-f]{3}){1,2}/i],[PR.PR_PLAIN,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i],[PR.PR_PUNCTUATION,/^[^\s\w\'\"]+/]]),["css"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_KEYWORD,/^-?(?:[_a-z]|(?:\\[\da-f]+ ?))(?:[_a-z\d\-]|\\(?:\\[\da-f]+ ?))*/i]]),["css-kw"]);PR.registerLangHandler(PR.createSimpleLexer([],[[PR.PR_STRING,/^[^\)\"\']+/]]),["css-str"]); \ No newline at end of file diff --git a/Docs/API/classes/TimeManager.html b/Docs/API/classes/TimeManager.html new file mode 100644 index 00000000..07505d5b --- /dev/null +++ b/Docs/API/classes/TimeManager.html @@ -0,0 +1,1744 @@ + + + + + TimeManager - Phaser + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.0.0 +
    +
    +
    + +
    + +
    +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    TimeManager Class

    +
    + + + + + + + + + + + Module: Phaser + + + + +
    + + + +
    +

    This is the core internal game clock. It manages the elapsed time and calculation of delta values, +used for game object motion and tweens.

    + +
    + + +
    +

    Constructor

    +
    +

    TimeManager

    + + +
    + (
      + +
    • + + game + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:13 + +

    + + + + + +
    + +
    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + game + Phaser.Game + + + + +
      +

      A reference to the currently running game.

      + +
      + + +
    • + +
    +
    + + + + + +
    + +
    + + +
    + + +
    +
    +

    Item Index

    + + +
    +

    Methods

    + + +
    + + + +
    +

    Properties

    + + +
    + + + + + +
    + + +
    +

    Methods

    + + +
    +

    elapsedSecondsSince

    + + +
    + (
      + +
    • + + since + +
    • + +
    ) +
    + + + + + Number + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:239 + +

    + + + + + +
    + +
    +

    How long has passed since the given time (in seconds).

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + since + Number + + + + +
      +

      The time you want to measure (in seconds).

      + +
      + + +
    • + +
    +
    + + + +
    +

    Returns:

    + +
    + + + Number: + +

    Duration between given time and now (in seconds).

    + + +
    +
    + + + +
    + + +
    +

    elapsedSince

    + + +
    + (
      + +
    • + + since + +
    • + +
    ) +
    + + + + + Number + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:227 + +

    + + + + + +
    + +
    +

    How long has passed since the given time.

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + since + Number + + + + +
      +

      The time you want to measure against.

      + +
      + + +
    • + +
    +
    + + + +
    +

    Returns:

    + +
    + + + Number: + +

    The difference between the given time and now.

    + + +
    +
    + + + +
    + + +
    +

    gamePaused

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:192 + +

    + + + + + +
    + +
    +

    Called when the game enters a paused state.

    + +
    + + + + + + +
    + + +
    +

    gameResumed

    + + + () + + + + + + + + private + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:201 + +

    + + + + + +
    + +
    +

    Called when the game resumes from a paused state.

    + +
    + + + + + + +
    + + +
    +

    reset

    + + + () + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:251 + +

    + + + + + +
    + +
    +

    Resets the private _started value to now.

    + +
    + + + + + + +
    + + +
    +

    totalElapsedSeconds

    + + + () + + + + + Number + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:89 + +

    + + + + + +
    + +
    +

    The number of seconds that have elapsed since the game was started.

    + +
    + + + + +
    +

    Returns:

    + +
    + + + Number: + + +
    +
    + + + +
    + + +
    +

    update

    + + +
    + (
      + +
    • + + raf + +
    • + +
    ) +
    + + + + + + + + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:156 + +

    + + + + + +
    + +
    +

    Update clock and calculate the fps. +This is called automatically by Game._raf

    + +
    + + +
    +

    Parameters:

    + +
      + +
    • + + raf + Number + + + + +
      +

      The current timestamp, either performance.now or Date.now

      + +
      + + +
    • + +
    +
    + + + + + +
    + + +
    + + + +
    +

    Properties

    + + +
    +

    _pauseStarted

    + Number + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:219 + +

    + + + + +
    + +
    +

    The time the game started being paused.

    + +
    + + + + + + +
    + + +
    +

    _started

    + Number + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:41 + +

    + + + + +
    + +
    +

    The time at which the Game instance started.

    + +
    + + + + + + +
    + + +
    +

    _timeLastSecond

    + Number + + + + + private + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:148 + +

    + + + + +
    + +
    +

    The time (in ms) that the last second counter ticked over.

    + +
    + + + + + + +
    + + +
    +

    delta

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:81 + +

    + + + + +
    + +
    +

    Elapsed time since the last frame.

    + +
    + + + + + + +
    + + +
    +

    elapsed

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:49 + +

    + + + + +
    + +
    +

    Number of milliseconds elapsed since the last frame update.

    + +
    + + + + + + +
    + + +
    +

    fps

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:100 + +

    + + + + +
    + +
    +

    Frames per second.

    + +
    + + + + + + +
    + + +
    +

    fpsMax

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:116 + +

    + + + + +
    + +
    +

    The highest rate the fps has reached (usually no higher than 60fps).

    + +
    + + + + + + +
    + + +
    +

    fpsMin

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:108 + +

    + + + + +
    + +
    +

    The lowest rate the fps has dropped to.

    + +
    + + + + + + +
    + + +
    +

    frames

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:140 + +

    + + + + +
    + +
    +

    The number of frames record in the last second.

    + +
    + + + + + + +
    + + +
    +

    game

    + Phaser.Game + + + + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:34 + +

    + + + + +
    + +
    +

    A reference to the currently running Game.

    + +
    + + + + + + +
    + + +
    +

    msMax

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:132 + +

    + + + + +
    + +
    +

    The maximum amount of time the game has taken between two frames.

    + +
    + + + + + + +
    + + +
    +

    msMin

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:124 + +

    + + + + +
    + +
    +

    The minimum amount of time the game has taken between two frames.

    + +
    + + + + + + +
    + + +
    +

    now

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:73 + +

    + + + + +
    + +
    +

    The time right now.

    + +
    + + + + + + +
    + + +
    +

    pausedTime

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:65 + +

    + + + + +
    + +
    +

    Records how long the game has been paused for. Is reset each time the game pauses.

    + +
    + + + + + + +
    + + +
    +

    pauseDuration

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:211 + +

    + + + + +
    + +
    +

    Records how long the game was paused for in miliseconds.

    + +
    + + + + + + +
    + + +
    +

    time

    + Number + + + + + public + + + + + + +
    + + + +

    + + Defined in + + + + + ..\Phaser\time\TimeManager.ts:57 + +

    + + + + +
    + +
    +

    Game time counter.

    + +
    + + + + + + +
    + + +
    + + + + + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/Docs/API/data.json b/Docs/API/data.json new file mode 100644 index 00000000..3e65bc60 --- /dev/null +++ b/Docs/API/data.json @@ -0,0 +1,364 @@ +{ + "project": { + "name": "Phaser", + "description": "HTML5 Game Framework", + "version": "1.0.0", + "url": "http://www.phaser.io/" + }, + "files": { + "..\\Phaser\\time\\TimeManager.ts": { + "name": "..\\Phaser\\time\\TimeManager.ts", + "modules": { + "Phaser": 1 + }, + "classes": { + "TimeManager": 1 + }, + "fors": {}, + "namespaces": {} + } + }, + "modules": { + "Phaser": { + "name": "Phaser", + "submodules": {}, + "classes": { + "TimeManager": 1 + }, + "fors": {}, + "namespaces": {}, + "tag": "module", + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 13, + "author": "Richard Davey ", + "copyright": "2013 Photon Storm Ltd.", + "license": "https://github.com/photonstorm/phaser/blob/master/license.txt MIT License" + } + }, + "classes": { + "TimeManager": { + "name": "TimeManager", + "shortname": "TimeManager", + "classitems": [], + "plugins": [], + "extensions": [], + "plugin_for": [], + "extension_for": [], + "module": "Phaser", + "namespace": "", + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 13, + "description": "This is the core internal game clock. It manages the elapsed time and calculation of delta values,\nused for game object motion and tweens.", + "is_constructor": 1, + "params": [ + { + "name": "game", + "description": "A reference to the currently running game.", + "type": "Phaser.Game" + } + ] + } + }, + "classitems": [ + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 34, + "description": "A reference to the currently running Game.", + "itemtype": "property", + "name": "game", + "type": "{Phaser.Game}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 41, + "description": "The time at which the Game instance started.", + "itemtype": "property", + "name": "_started", + "access": "private", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 49, + "description": "Number of milliseconds elapsed since the last frame update.", + "itemtype": "property", + "name": "elapsed", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 57, + "description": "Game time counter.", + "itemtype": "property", + "name": "time", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 65, + "description": "Records how long the game has been paused for. Is reset each time the game pauses.", + "itemtype": "property", + "name": "pausedTime", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 73, + "description": "The time right now.", + "itemtype": "property", + "name": "now", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 81, + "description": "Elapsed time since the last frame.", + "itemtype": "property", + "name": "delta", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 89, + "description": "The number of seconds that have elapsed since the game was started.", + "itemtype": "method", + "name": "totalElapsedSeconds", + "return": { + "description": "", + "type": "Number" + }, + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 100, + "description": "Frames per second.", + "itemtype": "property", + "name": "fps", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 108, + "description": "The lowest rate the fps has dropped to.", + "itemtype": "property", + "name": "fpsMin", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 116, + "description": "The highest rate the fps has reached (usually no higher than 60fps).", + "itemtype": "property", + "name": "fpsMax", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 124, + "description": "The minimum amount of time the game has taken between two frames.", + "itemtype": "property", + "name": "msMin", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 132, + "description": "The maximum amount of time the game has taken between two frames.", + "itemtype": "property", + "name": "msMax", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 140, + "description": "The number of frames record in the last second.", + "itemtype": "property", + "name": "frames", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 148, + "description": "The time (in ms) that the last second counter ticked over.", + "itemtype": "property", + "name": "_timeLastSecond", + "access": "private", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 156, + "description": "Update clock and calculate the fps.\nThis is called automatically by Game._raf", + "itemtype": "method", + "name": "update", + "params": [ + { + "name": "raf", + "description": "The current timestamp, either performance.now or Date.now", + "type": "Number" + } + ], + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 192, + "description": "Called when the game enters a paused state.", + "itemtype": "method", + "name": "gamePaused", + "access": "private", + "tagname": "", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 201, + "description": "Called when the game resumes from a paused state.", + "itemtype": "method", + "name": "gameResumed", + "access": "private", + "tagname": "", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 211, + "description": "Records how long the game was paused for in miliseconds.", + "itemtype": "property", + "name": "pauseDuration", + "access": "public", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 219, + "description": "The time the game started being paused.", + "itemtype": "property", + "name": "_pauseStarted", + "access": "private", + "tagname": "", + "type": "{Number}", + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 227, + "description": "How long has passed since the given time.", + "itemtype": "method", + "name": "elapsedSince", + "params": [ + { + "name": "since", + "description": "The time you want to measure against.", + "type": "Number" + } + ], + "return": { + "description": "The difference between the given time and now.", + "type": "Number" + }, + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 239, + "description": "How long has passed since the given time (in seconds).", + "itemtype": "method", + "name": "elapsedSecondsSince", + "params": [ + { + "name": "since", + "description": "The time you want to measure (in seconds).", + "type": "Number" + } + ], + "return": { + "description": "Duration between given time and now (in seconds).", + "type": "Number" + }, + "class": "TimeManager", + "module": "Phaser" + }, + { + "file": "..\\Phaser\\time\\TimeManager.ts", + "line": 251, + "description": "Resets the private _started value to now.", + "itemtype": "method", + "name": "reset", + "class": "TimeManager", + "module": "Phaser" + } + ], + "warnings": [ + { + "message": "unknown tag: copyright", + "line": " ..\\Phaser\\time\\TimeManager.ts:3" + }, + { + "message": "unknown tag: license", + "line": " ..\\Phaser\\time\\TimeManager.ts:3" + } + ] +} \ No newline at end of file diff --git a/Docs/API/files/.._Phaser_time_TimeManager.ts.html b/Docs/API/files/.._Phaser_time_TimeManager.ts.html new file mode 100644 index 00000000..f38ce3ec --- /dev/null +++ b/Docs/API/files/.._Phaser_time_TimeManager.ts.html @@ -0,0 +1,372 @@ + + + + + ..\Phaser\time\TimeManager.ts - Phaser + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.0.0 +
    +
    +
    + +
    + +
    +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    File: ..\Phaser\time\TimeManager.ts

    + +
    +
    +/// <reference path="../_definitions.ts" />
    +
    +/**
    +* @author       Richard Davey <rich@photonstorm.com>
    +* @copyright    2013 Photon Storm Ltd.
    +* @license      https://github.com/photonstorm/phaser/blob/master/license.txt  MIT License
    +* @module       Phaser
    +*/
    +module Phaser {
    +
    +    export class TimeManager {
    +
    +        /**
    +        * This is the core internal game clock. It manages the elapsed time and calculation of delta values,
    +        * used for game object motion and tweens.
    +        *
    +        * @class TimeManager
    +        * @constructor
    +        * @param {Phaser.Game} game A reference to the currently running game.
    +        */
    +        constructor(game: Phaser.Game) {
    +
    +            this.game = game;
    +
    +            this._started = 0;
    +            this._timeLastSecond = this._started;
    +            this.time = this._started;
    +
    +            this.game.onPause.add(this.gamePaused, this);
    +            this.game.onResume.add(this.gameResumed, this);
    +
    +        }
    +
    +        /**
    +        * A reference to the currently running Game.
    +        * @property game
    +        * @type {Phaser.Game}
    +        */
    +        public game: Phaser.Game;
    +
    +        /**
    +        * The time at which the Game instance started.
    +        * @property _started
    +        * @private
    +        * @type {Number}
    +        */
    +        private _started: number;
    +
    +        /**
    +        * Number of milliseconds elapsed since the last frame update.
    +        * @property elapsed
    +        * @public
    +        * @type {Number}
    +        */
    +        public elapsed: number = 0;
    +
    +        /**
    +        * Game time counter.
    +        * @property time
    +        * @public
    +        * @type {Number}
    +        */
    +        public time: number = 0;
    +
    +        /**
    +        * Records how long the game has been paused for. Is reset each time the game pauses.
    +        * @property pausedTime
    +        * @public
    +        * @type {Number}
    +        */
    +        public pausedTime: number = 0;
    +
    +        /**
    +        * The time right now.
    +        * @property now
    +        * @public
    +        * @type {Number}
    +        */
    +        public now: number = 0;
    +
    +        /**
    +        * Elapsed time since the last frame.
    +        * @property delta
    +        * @public
    +        * @type {Number}
    +        */
    +        public delta: number = 0;
    +
    +        /**
    +        * The number of seconds that have elapsed since the game was started.
    +        * @method totalElapsedSeconds
    +        * @return {Number}
    +        */
    +        public get totalElapsedSeconds(): number {
    +
    +            return (this.now - this._started) * 0.001;
    +
    +        }
    +
    +        /**
    +        * Frames per second.
    +        * @property fps
    +        * @public
    +        * @type {Number}
    +        */
    +        public fps: number = 0;
    +
    +        /**
    +        * The lowest rate the fps has dropped to.
    +        * @property fpsMin
    +        * @public
    +        * @type {Number}
    +        */
    +        public fpsMin: number = 1000;
    +
    +        /**
    +        * The highest rate the fps has reached (usually no higher than 60fps).
    +        * @property fpsMax
    +        * @public
    +        * @type {Number}
    +        */
    +        public fpsMax: number = 0;
    +
    +        /**
    +        * The minimum amount of time the game has taken between two frames.
    +        * @property msMin
    +        * @public
    +        * @type {Number}
    +        */
    +        public msMin: number = 1000;
    +
    +        /**
    +        * The maximum amount of time the game has taken between two frames.
    +        * @property msMax
    +        * @public
    +        * @type {Number}
    +        */
    +        public msMax: number = 0;
    +
    +        /**
    +        * The number of frames record in the last second.
    +        * @property frames
    +        * @public
    +        * @type {Number}
    +        */
    +        public frames: number = 0;
    +
    +        /**
    +        * The time (in ms) that the last second counter ticked over.
    +        * @property _timeLastSecond
    +        * @private
    +        * @type {Number}
    +        */
    +        private _timeLastSecond: number = 0;
    +
    +        /**
    +         * Update clock and calculate the fps.
    +         * This is called automatically by Game._raf
    +         * @method update
    +         * @param {Number} raf The current timestamp, either performance.now or Date.now
    +         */
    +        public update(raf: number) {
    +
    +            this.now = raf; // mark
    +            this.delta = this.now - this.time; // elapsedMS
    +
    +            this.msMin = Math.min(this.msMin, this.delta);
    +            this.msMax = Math.max(this.msMax, this.delta);
    +
    +            this.frames++;
    +
    +            if (this.now > this._timeLastSecond + 1000)
    +            {
    +                this.fps = Math.round((this.frames * 1000) / (this.now - this._timeLastSecond));
    +                this.fpsMin = Math.min(this.fpsMin, this.fps);
    +                this.fpsMax = Math.max(this.fpsMax, this.fps);
    +
    +                this._timeLastSecond = this.now;
    +                this.frames = 0;
    +            }
    +
    +            this.time = this.now; // _total
    +
    +            //  Paused?
    +            if (this.game.paused)
    +            {
    +                this.pausedTime = this.now - this._pauseStarted;
    +            }
    +
    +        }
    +
    +        /**
    +        * Called when the game enters a paused state.
    +        * @method gamePaused
    +        * @private
    +        */
    +        private gamePaused() {
    +            this._pauseStarted = this.now;
    +        }
    +
    +        /**
    +        * Called when the game resumes from a paused state.
    +        * @method gameResumed
    +        * @private
    +        */
    +        private gameResumed() {
    +            //  Level out the delta timer to avoid spikes
    +            this.pauseDuration = this.pausedTime;
    +        }
    +
    +        /**
    +        * Records how long the game was paused for in miliseconds.
    +        * @property pauseDuration
    +        * @public
    +        * @type {Number}
    +        */
    +        public pauseDuration: number = 0;
    +
    +        /**
    +        * The time the game started being paused.
    +        * @property _pauseStarted
    +        * @private
    +        * @type {Number}
    +        */
    +        private _pauseStarted: number = 0;
    +
    +        /**
    +        * How long has passed since the given time.
    +        * @method elapsedSince
    +        * @param {Number} since The time you want to measure against.
    +        * @return {Number} The difference between the given time and now.
    +        */
    +        public elapsedSince(since: number): number {
    +
    +            return this.now - since;
    +
    +        }
    +
    +        /**
    +        * How long has passed since the given time (in seconds).
    +        * @method elapsedSecondsSince
    +        * @param {Number} since The time you want to measure (in seconds).
    +        * @return {Number} Duration between given time and now (in seconds).
    +        */
    +        public elapsedSecondsSince(since: number): number {
    +
    +            return (this.now - since) * 0.001;
    +
    +        }
    +
    +        /**
    +        * Resets the private _started value to now.
    +        * @method reset
    +        */
    +        public reset() {
    +
    +            this._started = this.now;
    +
    +        }
    +
    +    }
    +
    +}
    +    
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/Docs/API/index.html b/Docs/API/index.html new file mode 100644 index 00000000..ca852ea6 --- /dev/null +++ b/Docs/API/index.html @@ -0,0 +1,124 @@ + + + + + Phaser + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.0.0 +
    +
    +
    + +
    + +
    +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +
    +
    +

    + Browse to a module or class using the sidebar to view its API documentation. +

    + +

    Keyboard Shortcuts

    + +
      +
    • Press s to focus the API search box.

    • + +
    • Use Up and Down to select classes, modules, and search results.

    • + +
    • With the API search box or sidebar focused, use -Left or -Right to switch sidebar tabs.

    • + +
    • With the API search box or sidebar focused, use Ctrl+Left and Ctrl+Right to switch sidebar tabs.

    • +
    +
    +
    + + + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/Docs/API/modules/Phaser.html b/Docs/API/modules/Phaser.html new file mode 100644 index 00000000..d6337ff1 --- /dev/null +++ b/Docs/API/modules/Phaser.html @@ -0,0 +1,147 @@ + + + + + Phaser - Phaser + + + + + + + + +
    +
    +
    + +

    + +
    +
    + API Docs for: 1.0.0 +
    +
    +
    + +
    + +
    +
    +
    + Show: + + + + + + + +
    + + +
    +
    +
    +

    Phaser Module

    +
    + + + + + + + + + +
    + + + +
    + +
    + + + +
    +
    + +

    This module provides the following classes:

    + + + +
    + +
    + +
    +
    + +
    +
    +
    +
    +
    +
    + + + + + + + + + + diff --git a/Docs/logo/PHASER logotype vector 02.fla b/Docs/Phaser Logo/PHASER logotype vector 02.fla similarity index 100% rename from Docs/logo/PHASER logotype vector 02.fla rename to Docs/Phaser Logo/PHASER logotype vector 02.fla diff --git a/Docs/phaser logo sprite.gif b/Docs/Phaser Logo/phaser logo sprite.gif similarity index 100% rename from Docs/phaser logo sprite.gif rename to Docs/Phaser Logo/phaser logo sprite.gif diff --git a/Docs/logo/phaser space paint 08.png b/Docs/Phaser Logo/phaser space paint 08.png similarity index 100% rename from Docs/logo/phaser space paint 08.png rename to Docs/Phaser Logo/phaser space paint 08.png diff --git a/Docs/logo/phaser vector final.eps b/Docs/Phaser Logo/phaser vector final.eps similarity index 100% rename from Docs/logo/phaser vector final.eps rename to Docs/Phaser Logo/phaser vector final.eps diff --git a/Docs/logo/phaser vector final.fla b/Docs/Phaser Logo/phaser vector final.fla similarity index 100% rename from Docs/logo/phaser vector final.fla rename to Docs/Phaser Logo/phaser vector final.fla diff --git a/Docs/logo/phaser vector final.png b/Docs/Phaser Logo/phaser vector final.png similarity index 100% rename from Docs/logo/phaser vector final.png rename to Docs/Phaser Logo/phaser vector final.png diff --git a/Docs/phaserSprite.gif b/Docs/Phaser Logo/phaserSprite.gif similarity index 100% rename from Docs/phaserSprite.gif rename to Docs/Phaser Logo/phaserSprite.gif diff --git a/Docs/phaserWIP4.png b/Docs/Phaser Logo/phaserWIP4.png similarity index 100% rename from Docs/phaserWIP4.png rename to Docs/Phaser Logo/phaserWIP4.png diff --git a/Docs/phaser_logo.png b/Docs/Phaser Logo/phaser_logo.png similarity index 100% rename from Docs/phaser_logo.png rename to Docs/Phaser Logo/phaser_logo.png diff --git a/Docs/game art/avoid-digits.png b/Docs/Resources/avoid-digits.png similarity index 100% rename from Docs/game art/avoid-digits.png rename to Docs/Resources/avoid-digits.png diff --git a/Docs/game art/avoid-panel.png b/Docs/Resources/avoid-panel.png similarity index 100% rename from Docs/game art/avoid-panel.png rename to Docs/Resources/avoid-panel.png diff --git a/Docs/game art/avoid-sheet.png b/Docs/Resources/avoid-sheet.png similarity index 100% rename from Docs/game art/avoid-sheet.png rename to Docs/Resources/avoid-sheet.png diff --git a/Docs/game art/avoidmock4x2.png b/Docs/Resources/avoidmock4x2.png similarity index 100% rename from Docs/game art/avoidmock4x2.png rename to Docs/Resources/avoidmock4x2.png diff --git a/Docs/box-01.png b/Docs/Resources/box-01.png similarity index 100% rename from Docs/box-01.png rename to Docs/Resources/box-01.png diff --git a/Docs/box-02.png b/Docs/Resources/box-02.png similarity index 100% rename from Docs/box-02.png rename to Docs/Resources/box-02.png diff --git a/Docs/phaser checkboxes.gif b/Docs/Resources/phaser checkboxes.gif similarity index 100% rename from Docs/phaser checkboxes.gif rename to Docs/Resources/phaser checkboxes.gif diff --git a/Docs/phaser power tools.gif b/Docs/Resources/phaser power tools.gif similarity index 100% rename from Docs/phaser power tools.gif rename to Docs/Resources/phaser power tools.gif diff --git a/Docs/phaser_balls.png b/Docs/Screen Shots/phaser_balls.png similarity index 100% rename from Docs/phaser_balls.png rename to Docs/Screen Shots/phaser_balls.png diff --git a/Docs/phaser_blaster.png b/Docs/Screen Shots/phaser_blaster.png similarity index 100% rename from Docs/phaser_blaster.png rename to Docs/Screen Shots/phaser_blaster.png diff --git a/Docs/phaser_cams.png b/Docs/Screen Shots/phaser_cams.png similarity index 100% rename from Docs/phaser_cams.png rename to Docs/Screen Shots/phaser_cams.png diff --git a/Docs/phaser_desert.png b/Docs/Screen Shots/phaser_desert.png similarity index 100% rename from Docs/phaser_desert.png rename to Docs/Screen Shots/phaser_desert.png diff --git a/Docs/phaser_fruit_particles.png b/Docs/Screen Shots/phaser_fruit_particles.png similarity index 100% rename from Docs/phaser_fruit_particles.png rename to Docs/Screen Shots/phaser_fruit_particles.png diff --git a/Docs/phaser_mapdraw.png b/Docs/Screen Shots/phaser_mapdraw.png similarity index 100% rename from Docs/phaser_mapdraw.png rename to Docs/Screen Shots/phaser_mapdraw.png diff --git a/Docs/phaser_particles.png b/Docs/Screen Shots/phaser_particles.png similarity index 100% rename from Docs/phaser_particles.png rename to Docs/Screen Shots/phaser_particles.png diff --git a/Docs/phaser_rotate4.png b/Docs/Screen Shots/phaser_rotate4.png similarity index 100% rename from Docs/phaser_rotate4.png rename to Docs/Screen Shots/phaser_rotate4.png diff --git a/Docs/phaser_scrollfactor.png b/Docs/Screen Shots/phaser_scrollfactor.png similarity index 100% rename from Docs/phaser_scrollfactor.png rename to Docs/Screen Shots/phaser_scrollfactor.png diff --git a/Docs/phaser_tilemap.png b/Docs/Screen Shots/phaser_tilemap.png similarity index 100% rename from Docs/phaser_tilemap.png rename to Docs/Screen Shots/phaser_tilemap.png diff --git a/Docs/phaser_tilemap_collision.png b/Docs/Screen Shots/phaser_tilemap_collision.png similarity index 100% rename from Docs/phaser_tilemap_collision.png rename to Docs/Screen Shots/phaser_tilemap_collision.png diff --git a/Docs/Physics Comparison.xlsx b/Docs/WIP/Physics Comparison.xlsx similarity index 100% rename from Docs/Physics Comparison.xlsx rename to Docs/WIP/Physics Comparison.xlsx diff --git a/Docs/phaser_copy.doc b/Docs/WIP/phaser_copy.doc similarity index 100% rename from Docs/phaser_copy.doc rename to Docs/WIP/phaser_copy.doc diff --git a/Docs/docs_build.bat b/Docs/docs_build.bat new file mode 100644 index 00000000..95cc9ce7 --- /dev/null +++ b/Docs/docs_build.bat @@ -0,0 +1 @@ +yuidoc -c ../Phaser/yuidoc.json -o API/ -t yuidoc-theme-dana -e .ts ../Phaser/time \ No newline at end of file diff --git a/Docs/docs_server.bat b/Docs/docs_server.bat new file mode 100644 index 00000000..05d5d3d6 --- /dev/null +++ b/Docs/docs_server.bat @@ -0,0 +1 @@ +yuidoc -n -e .ts --server 3000 ../Phaser/time \ No newline at end of file diff --git a/Docs/tags.txt b/Docs/tags.txt index dbaeb250..ff212b63 100644 --- a/Docs/tags.txt +++ b/Docs/tags.txt @@ -1,145 +1,48 @@ /** - * Name - * - * Long description - * - * @package Phaser. - * @author Richard Davey - * @copyright 2013 Photon Storm Ltd. - * @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License - */ +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser +*/ +/** +* The class constructor +* +* @class Name +* @constructor +* @param {Phaser.Game} game A reference to the currently running game. +*/ + +/** +* A reference to the currently running Game. +* @property game +* @type {Phaser.Game} +*/ +public game: Phaser.Game; + +/** +* My method description. Like other pieces of your comment blocks, +* this can span multiple lines. +* +* @method methodName +* @param {String} foo Argument 1 +* @param {Object} config A config object +* @param {String} config.name The name on the config object +* @param {Function} config.callback A callback function on the config object +* @param {Boolean} [extra=false] Do extra, optional work +* @return {Boolean} Returns true on success +*/ + +/** +* My property description. Like other pieces of your comment blocks, +* this can span multiple lines. +* +* @property propertyName +* @public +* @type {Object} +* @default "foo" +*/ @param {Type} Name Description Object, Array, String, Boolean, Number, Mixed, MyType -@module Phaser.Components - -@class Animation -@constructor - -@event signal details here -@param {Type} paramName - -/** - * Property description - * @property game - * @type Phaser.Game - * @protected / @public / @private - * @static - * @default - */ - -@default could be: - -@default {object: 0, blah: 1} -@default Boolean - -/** - * Description of the method - * @method blahBlah - * @param {Type} name The description - * @return {Type} the description - */ - - -@abstract -This member must be implemented (or overridden) by the inheritor. - -@access -Specify the access level of this member - private, public, or protected. - -@author -Identify the author of an item. - -@callback -Document a callback function. - -@classdesc -Use the following text to describe the entire class. - -@constant -Document an object as a constant. - -@constructor -This function is intended to be called with the "new" keyword. - -@copyright -Document some copyright information. - -@default -Document the default value. - -@deprecated -Document that this is no longer the preferred way. - -@desc -Describe a symbol. - -@enum -Document a collection of related properties. - -@event -Document an event. - -@example -Provide an example of how to use a documented item. - -@link -Inline tag - create a link. -@member -Document a member. -@memberof -This symbol belongs to a parent symbol. -@method -Describe a method or function. -@mixes -This object mixes in all the members from another object. -@mixin -Document a mixin object. -@module -Document a JavaScript module. -@name -Document the name of an object. -@namespace -Document a namespace object. -@param -Document the parameter to a function. -@private -This symbol is meant to be private. -@property -Document a property of an object. -@protected -This member is meant to be protected. -@public -This symbol is meant to be public. -@readonly -This symbol is meant to be read-only. -@requires -This file requires a JavaScript module. -@returns -Document the return value of a function. -@see -Refer to some other documentation for more information. -@since -When was this feature added? -@static -Document a static member. -@summary -A shorter version of the full description. -@this -What does the 'this' keyword refer to here? -@throws -Describe what errors could be thrown. -@todo -Document tasks to be completed. -@tutorial -Insert a link to an included tutorial file. -@type -Document the type of an object. -@typedef -Document a custom type. -@variation -Distinguish different objects with the same name. -@version -Documents the version number of an item. \ No newline at end of file diff --git a/Phaser/Phaser.csproj b/Phaser/Phaser.csproj index bfcb569f..70e5b9bd 100644 --- a/Phaser/Phaser.csproj +++ b/Phaser/Phaser.csproj @@ -1,4 +1,4 @@ - + Debug @@ -16,7 +16,16 @@ + + + + Emitter.ts + + + + Particle.ts + Phaser.ts @@ -416,7 +425,7 @@ ES5 false false - ../build/phaser-debug.js + ../build/phaser-debug.js ES5 diff --git a/Phaser/Phaser.sln b/Phaser/Phaser.sln index 768fa788..5a1f9a04 100644 --- a/Phaser/Phaser.sln +++ b/Phaser/Phaser.sln @@ -3,6 +3,10 @@ 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 @@ -13,6 +17,14 @@ Global {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 diff --git a/Phaser/_definitions.ts b/Phaser/_definitions.ts index a76d2fcf..982d7f5a 100644 --- a/Phaser/_definitions.ts +++ b/Phaser/_definitions.ts @@ -88,6 +88,9 @@ /// /// +/// +/// + /// /// diff --git a/Phaser/gameobjects/GameObjectFactory.js b/Phaser/gameobjects/GameObjectFactory.js index a4bf2964..359ba73d 100644 --- a/Phaser/gameobjects/GameObjectFactory.js +++ b/Phaser/gameobjects/GameObjectFactory.js @@ -125,9 +125,10 @@ var Phaser; * * @return {Particle} The newly created particle object. */ - //public particle(): ArcadeParticle { - // return new ArcadeParticle(this.game); - //} + GameObjectFactory.prototype.particle = function () { + return new Phaser.ArcadeParticle(this.game); + }; + /** * Create a new Emitter. * @@ -136,9 +137,13 @@ var Phaser; * @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): ArcadeEmitter { - // return this._world.group.add(new ArcadeEmitter(this.game, x, y, size)); - //} + GameObjectFactory.prototype.emitter = function (x, y, size) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof size === "undefined") { size = 0; } + return this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size)); + }; + /** * Create a new ScrollZone object with image key, position and size. * @@ -237,9 +242,10 @@ var Phaser; * @param emitter The Emitter to add to the Game World * @return {Phaser.Emitter} The Emitter object */ - //public existingEmitter(emitter: ArcadeEmitter): ArcadeEmitter { - // return this._world.group.add(emitter); - //} + GameObjectFactory.prototype.existingEmitter = function (emitter) { + 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. diff --git a/Phaser/gameobjects/GameObjectFactory.ts b/Phaser/gameobjects/GameObjectFactory.ts index 6f90219e..e9fa7028 100644 --- a/Phaser/gameobjects/GameObjectFactory.ts +++ b/Phaser/gameobjects/GameObjectFactory.ts @@ -130,9 +130,9 @@ module Phaser { * * @return {Particle} The newly created particle object. */ - //public particle(): ArcadeParticle { - // return new ArcadeParticle(this.game); - //} + public particle(): Phaser.ArcadeParticle { + return new Phaser.ArcadeParticle(this.game); + } /** * Create a new Emitter. @@ -142,9 +142,9 @@ module Phaser { * @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): ArcadeEmitter { - // return this._world.group.add(new ArcadeEmitter(this.game, x, y, size)); - //} + public emitter(x: number = 0, y: number = 0, size: number = 0): Phaser.ArcadeEmitter { + return this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size)); + } /** * Create a new ScrollZone object with image key, position and size. @@ -237,9 +237,9 @@ module Phaser { * @param emitter The Emitter to add to the Game World * @return {Phaser.Emitter} The Emitter object */ - //public existingEmitter(emitter: ArcadeEmitter): ArcadeEmitter { - // return this._world.group.add(emitter); - //} + public existingEmitter(emitter: Phaser.ArcadeEmitter): Phaser.ArcadeEmitter { + return this._world.group.add(emitter); + } /** * Add an existing ScrollZone to the current world. diff --git a/Phaser/input/Keyboard.js b/Phaser/input/Keyboard.js index ae533d39..3a3a956c 100644 --- a/Phaser/input/Keyboard.js +++ b/Phaser/input/Keyboard.js @@ -150,6 +150,110 @@ var Phaser; 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; diff --git a/Phaser/input/Keyboard.ts b/Phaser/input/Keyboard.ts index 448142d5..9219e6b8 100644 --- a/Phaser/input/Keyboard.ts +++ b/Phaser/input/Keyboard.ts @@ -211,7 +211,6 @@ module Phaser { } -/* // Letters public static A: number = "A".charCodeAt(0); public static B: number = "B".charCodeAt(0); @@ -321,7 +320,6 @@ module Phaser { public static DELETE: number = 46; public static HELP: number = 47; public static NUM_LOCK: number = 144; -*/ } } \ No newline at end of file diff --git a/Phaser/particles/Emitter.js b/Phaser/particles/Emitter.js new file mode 100644 index 00000000..f6638f36 --- /dev/null +++ b/Phaser/particles/Emitter.js @@ -0,0 +1,327 @@ +/// +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 __(); +}; +/** +* Phaser - ArcadeEmitter +* +* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for +* continuous effects like rain and fire. All it really does is launch Particle objects out +* at set intervals, and fixes their positions and velocities accorindgly. +*/ +var Phaser; +(function (Phaser) { + var ArcadeEmitter = (function (_super) { + __extends(ArcadeEmitter, _super); + /** + * Creates a new Emitter object at a specific position. + * Does NOT automatically generate or attach particles! + * + * @param x {number} The X position of the emitter. + * @param y {number} The Y position of the emitter. + * @param [size] {number} Specifies a maximum capacity for this emitter. + */ + function ArcadeEmitter(game, x, y, size) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof size === "undefined") { size = 0; } + _super.call(this, game, size); + + this.x = x; + this.y = y; + this.width = 0; + this.height = 0; + this.minParticleSpeed = new Phaser.Vec2(-100, -100); + this.maxParticleSpeed = new Phaser.Vec2(100, 100); + this.minRotation = -360; + this.maxRotation = 360; + this.gravity = 0; + this.particleClass = null; + this.particleDrag = new Phaser.Vec2(); + this.frequency = 0.1; + this.lifespan = 3; + this.bounce = 0; + this._quantity = 0; + this._counter = 0; + this._explode = true; + this.on = false; + + this.exists = true; + this.active = true; + this.visible = true; + } + /** + * Clean up memory. + */ + ArcadeEmitter.prototype.destroy = function () { + this.minParticleSpeed = null; + this.maxParticleSpeed = null; + this.particleDrag = null; + this.particleClass = null; + this._point = null; + _super.prototype.destroy.call(this); + }; + + /** + * This function generates a new array of particle sprites to attach to the emitter. + * + * @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet. + * @param quantity {number} The number of particles to generate when using the "create from image" option. + * @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!). + * @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box. + * + * @return This Emitter instance (nice for chaining stuff together, if you're into that). + */ + ArcadeEmitter.prototype.makeParticles = function (graphics, quantity, multiple, collide) { + if (typeof quantity === "undefined") { quantity = 50; } + if (typeof multiple === "undefined") { multiple = false; } + if (typeof collide === "undefined") { collide = 0; } + this.maxSize = quantity; + + var totalFrames = 1; + + /* + if(Multiple) + { + var sprite:Sprite = new Sprite(this.game); + sprite.loadGraphic(Graphics,true); + totalFrames = sprite.frames; + sprite.destroy(); + } + */ + var randomFrame; + var particle; + var i = 0; + + while (i < quantity) { + if (this.particleClass == null) { + particle = new Phaser.ArcadeParticle(this.game); + } else { + particle = new this.particleClass(this.game); + } + + if (multiple) { + /* + randomFrame = this.game.math.random()*totalFrames; + */ + } else { + if (graphics) { + particle.texture.loadImage(graphics); + } + } + + if (collide > 0) { + //particle.body.allowCollisions = Types.ANY; + particle.body.type = Phaser.Types.BODY_DYNAMIC; + particle.width *= collide; + particle.height *= collide; + } else { + //particle.body.allowCollisions = Types.NONE; + } + + particle.exists = false; + + // Center the origin for rotation assistance + //particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); + this.add(particle); + + i++; + } + + return this; + }; + + ArcadeEmitter.prototype.preUpdate = function () { + }; + ArcadeEmitter.prototype.postUpdate = function () { + }; + + /** + * Called automatically by the game loop, decides when to launch particles and when to "die". + */ + ArcadeEmitter.prototype.update = function () { + if (this.on) { + if (this._explode) { + this.on = false; + + var i = 0; + var l = this._quantity; + + if ((l <= 0) || (l > this.length)) { + l = this.length; + } + + while (i < l) { + this.emitParticle(); + i++; + } + + this._quantity = 0; + } else { + this._timer += this.game.time.elapsed; + + while ((this.frequency > 0) && (this._timer > this.frequency) && this.on) { + this._timer -= this.frequency; + this.emitParticle(); + + if ((this._quantity > 0) && (++this._counter >= this._quantity)) { + this.on = false; + this._quantity = 0; + } + } + } + } + + _super.prototype.update.call(this); + }; + + /** + * Call this function to turn off all the particles and the emitter. + */ + ArcadeEmitter.prototype.kill = function () { + this.on = false; + this.alive = false; + this.exists = false; + }; + + /** + * Handy for bringing game objects "back to life". Just sets alive and exists back to true. + * In practice, this is most often called by Object.reset(). + */ + ArcadeEmitter.prototype.revive = function () { + this.alive = true; + this.exists = true; + }; + + /** + * Call this function to start emitting particles. + * + * @param explode {boolean} Whether the particles should all burst out at once. + * @param lifespan {number} How long each particle lives once emitted. 0 = forever. + * @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds. + * @param quantity {number} How many particles to launch. 0 = "all of the particles". + */ + ArcadeEmitter.prototype.start = function (explode, lifespan, frequency, quantity) { + if (typeof explode === "undefined") { explode = true; } + if (typeof lifespan === "undefined") { lifespan = 0; } + if (typeof frequency === "undefined") { frequency = 0.1; } + if (typeof quantity === "undefined") { quantity = 0; } + this.revive(); + + this.visible = true; + this.on = true; + + this._explode = explode; + this.lifespan = lifespan; + this.frequency = frequency; + this._quantity += quantity; + + this._counter = 0; + this._timer = 0; + }; + + /** + * This function can be used both internally and externally to emit the next particle. + */ + ArcadeEmitter.prototype.emitParticle = function () { + var particle = this.recycle(Phaser.ArcadeParticle); + + particle.lifespan = this.lifespan; + + //particle.body.bounce.setTo(this.bounce, this.bounce); + Phaser.SpriteUtils.reset(particle, this.x - (particle.width >> 1) + this.game.rnd.integer * this.width, this.y - (particle.height >> 1) + this.game.rnd.integer * this.height); + particle.visible = true; + + if (this.minParticleSpeed.x != this.maxParticleSpeed.x) { + particle.body.velocity.x = this.minParticleSpeed.x + this.game.rnd.integer * (this.maxParticleSpeed.x - this.minParticleSpeed.x); + } else { + particle.body.velocity.x = this.minParticleSpeed.x; + } + + if (this.minParticleSpeed.y != this.maxParticleSpeed.y) { + particle.body.velocity.y = this.minParticleSpeed.y + this.game.rnd.integer * (this.maxParticleSpeed.y - this.minParticleSpeed.y); + } else { + particle.body.velocity.y = this.minParticleSpeed.y; + } + + if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) { + particle.body.angularVelocity = this.minRotation + this.game.rnd.integer * (this.maxRotation - this.minRotation); + } else { + particle.body.angularVelocity = this.minRotation; + } + + if (particle.body.angularVelocity != 0) { + particle.rotation = this.game.rnd.integer * 360 - 180; + } + + //particle.body.drag.x = this.particleDrag.x; + //particle.body.drag.y = this.particleDrag.y; + particle.onEmit(); + }; + + /** + * A more compact way of setting the width and height of the emitter. + * + * @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions). + * @param height {number} The desired height of the emitter. + */ + ArcadeEmitter.prototype.setSize = function (width, height) { + this.width = width; + this.height = height; + }; + + /** + * A more compact way of setting the X velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setXSpeed = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minParticleSpeed.x = min; + this.maxParticleSpeed.x = max; + }; + + /** + * A more compact way of setting the Y velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setYSpeed = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minParticleSpeed.y = min; + this.maxParticleSpeed.y = max; + }; + + /** + * A more compact way of setting the angular velocity constraints of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setRotation = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minRotation = min; + this.maxRotation = max; + }; + + /** + * Change the emitter's midpoint to match the midpoint of a Object. + * + * @param Object {object} The Object that you want to sync up with. + */ + ArcadeEmitter.prototype.at = function (object) { + //this.x = object.body.bounds.halfWidth - (this.width >> 1); + //this.y = object.body.bounds.halfHeight - (this.height >> 1); + }; + return ArcadeEmitter; + })(Phaser.Group); + Phaser.ArcadeEmitter = ArcadeEmitter; +})(Phaser || (Phaser = {})); diff --git a/Phaser/particles/Emitter.ts b/Phaser/particles/Emitter.ts new file mode 100644 index 00000000..0d412e00 --- /dev/null +++ b/Phaser/particles/Emitter.ts @@ -0,0 +1,462 @@ +/// + +/** +* Phaser - ArcadeEmitter +* +* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for +* continuous effects like rain and fire. All it really does is launch Particle objects out +* at set intervals, and fixes their positions and velocities accorindgly. +*/ + +module Phaser { + + export class ArcadeEmitter extends Phaser.Group { + + /** + * Creates a new Emitter object at a specific position. + * Does NOT automatically generate or attach particles! + * + * @param x {number} The X position of the emitter. + * @param y {number} The Y position of the emitter. + * @param [size] {number} Specifies a maximum capacity for this emitter. + */ + constructor(game: Phaser.Game, x: number = 0, y: number = 0, size: number = 0) { + + super(game, size); + + this.x = x; + this.y = y; + this.width = 0; + this.height = 0; + this.minParticleSpeed = new Vec2(-100, -100); + this.maxParticleSpeed = new Vec2(100, 100); + this.minRotation = -360; + this.maxRotation = 360; + this.gravity = 0; + this.particleClass = null; + this.particleDrag = new Vec2(); + this.frequency = 0.1; + this.lifespan = 3; + this.bounce = 0; + this._quantity = 0; + this._counter = 0; + this._explode = true; + this.on = false; + + this.exists = true; + this.active = true; + this.visible = true; + + } + + /** + * The X position of the top left corner of the emitter in world space. + */ + public x: number; + + /** + * The Y position of the top left corner of emitter in world space. + */ + public y: number; + + /** + * The width of the emitter. Particles can be randomly generated from anywhere within this box. + */ + public width: number; + + /** + * The height of the emitter. Particles can be randomly generated from anywhere within this box. + */ + public height: number; + + /** + * + */ + public alive: boolean; + + /** + * + */ + public active: boolean; + + /** + * The minimum possible velocity of a particle. + * The default value is (-100,-100). + */ + public minParticleSpeed: Phaser.Vec2; + + /** + * The maximum possible velocity of a particle. + * The default value is (100,100). + */ + public maxParticleSpeed: Phaser.Vec2; + + /** + * The X and Y drag component of particles launched from the emitter. + */ + public particleDrag: Phaser.Vec2; + + /** + * The minimum possible angular velocity of a particle. The default value is -360. + * NOTE: rotating particles are more expensive to draw than non-rotating ones! + */ + public minRotation: number; + + /** + * The maximum possible angular velocity of a particle. The default value is 360. + * NOTE: rotating particles are more expensive to draw than non-rotating ones! + */ + public maxRotation: number; + + /** + * Sets the acceleration.y member of each particle to this value on launch. + */ + public gravity: number; + + /** + * Determines whether the emitter is currently emitting particles. + * It is totally safe to directly toggle this. + */ + public on: boolean; + + /** + * How often a particle is emitted (if emitter is started with Explode == false). + */ + public frequency: number; + + /** + * How long each particle lives once it is emitted. + * Set lifespan to 'zero' for particles to live forever. + */ + public lifespan: number; + + /** + * How much each particle should bounce. 1 = full bounce, 0 = no bounce. + */ + public bounce: number; + + /** + * Set your own particle class type here. + * Default is Particle. + */ + public particleClass; + + /** + * Internal helper for deciding how many particles to launch. + */ + private _quantity: number; + + /** + * Internal helper for the style of particle emission (all at once, or one at a time). + */ + private _explode: boolean; + + /** + * Internal helper for deciding when to launch particles or kill them. + */ + private _timer: number; + + /** + * Internal counter for figuring out how many particles to launch. + */ + private _counter: number; + + /** + * Internal point object, handy for reusing for memory mgmt purposes. + */ + private _point: Phaser.Vec2; + + /** + * Clean up memory. + */ + public destroy() { + this.minParticleSpeed = null; + this.maxParticleSpeed = null; + this.particleDrag = null; + this.particleClass = null; + this._point = null; + super.destroy(); + } + + /** + * This function generates a new array of particle sprites to attach to the emitter. + * + * @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet. + * @param quantity {number} The number of particles to generate when using the "create from image" option. + * @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!). + * @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box. + * + * @return This Emitter instance (nice for chaining stuff together, if you're into that). + */ + public makeParticles(graphics, quantity: number = 50, multiple: boolean = false, collide: number = 0): Phaser.ArcadeEmitter { + + this.maxSize = quantity; + + var totalFrames: number = 1; + + /* + if(Multiple) + { + var sprite:Sprite = new Sprite(this.game); + sprite.loadGraphic(Graphics,true); + totalFrames = sprite.frames; + sprite.destroy(); + } + */ + + var randomFrame: number; + var particle: Phaser.ArcadeParticle; + var i: number = 0; + + while (i < quantity) + { + if (this.particleClass == null) + { + particle = new Phaser.ArcadeParticle(this.game); + } + else + { + particle = new this.particleClass(this.game); + } + + if (multiple) + { + /* + randomFrame = this.game.math.random()*totalFrames; + */ + } + else + { + if (graphics) + { + particle.texture.loadImage(graphics); + } + } + + if (collide > 0) + { + //particle.body.allowCollisions = Types.ANY; + particle.body.type = Phaser.Types.BODY_DYNAMIC; + particle.width *= collide; + particle.height *= collide; + } + else + { + //particle.body.allowCollisions = Types.NONE; + } + + particle.exists = false; + // Center the origin for rotation assistance + //particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); + + this.add(particle); + + i++; + } + + return this; + } + + public preUpdate() { } + public postUpdate() { } + + /** + * Called automatically by the game loop, decides when to launch particles and when to "die". + */ + public update() { + + if (this.on) + { + if (this._explode) + { + this.on = false; + + var i: number = 0; + var l: number = this._quantity; + + if ((l <= 0) || (l > this.length)) + { + l = this.length; + } + + while (i < l) + { + this.emitParticle(); + i++; + } + + this._quantity = 0; + } + else + { + this._timer += this.game.time.elapsed; + + while ((this.frequency > 0) && (this._timer > this.frequency) && this.on) + { + this._timer -= this.frequency; + this.emitParticle(); + + if ((this._quantity > 0) && (++this._counter >= this._quantity)) + { + this.on = false; + this._quantity = 0; + } + } + } + } + + super.update(); + + } + + /** + * Call this function to turn off all the particles and the emitter. + */ + public kill() { + this.on = false; + this.alive = false; + this.exists = false; + } + + /** + * Handy for bringing game objects "back to life". Just sets alive and exists back to true. + * In practice, this is most often called by Object.reset(). + */ + public revive() { + this.alive = true; + this.exists = true; + } + + /** + * Call this function to start emitting particles. + * + * @param explode {boolean} Whether the particles should all burst out at once. + * @param lifespan {number} How long each particle lives once emitted. 0 = forever. + * @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds. + * @param quantity {number} How many particles to launch. 0 = "all of the particles". + */ + public start(explode: boolean = true, lifespan: number = 0, frequency: number = 0.1, quantity: number = 0) { + + this.revive(); + + this.visible = true; + this.on = true; + + this._explode = explode; + this.lifespan = lifespan; + this.frequency = frequency; + this._quantity += quantity; + + this._counter = 0; + this._timer = 0; + + } + + /** + * This function can be used both internally and externally to emit the next particle. + */ + public emitParticle() { + + var particle: ArcadeParticle = this.recycle(ArcadeParticle); + + particle.lifespan = this.lifespan; + //particle.body.bounce.setTo(this.bounce, this.bounce); + SpriteUtils.reset(particle, this.x - (particle.width >> 1) + this.game.rnd.integer * this.width, this.y - (particle.height >> 1) + this.game.rnd.integer * this.height); + particle.visible = true; + + if (this.minParticleSpeed.x != this.maxParticleSpeed.x) + { + particle.body.velocity.x = this.minParticleSpeed.x + this.game.rnd.integer * (this.maxParticleSpeed.x - this.minParticleSpeed.x); + } + else + { + particle.body.velocity.x = this.minParticleSpeed.x; + } + + if (this.minParticleSpeed.y != this.maxParticleSpeed.y) + { + particle.body.velocity.y = this.minParticleSpeed.y + this.game.rnd.integer * (this.maxParticleSpeed.y - this.minParticleSpeed.y); + } + else + { + particle.body.velocity.y = this.minParticleSpeed.y; + } + + //particle.body.acceleration.y = this.gravity; + + if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) + { + particle.body.angularVelocity = this.minRotation + this.game.rnd.integer * (this.maxRotation - this.minRotation); + } + else + { + particle.body.angularVelocity = this.minRotation; + } + + if (particle.body.angularVelocity != 0) + { + particle.rotation = this.game.rnd.integer * 360 - 180; + } + + //particle.body.drag.x = this.particleDrag.x; + //particle.body.drag.y = this.particleDrag.y; + particle.onEmit(); + + } + + /** + * A more compact way of setting the width and height of the emitter. + * + * @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions). + * @param height {number} The desired height of the emitter. + */ + public setSize(width: number, height: number) { + this.width = width; + this.height = height; + } + + /** + * A more compact way of setting the X velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + public setXSpeed(min: number = 0, max: number = 0) { + this.minParticleSpeed.x = min; + this.maxParticleSpeed.x = max; + } + + /** + * A more compact way of setting the Y velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + public setYSpeed(min: number = 0, max: number = 0) { + this.minParticleSpeed.y = min; + this.maxParticleSpeed.y = max; + } + + /** + * A more compact way of setting the angular velocity constraints of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + public setRotation(min: number = 0, max: number = 0) { + this.minRotation = min; + this.maxRotation = max; + } + + /** + * Change the emitter's midpoint to match the midpoint of a Object. + * + * @param Object {object} The Object that you want to sync up with. + */ + public at(object: Sprite) { + //this.x = object.body.bounds.halfWidth - (this.width >> 1); + //this.y = object.body.bounds.halfHeight - (this.height >> 1); + } + } + +} \ No newline at end of file diff --git a/Phaser/particles/Particle.js b/Phaser/particles/Particle.js new file mode 100644 index 00000000..612ae732 --- /dev/null +++ b/Phaser/particles/Particle.js @@ -0,0 +1,52 @@ +/// +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 __(); +}; +/** +* Phaser - ArcadeParticle +* +* This is a simple particle class that extends a Sprite to have a slightly more +* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required. +*/ +var Phaser; +(function (Phaser) { + var ArcadeParticle = (function (_super) { + __extends(ArcadeParticle, _super); + /** + * Instantiate a new particle. Like Sprite, all meaningful creation + * happens during loadGraphic() or makeGraphic() or whatever. + */ + function ArcadeParticle(game) { + _super.call(this, game); + + this.body.type = Phaser.Types.BODY_DYNAMIC; + this.lifespan = 0; + } + /** + * The particle's main update logic. Basically it checks to see if it should be dead yet. + */ + ArcadeParticle.prototype.update = function () { + if (this.lifespan <= 0) { + return; + } + + this.lifespan -= this.game.time.elapsed; + + if (this.lifespan <= 0) { + this.kill(); + } + }; + + /** + * Triggered whenever this object is launched by a Emitter. + * You can override this to add custom behavior like a sound or AI or something. + */ + ArcadeParticle.prototype.onEmit = function () { + }; + return ArcadeParticle; + })(Phaser.Sprite); + Phaser.ArcadeParticle = ArcadeParticle; +})(Phaser || (Phaser = {})); diff --git a/Phaser/particles/Particle.ts b/Phaser/particles/Particle.ts new file mode 100644 index 00000000..b34d6248 --- /dev/null +++ b/Phaser/particles/Particle.ts @@ -0,0 +1,63 @@ +/// + +/** +* Phaser - ArcadeParticle +* +* This is a simple particle class that extends a Sprite to have a slightly more +* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required. +*/ + +module Phaser { + + export class ArcadeParticle extends Phaser.Sprite { + + /** + * Instantiate a new particle. Like Sprite, all meaningful creation + * happens during loadGraphic() or makeGraphic() or whatever. + */ + constructor(game: Phaser.Game) { + + super(game); + + this.body.type = Phaser.Types.BODY_DYNAMIC; + this.lifespan = 0; + + } + + /** + * How long this particle lives before it disappears. + * NOTE: this is a maximum, not a minimum; the object + * could get recycled before its lifespan is up. + */ + public lifespan: number; + + /** + * The particle's main update logic. Basically it checks to see if it should be dead yet. + */ + public update() { + + // Lifespan behavior + if (this.lifespan <= 0) + { + return; + } + + this.lifespan -= this.game.time.elapsed; + + if (this.lifespan <= 0) + { + this.kill(); + } + + } + + /** + * Triggered whenever this object is launched by a Emitter. + * You can override this to add custom behavior like a sound or AI or something. + */ + public onEmit() { + } + + } + +} \ No newline at end of file diff --git a/Phaser/time/TimeManager.js b/Phaser/time/TimeManager.js index 73aeefcf..01b05259 100644 --- a/Phaser/time/TimeManager.js +++ b/Phaser/time/TimeManager.js @@ -1,84 +1,119 @@ /// /** -* Phaser - TimeManager -* -* This is the game clock and it manages elapsed time and calculation of delta values, used for game object motion. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser */ var Phaser; (function (Phaser) { var TimeManager = (function () { /** - * Time constructor - * Create a new Time. + * This is the core internal game clock. It manages the elapsed time and calculation of delta values, + * used for game object motion and tweens. * - * @param game {Phaser.Game} Current game instance. + * @class TimeManager + * @constructor + * @param {Phaser.Game} game A reference to the currently running game. */ function TimeManager(game) { /** - * Elapsed since last frame. - * @type {number} + * Number of milliseconds elapsed since the last frame update. + * @property elapsed + * @public + * @type {Number} */ this.elapsed = 0; /** * Game time counter. * @property time - * @type {number} + * @public + * @type {Number} */ this.time = 0; /** - * How long the game has been paused for. Gets reset each time the game pauses. + * Records how long the game has been paused for. Is reset each time the game pauses. * @property pausedTime - * @type {number} + * @public + * @type {Number} */ this.pausedTime = 0; /** - * Time of current frame. + * The time right now. * @property now - * @type {number} + * @public + * @type {Number} */ this.now = 0; /** - * Elapsed time since last frame. + * Elapsed time since the last frame. * @property delta - * @type {number} + * @public + * @type {Number} */ this.delta = 0; /** * Frames per second. - * @type {number} + * @property fps + * @public + * @type {Number} */ this.fps = 0; /** - * Minimal fps. - * @type {number} + * The lowest rate the fps has dropped to. + * @property fpsMin + * @public + * @type {Number} */ this.fpsMin = 1000; /** - * Maximal fps. - * @type {number} + * The highest rate the fps has reached (usually no higher than 60fps). + * @property fpsMax + * @public + * @type {Number} */ this.fpsMax = 0; /** - * Minimum duration between 2 frames. - * @type {number} + * The minimum amount of time the game has taken between two frames. + * @property msMin + * @public + * @type {Number} */ this.msMin = 1000; /** - * Maximum duration between 2 frames. - * @type {number} + * The maximum amount of time the game has taken between two frames. + * @property msMax + * @public + * @type {Number} */ this.msMax = 0; /** - * How many frames in last second. - * @type {number} + * The number of frames record in the last second. + * @property frames + * @public + * @type {Number} */ this.frames = 0; /** - * Time of last second. - * @type {number} + * The time (in ms) that the last second counter ticked over. + * @property _timeLastSecond + * @private + * @type {Number} */ this._timeLastSecond = 0; + /** + * Records how long the game was paused for in miliseconds. + * @property pauseDuration + * @public + * @type {Number} + */ this.pauseDuration = 0; + /** + * The time the game started being paused. + * @property _pauseStarted + * @private + * @type {Number} + */ this._pauseStarted = 0; this.game = game; @@ -91,7 +126,7 @@ var Phaser; } Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", { get: /** - * + * The number of seconds that have elapsed since the game was started. * @method totalElapsedSeconds * @return {Number} */ @@ -106,7 +141,7 @@ var Phaser; * Update clock and calculate the fps. * This is called automatically by Game._raf * @method update - * @param {number} raf The current timestamp, either performance.now or Date.now + * @param {Number} raf The current timestamp, either performance.now or Date.now */ TimeManager.prototype.update = function (raf) { this.now = raf; @@ -133,20 +168,30 @@ var Phaser; } }; + /** + * Called when the game enters a paused state. + * @method gamePaused + * @private + */ TimeManager.prototype.gamePaused = function () { this._pauseStarted = this.now; }; + /** + * Called when the game resumes from a paused state. + * @method gameResumed + * @private + */ TimeManager.prototype.gameResumed = function () { // Level out the delta timer to avoid spikes this.pauseDuration = this.pausedTime; }; /** - * How long has passed since given time. + * How long has passed since the given time. * @method elapsedSince - * @param {number} since The time you want to measure. - * @return {number} Duration between given time and now. + * @param {Number} since The time you want to measure against. + * @return {Number} The difference between the given time and now. */ TimeManager.prototype.elapsedSince = function (since) { return this.now - since; @@ -155,15 +200,15 @@ var Phaser; /** * How long has passed since the given time (in seconds). * @method elapsedSecondsSince - * @param {number} since The time you want to measure (in seconds). - * @return {number} Duration between given time and now (in seconds). + * @param {Number} since The time you want to measure (in seconds). + * @return {Number} Duration between given time and now (in seconds). */ TimeManager.prototype.elapsedSecondsSince = function (since) { return (this.now - since) * 0.001; }; /** - * Set the start time to now. + * Resets the private _started value to now. * @method reset */ TimeManager.prototype.reset = function () { diff --git a/Phaser/time/TimeManager.ts b/Phaser/time/TimeManager.ts index f3c13273..648eecd9 100644 --- a/Phaser/time/TimeManager.ts +++ b/Phaser/time/TimeManager.ts @@ -1,21 +1,23 @@ /// /** -* Phaser - TimeManager -* -* This is the game clock and it manages elapsed time and calculation of delta values, used for game object motion. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser */ - module Phaser { export class TimeManager { /** - * Time constructor - * Create a new Time. - * - * @param game {Phaser.Game} Current game instance. - */ + * This is the core internal game clock. It manages the elapsed time and calculation of delta values, + * used for game object motion and tweens. + * + * @class TimeManager + * @constructor + * @param {Phaser.Game} game A reference to the currently running game. + */ constructor(game: Phaser.Game) { this.game = game; @@ -30,52 +32,62 @@ module Phaser { } /** - * Local reference to game. - */ + * A reference to the currently running Game. + * @property game + * @type {Phaser.Game} + */ public game: Phaser.Game; /** - * Time when this object created. - * @param {number} - */ + * The time at which the Game instance started. + * @property _started + * @private + * @type {Number} + */ private _started: number; /** - * Elapsed since last frame. - * @type {number} - */ + * Number of milliseconds elapsed since the last frame update. + * @property elapsed + * @public + * @type {Number} + */ public elapsed: number = 0; /** - * Game time counter. - * @property time - * @type {number} - */ + * Game time counter. + * @property time + * @public + * @type {Number} + */ public time: number = 0; /** - * How long the game has been paused for. Gets reset each time the game pauses. - * @property pausedTime - * @type {number} - */ + * Records how long the game has been paused for. Is reset each time the game pauses. + * @property pausedTime + * @public + * @type {Number} + */ public pausedTime: number = 0; /** - * Time of current frame. - * @property now - * @type {number} - */ + * The time right now. + * @property now + * @public + * @type {Number} + */ public now: number = 0; /** - * Elapsed time since last frame. - * @property delta - * @type {number} - */ + * Elapsed time since the last frame. + * @property delta + * @public + * @type {Number} + */ public delta: number = 0; /** - * + * The number of seconds that have elapsed since the game was started. * @method totalElapsedSeconds * @return {Number} */ @@ -86,52 +98,66 @@ module Phaser { } /** - * Frames per second. - * @type {number} - */ + * Frames per second. + * @property fps + * @public + * @type {Number} + */ public fps: number = 0; /** - * Minimal fps. - * @type {number} - */ + * The lowest rate the fps has dropped to. + * @property fpsMin + * @public + * @type {Number} + */ public fpsMin: number = 1000; /** - * Maximal fps. - * @type {number} - */ + * The highest rate the fps has reached (usually no higher than 60fps). + * @property fpsMax + * @public + * @type {Number} + */ public fpsMax: number = 0; /** - * Minimum duration between 2 frames. - * @type {number} - */ + * The minimum amount of time the game has taken between two frames. + * @property msMin + * @public + * @type {Number} + */ public msMin: number = 1000; /** - * Maximum duration between 2 frames. - * @type {number} - */ + * The maximum amount of time the game has taken between two frames. + * @property msMax + * @public + * @type {Number} + */ public msMax: number = 0; /** - * How many frames in last second. - * @type {number} - */ + * The number of frames record in the last second. + * @property frames + * @public + * @type {Number} + */ public frames: number = 0; /** - * Time of last second. - * @type {number} - */ + * The time (in ms) that the last second counter ticked over. + * @property _timeLastSecond + * @private + * @type {Number} + */ private _timeLastSecond: number = 0; /** * Update clock and calculate the fps. * This is called automatically by Game._raf * @method update - * @param {number} raf The current timestamp, either performance.now or Date.now + * @param {Number} raf The current timestamp, either performance.now or Date.now */ public update(raf: number) { @@ -163,24 +189,47 @@ module Phaser { } + /** + * Called when the game enters a paused state. + * @method gamePaused + * @private + */ private gamePaused() { this._pauseStarted = this.now; } + /** + * Called when the game resumes from a paused state. + * @method gameResumed + * @private + */ private gameResumed() { // Level out the delta timer to avoid spikes this.pauseDuration = this.pausedTime; } + /** + * Records how long the game was paused for in miliseconds. + * @property pauseDuration + * @public + * @type {Number} + */ public pauseDuration: number = 0; + + /** + * The time the game started being paused. + * @property _pauseStarted + * @private + * @type {Number} + */ private _pauseStarted: number = 0; /** - * How long has passed since given time. - * @method elapsedSince - * @param {number} since The time you want to measure. - * @return {number} Duration between given time and now. - */ + * How long has passed since the given time. + * @method elapsedSince + * @param {Number} since The time you want to measure against. + * @return {Number} The difference between the given time and now. + */ public elapsedSince(since: number): number { return this.now - since; @@ -188,11 +237,11 @@ module Phaser { } /** - * How long has passed since the given time (in seconds). - * @method elapsedSecondsSince - * @param {number} since The time you want to measure (in seconds). - * @return {number} Duration between given time and now (in seconds). - */ + * How long has passed since the given time (in seconds). + * @method elapsedSecondsSince + * @param {Number} since The time you want to measure (in seconds). + * @return {Number} Duration between given time and now (in seconds). + */ public elapsedSecondsSince(since: number): number { return (this.now - since) * 0.001; @@ -200,9 +249,9 @@ module Phaser { } /** - * Set the start time to now. - * @method reset - */ + * Resets the private _started value to now. + * @method reset + */ public reset() { this._started = this.now; diff --git a/Phaser/yuidoc.json b/Phaser/yuidoc.json new file mode 100644 index 00000000..ac031eaf --- /dev/null +++ b/Phaser/yuidoc.json @@ -0,0 +1,10 @@ +{ + "name": "Phaser", + "description": "HTML5 Game Framework", + "version": "1.0.0", + "url": "http://www.phaser.io/", + "options": { + "linkNatives": "false" + } + +} \ No newline at end of file diff --git a/Plugins/CameraFX/Border.js b/Plugins/CameraFX/Border.js index 3be0f00f..d2ec8192 100644 --- a/Plugins/CameraFX/Border.js +++ b/Plugins/CameraFX/Border.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,7 +18,7 @@ var Phaser; var Border = (function (_super) { __extends(Border, _super); function Border(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); /** * Whether render border of this camera or not. (default is true) * @type {boolean} @@ -31,7 +32,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); @@ -40,7 +41,7 @@ var Phaser; }; return Border; })(Phaser.Plugin); - CameraFX.Border = Border; + CameraFX.Border = Border; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/CameraFX/Fade.js b/Plugins/CameraFX/Fade.js index 0f30b85f..217e9db7 100644 --- a/Plugins/CameraFX/Fade.js +++ b/Plugins/CameraFX/Fade.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,13 +18,13 @@ var Phaser; var Fade = (function (_super) { __extends(Fade, _super); function Fade(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); this._fxFadeComplete = null; this._fxFadeDuration = 0; 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. @@ -31,48 +32,53 @@ 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. */ - function (color, duration, onComplete, force) { + Fade.prototype.start = 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 () { - // Update the Fade effect - if(this._fxFadeAlpha > 0) { + 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 () { - // "Fade" FX - if(this._fxFadeAlpha > 0) { + 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); } }; return Fade; })(Phaser.Plugin); - CameraFX.Fade = Fade; + CameraFX.Fade = Fade; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/CameraFX/Flash.js b/Plugins/CameraFX/Flash.js index ffcf2002..ea952004 100644 --- a/Plugins/CameraFX/Flash.js +++ b/Plugins/CameraFX/Flash.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,13 +18,13 @@ var Phaser; var Flash = (function (_super) { __extends(Flash, _super); function Flash(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); this._fxFlashComplete = null; this._fxFlashDuration = 0; 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. @@ -31,47 +32,53 @@ 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. */ - function (color, duration, onComplete, force) { + Flash.prototype.start = 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 () { - // Update the Flash effect - if(this._fxFlashAlpha > 0) { + 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); } }; return Flash; })(Phaser.Plugin); - CameraFX.Flash = Flash; + CameraFX.Flash = Flash; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/CameraFX/Mirror.js b/Plugins/CameraFX/Mirror.js index e474c9b2..0163166e 100644 --- a/Plugins/CameraFX/Mirror.js +++ b/Plugins/CameraFX/Mirror.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,66 +18,76 @@ var Phaser; var Mirror = (function (_super) { __extends(Mirror, _super); function Mirror(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); this._mirrorColor = null; this.flipX = false; this.flipY = true; this.cls = false; this.camera = parent; + this._canvas = document.createElement('canvas'); this._canvas.width = parent.width; this._canvas.height = parent.height; this._context = this._canvas.getContext('2d'); } - Mirror.prototype.start = /** + /** * This is the rectangular region to grab from the Camera used in the Mirror effect * It is rendered to the Stage at Mirror.x/y (note the use of Stage coordinates, not World coordinates) */ - function (x, y, region, fillColor) { + Mirror.prototype.start = function (x, y, region, fillColor) { if (typeof fillColor === "undefined") { fillColor = 'rgba(0, 0, 100, 0.5)'; } this.x = x; this.y = y; + this._mirrorX = region.x; this._mirrorY = region.y; this._mirrorWidth = region.width; this._mirrorHeight = region.height; - if(fillColor) { + + if (fillColor) { this._mirrorColor = fillColor; this._context.fillStyle = this._mirrorColor; } }; + Mirror.prototype.postRender = function () { this._sx = this.camera.screenView.x + this._mirrorX; this._sy = this.camera.screenView.y + this._mirrorY; - if(this.flipX == true && this.flipY == false) { + + if (this.flipX == true && this.flipY == false) { this._sx = 0; - } else if(this.flipY == true && this.flipX == false) { + } else if (this.flipY == true && this.flipX == false) { this._sy = 0; } + this._context.drawImage(this.game.stage.canvas, this._sx, this._sy, this._mirrorWidth, this._mirrorHeight, 0, 0, this._mirrorWidth, this._mirrorHeight); - if(this._mirrorColor) { + + if (this._mirrorColor) { this._context.fillRect(0, 0, this._mirrorWidth, this._mirrorHeight); } - if(this.flipX || this.flipY) { + + if (this.flipX || this.flipY) { this.game.stage.context.save(); } - if(this.flipX && this.flipY) { + + if (this.flipX && this.flipY) { this.game.stage.context.transform(-1, 0, 0, -1, this._mirrorWidth, this._mirrorHeight); this.game.stage.context.drawImage(this._canvas, -this.x, -this.y); - } else if(this.flipX) { + } else if (this.flipX) { this.game.stage.context.transform(-1, 0, 0, 1, this._mirrorWidth, 0); this.game.stage.context.drawImage(this._canvas, -this.x, this.y); - } else if(this.flipY) { + } else if (this.flipY) { this.game.stage.context.transform(1, 0, 0, -1, 0, this._mirrorHeight); this.game.stage.context.drawImage(this._canvas, this.x, -this.y); } - if(this.flipX || this.flipY) { + + if (this.flipX || this.flipY) { this.game.stage.context.restore(); } }; return Mirror; })(Phaser.Plugin); - CameraFX.Mirror = Mirror; + CameraFX.Mirror = Mirror; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/CameraFX/Scanlines.js b/Plugins/CameraFX/Scanlines.js index d4bd518b..f921e01e 100644 --- a/Plugins/CameraFX/Scanlines.js +++ b/Plugins/CameraFX/Scanlines.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,20 +18,21 @@ var Phaser; var Scanlines = (function (_super) { __extends(Scanlines, _super); function Scanlines(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); this.spacing = 4; this.color = 'rgba(0, 0, 0, 0.3)'; this.camera = parent; } Scanlines.prototype.postRender = function () { this.game.stage.context.fillStyle = this.color; - for(var y = this.camera.screenView.y; y < this.camera.screenView.height; y += this.spacing) { + + for (var y = this.camera.screenView.y; y < this.camera.screenView.height; y += this.spacing) { this.game.stage.context.fillRect(this.camera.screenView.x, y, this.camera.screenView.width, 1); } }; return Scanlines; })(Phaser.Plugin); - CameraFX.Scanlines = Scanlines; + CameraFX.Scanlines = Scanlines; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/CameraFX/Shadow.js b/Plugins/CameraFX/Shadow.js index 639cd2a4..7eef5d76 100644 --- a/Plugins/CameraFX/Shadow.js +++ b/Plugins/CameraFX/Shadow.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,7 +18,7 @@ var Phaser; var Shadow = (function (_super) { __extends(Shadow, _super); function Shadow(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); /** * Render camera shadow or not. (default is false) * @type {boolean} @@ -40,25 +41,24 @@ 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. */ - function () { - // Shadow - if(this.showShadow == true) { + Shadow.prototype.preRender = function () { + 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. */ - function () { - // Shadow off - if(this.showShadow == true) { + Shadow.prototype.render = function () { + if (this.showShadow == true) { this.game.stage.context.shadowBlur = 0; this.game.stage.context.shadowOffsetX = 0; this.game.stage.context.shadowOffsetY = 0; @@ -66,7 +66,7 @@ var Phaser; }; return Shadow; })(Phaser.Plugin); - CameraFX.Shadow = Shadow; + CameraFX.Shadow = Shadow; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/CameraFX/Shake.js b/Plugins/CameraFX/Shake.js index f2fd3d25..905e9b4a 100644 --- a/Plugins/CameraFX/Shake.js +++ b/Plugins/CameraFX/Shake.js @@ -1,4 +1,5 @@ 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 __(); @@ -17,7 +18,7 @@ var Phaser; var Shake = (function (_super) { __extends(Shake, _super); function Shake(game, parent) { - _super.call(this, game, parent); + _super.call(this, game, parent); this._fxShakeIntensity = 0; this._fxShakeDuration = 0; this._fxShakeComplete = null; @@ -27,10 +28,7 @@ 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. @@ -39,57 +37,65 @@ 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). */ - function (intensity, duration, onComplete, force, direction) { + Shake.prototype.start = 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 a shake is not already running we need to store the offsets here - if(this._fxShakeOffset.x == 0 && this._fxShakeOffset.y == 0) { + + 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 () { - // Update the "shake" special effect - if(this._fxShakeDuration > 0) { + 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; + CameraFX.Shake = Shake; })(Plugins.CameraFX || (Plugins.CameraFX = {})); var CameraFX = Plugins.CameraFX; })(Phaser.Plugins || (Phaser.Plugins = {})); diff --git a/Plugins/Template.js b/Plugins/Template.js index 8c54f41d..83f1244c 100644 --- a/Plugins/Template.js +++ b/Plugins/Template.js @@ -1,4 +1,5 @@ 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 __(); @@ -14,55 +15,63 @@ var Phaser; var Example = (function (_super) { __extends(Example, _super); function Example(game, parent) { - _super.call(this, 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. */ - function () { + Example.prototype.preUpdate = 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. */ - function () { + Example.prototype.update = 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. */ - function () { + Example.prototype.postUpdate = 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. */ - function () { + Example.prototype.preRender = 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. */ - function () { + Example.prototype.render = 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. */ - function () { + Example.prototype.postRender = function () { }; return Example; })(Phaser.Plugin); - Plugins.Example = Example; + Plugins.Example = Example; })(Phaser.Plugins || (Phaser.Plugins = {})); var Plugins = Phaser.Plugins; })(Phaser || (Phaser = {})); diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index e83340ee..b1fb84bc 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -118,7 +118,6 @@ scrollfactor 2.ts - @@ -252,25 +251,6 @@ sprite test 1.ts - - graphic emitter.ts - - - - - mousetrail.ts - - - multiple streams.ts - - - - sprite emitter.ts - - - - when particles collide.ts - @@ -462,6 +442,7 @@ + diff --git a/Tests/audio/audio sprites 1.js b/Tests/audio/audio sprites 1.js index d7387a0a..0b34a27d 100644 --- a/Tests/audio/audio sprites 1.js +++ b/Tests/audio/audio sprites 1.js @@ -4,37 +4,40 @@ //var PhaserGlobal = { disableWebAudio: true }; (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { - game.load.audio('rabbit', [ - 'assets/mp3/peter_rabbit.m4a', - 'assets/mp3/peter_rabbit.mp3', - 'assets/mp3/peter_rabbit.ogg' - ]); + game.load.audio('rabbit', ['assets/mp3/peter_rabbit.m4a', 'assets/mp3/peter_rabbit.mp3', 'assets/mp3/peter_rabbit.ogg']); game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); } + audioSprite: -Phaser.Sound + Phaser.Sound; button: -Phaser.UI.Button + Phaser.UI.Button; pause: -Phaser.UI.Button + Phaser.UI.Button; + function create() { this.audioSprite = game.add.audio('rabbit'); this.audioSprite.addMarker('title', 3.00, 5.00, 1, true); this.audioSprite.addMarker('help', 6.00, 12.00); this.audioSprite.addMarker('intro', 14.00, 19.00); this.audioSprite.addMarker('peter', 20.00, 21.50); + this.button = game.add.button(game.stage.centerX, 400, 'button', playMusic, this, 2, 1, 0); //this.pause = game.add.button(200, 200, 'button', togglePause, this, 2, 1, 0); - } + } + function playMusic() { this.audioSprite.play('help'); } + function render() { Phaser.DebugUtils.renderSoundInfo(this.audioSprite, 32, 32); } + function togglePause() { - if(this.music.paused) { + if (this.music.paused) { this.music.resume(); } else { this.music.pause(); diff --git a/Tests/audio/play sound 1.js b/Tests/audio/play sound 1.js index ab73325c..ed4bbdb3 100644 --- a/Tests/audio/play sound 1.js +++ b/Tests/audio/play sound 1.js @@ -4,50 +4,57 @@ //var PhaserGlobal = { fakeiOSTouchLock: true, disableWebAudio: true }; (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { //game.load.audio('wizball', ['assets/mp3/oedipus_wizball_highscore.ogg', 'assets/mp3/oedipus_wizball_highscore.mp3']); - game.load.audio('boden', [ - 'assets/mp3/bodenstaendig_2000_in_rock_4bit.mp3' - ]); + game.load.audio('boden', ['assets/mp3/bodenstaendig_2000_in_rock_4bit.mp3']); game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); } + button: -Phaser.UI.Button + Phaser.UI.Button; music: -Phaser.Sound + Phaser.Sound; volumeUp: -Phaser.UI.Button + Phaser.UI.Button; volumeDown: -Phaser.UI.Button + Phaser.UI.Button; pause: -Phaser.UI.Button + Phaser.UI.Button; + function create() { this.music = game.add.audio('boden'); + this.button = game.add.button(game.stage.centerX, 400, 'button', playMusic, this, 2, 1, 0); //this.volumeUp = game.add.button(0, 0, 'button', volUp, this, 2, 1, 0); //this.volumeDown = game.add.button(700, 0, 'button', volDown, this, 2, 1, 0); //this.pause = game.add.button(200, 200, 'button', togglePause, this, 2, 1, 0); - } + } + function render() { Phaser.DebugUtils.renderSoundInfo(this.music, 0, 300); } + function togglePause() { - if(this.music.paused) { + if (this.music.paused) { this.music.resume(); } else { this.music.pause(); } } + function volUp() { //game.sound.volume += 0.1; this.music.volume += 0.1; console.log('vol up', game.sound.volume); } + function volDown() { //game.sound.volume -= 0.1; this.music.volume -= 0.1; console.log('vol down', game.sound.volume); } + function playMusic() { this.music.play(); } diff --git a/Tests/buttons/basic button 2.js b/Tests/buttons/basic button 2.js index 61fbe23a..a647d370 100644 --- a/Tests/buttons/basic button 2.js +++ b/Tests/buttons/basic button 2.js @@ -2,28 +2,34 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('beast', 'assets/pics/shadow_of_the_beast2_other_world.png'); game.load.atlas('button', 'assets/buttons/button_texture_atlas.png', 'assets/buttons/button_texture_atlas.json'); } + image: -Phaser.Sprite + Phaser.Sprite; button: -Phaser.UI.Button + Phaser.UI.Button; + function create() { // This is just an image that we'll toggle the display of when you click the button this.image = game.add.sprite(game.stage.centerX, 0, 'beast'); this.image.transform.origin.setTo(0.5, 0); + // This button is created from a texture atlas. // Instead of frame IDs (like with a sprite sheet) we can tell it to use frame names instead. // In this case our atlast frame names were called 'over', 'out' and 'down', but they could be anything you want. // The function "clickedIt" will be called when the button is clicked or touched this.button = game.add.button(game.stage.centerX, 400, 'button', clickedIt, this, 'over', 'out', 'down'); + // Just makes the button origin set to the middle, we only do this to center the button on-screen, no other reason this.button.transform.origin.setTo(0.5, 0.5); } + function clickedIt() { - if(this.image.visible == true) { + if (this.image.visible == true) { this.image.visible = false; } else { this.image.visible = true; diff --git a/Tests/buttons/basic button.js b/Tests/buttons/basic button.js index e523c871..9964da5a 100644 --- a/Tests/buttons/basic button.js +++ b/Tests/buttons/basic button.js @@ -2,29 +2,35 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('beast', 'assets/pics/shadow_of_the_beast2_karamoon.png'); game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); } + image: -Phaser.Sprite + Phaser.Sprite; button: -Phaser.UI.Button + Phaser.UI.Button; + function create() { // This is just an image that we'll toggle the display of when you click the button this.image = game.add.sprite(game.stage.centerX, 0, 'beast'); this.image.transform.origin.setTo(0.5, 0); + // This button is created from a sprite sheet. // Frame 0 = the 'down' state // Frame 1 = the 'out' state // Frame 2 = the 'over' state // The function "clickedIt" will be called when the button is clicked or touched this.button = game.add.button(game.stage.centerX, 400, 'button', clickedIt, this, 2, 1, 0); + // Just makes the button origin set to the middle, we only do this to center the button on-screen, no other reason this.button.transform.origin.setTo(0.5, 0.5); } + function clickedIt() { - if(this.image.visible == true) { + if (this.image.visible == true) { this.image.visible = false; } else { this.image.visible = true; diff --git a/Tests/buttons/camera buttons.js b/Tests/buttons/camera buttons.js index e4b4666f..7dcea269 100644 --- a/Tests/buttons/camera buttons.js +++ b/Tests/buttons/camera buttons.js @@ -2,25 +2,32 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { game.load.spritesheet('button', 'assets/buttons/button_sprite_sheet.png', 193, 71); } + var button; var secondCam; + function create() { button = game.add.button(200, 400, 'button', clickedIt, this, 2, 1, 0); button.origin.setTo(0.5, 0.5); + game.camera.width = 400; game.camera.texture.opaque = true; game.camera.texture.backgroundColor = 'rgb(100,0,0)'; + secondCam = game.add.camera(400, 0, 400, 600); secondCam.texture.opaque = true; secondCam.texture.backgroundColor = 'rgb(0,100,0)'; } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderSpriteWorldView(button, 32, 200); } + function clickedIt() { button.rotation += 10; } diff --git a/Tests/buttons/rotated buttons.js b/Tests/buttons/rotated buttons.js index 64d967de..446f3bcc 100644 --- a/Tests/buttons/rotated buttons.js +++ b/Tests/buttons/rotated buttons.js @@ -2,32 +2,39 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('beast', 'assets/pics/shadow_of_the_beast2_other_world.png'); game.load.atlas('button', 'assets/buttons/button_texture_atlas.png', 'assets/buttons/button_texture_atlas.json'); } + image: -Phaser.Sprite + Phaser.Sprite; button: -Phaser.UI.Button + Phaser.UI.Button; + function create() { // This is just an image that we'll toggle the display of when you click the button this.image = game.add.sprite(game.stage.centerX, 0, 'beast'); this.image.transform.origin.setTo(0.5, 0); + // This button is created from a texture atlas. // Instead of frame IDs (like with a sprite sheet) we can tell it to use frame names instead. // In this case our atlast frame names were called 'over', 'out' and 'down', but they could be anything you want. // The function "clickedIt" will be called when the button is clicked or touched this.button = game.add.button(game.stage.centerX, 400, 'button', clickedIt, this, 'over', 'out', 'down'); + // Makes the button origin set to the middle this.button.transform.origin.setTo(0.5, 0.5); } + function update() { // Rotate the button each frame, the button states will still work and respond. this.button.rotation += 1; } + function clickedIt() { - if(this.image.visible == true) { + if (this.image.visible == true) { this.image.visible = false; } else { this.image.visible = true; diff --git a/Tests/camera fx/mirror.js b/Tests/camera fx/mirror.js index ca47ce14..995c28d9 100644 --- a/Tests/camera fx/mirror.js +++ b/Tests/camera fx/mirror.js @@ -2,22 +2,29 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/ninja-masters2.png'); } + var mirror; + function create() { // Just set the world to be the size of the image we're loading in game.world.setSize(1216, 896); + // What we need is a camera 800x400 pixels in size as the mirror effect will be 200px tall and sit below it. // So we resize our default camera to 400px game.camera.height = 400; + // Add our effect to the camera mirror = game.camera.plugins.add(Phaser.Plugins.CameraFX.Mirror); + // The first 2 parameters are the x and y coordinates of where to display the effect. They are in STAGE coordinates, not World. // The next is a Rectangle making up the region of the Camera that we'll create the effect from (in this case the whole camera). // Finally we set the fill color that is put over the top of the mirror effect. mirror.start(0, 400, new Phaser.Rectangle(0, 0, 800, 400), 'rgba(0, 0, 100, 0.7)'); + // Experiment with variations on these to see the different mirror effects that can be achieved. //mirror.flipX = true; //mirror.flipY = true; @@ -25,15 +32,17 @@ // just a single image, but when used on a full game it can look really quite neat. game.add.sprite(0, 0, 'backdrop'); } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/camera fx/scanlines.js b/Tests/camera fx/scanlines.js index f0f3faf1..472b7a41 100644 --- a/Tests/camera fx/scanlines.js +++ b/Tests/camera fx/scanlines.js @@ -2,29 +2,38 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/ninja-masters2.png'); } + var scanlines; + function create() { game.world.setSize(1216, 896); + // Add our effect to the camera scanlines = game.camera.plugins.add(Phaser.Plugins.CameraFX.Scanlines); + // We'll have the scanlines spaced out every 2 pixels scanlines.spacing = 2; + // This is the color the lines will be drawn in scanlines.color = 'rgba(0, 0, 0, 0.8)'; + game.add.sprite(0, 0, 'backdrop'); } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/cameras/basic camera 1.js b/Tests/cameras/basic camera 1.js index 65e10e62..8301de2d 100644 --- a/Tests/cameras/basic camera 1.js +++ b/Tests/cameras/basic camera 1.js @@ -1,16 +1,21 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('backdrop', 'assets/pics/remember-me.jpg'); game.load.image('melon', 'assets/sprites/melon.png'); } + function create() { game.world.setSize(1920, 1200, true); + game.add.sprite(0, 0, 'backdrop'); - for(var i = 0; i < 100; i++) { + + for (var i = 0; i < 100; i++) { game.add.sprite(game.world.randomX, game.world.randomY, 'melon'); } + //game.camera.texture.alpha = 0.5; //game.camera.width = 400; game.camera.texture.opaque = true; @@ -19,24 +24,28 @@ game.camera.setPosition(game.stage.centerX, game.stage.centerY); //game.camera.setPosition(0, 0); //console.log('cam', game.camera.width, game.camera.height); - } + } + function update() { - game.camera.rotation++; - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + game.camera.rotation--; + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { //game.camera.x -= 4; game.camera.transform.scale.x -= 0.1; game.camera.transform.scale.y -= 0.1; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { //game.camera.x += 4; game.camera.transform.scale.x += 0.1; game.camera.transform.scale.y += 0.1; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 32); } diff --git a/Tests/cameras/basic camera 1.ts b/Tests/cameras/basic camera 1.ts index ed941ec9..f8eb42f8 100644 --- a/Tests/cameras/basic camera 1.ts +++ b/Tests/cameras/basic camera 1.ts @@ -35,7 +35,7 @@ function update() { - game.camera.rotation++; + game.camera.rotation--; if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { diff --git a/Tests/cameras/basic follow.js b/Tests/cameras/basic follow.js index 76b3df86..ea06ef61 100644 --- a/Tests/cameras/basic follow.js +++ b/Tests/cameras/basic follow.js @@ -1,8 +1,10 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + var ufo; var speed = 4; + function preload() { game.world.setSize(1280, 600, true); game.load.image('ground', 'assets/tests/ground-2x.png'); @@ -11,6 +13,7 @@ game.load.image('cloud0', 'assets/tests/cloud-big-2x.png'); game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png'); game.load.image('cloud2', 'assets/tests/cloud-small-2x.png'); + game.load.spritesheet('ufo', 'assets/sprites/ufo.png', 24, 21); } function create() { @@ -21,27 +24,29 @@ game.add.sprite(200, 120, 'cloud0').transform.scrollFactor.setTo(0.3, 0.3); game.add.sprite(-60, 120, 'cloud1').transform.scrollFactor.setTo(0.5, 0.3); game.add.sprite(900, 170, 'cloud2').transform.scrollFactor.setTo(0.7, 0.3); + // ufo spirte ufo = game.add.sprite(320, 240, 'ufo'); ufo.animations.add('fly', null, 30, false); ufo.animations.play('fly'); ufo.transform.origin.setTo(0.5, 0.5); + // make camera follows ufo game.camera.follow(ufo); } function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { ufo.x -= speed; ufo.rotation = -15; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { ufo.x += speed; ufo.rotation = 15; } else { ufo.rotation = 0; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { ufo.y -= speed; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { ufo.y += speed; } } diff --git a/Tests/cameras/camera alpha.js b/Tests/cameras/camera alpha.js index c6fc4a66..f31816ca 100644 --- a/Tests/cameras/camera alpha.js +++ b/Tests/cameras/camera alpha.js @@ -1,31 +1,40 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png'); game.load.image('car', 'assets/sprites/car90.png'); } + var car; var miniCam; + function create() { game.world.setSize(2240, 2240, true); + game.add.sprite(0, 0, 'grid'); + car = game.add.sprite(400, 300, 'car'); + game.camera.follow(car, Phaser.Types.CAMERA_FOLLOW_TOPDOWN); + miniCam = game.add.camera(0, 0, 300, 300); miniCam.follow(car, Phaser.Types.CAMERA_FOLLOW_TOPDOWN_TIGHT); miniCam.setBounds(0, 0, game.world.width, game.world.height); miniCam.texture.alpha = 0.7; } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { car.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { car.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { car.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { car.y += 4; } /* @@ -50,7 +59,8 @@ car.velocity.copyFrom(motion); } */ - } + } + function render() { Phaser.DebugUtils.renderSpriteInfo(car, 32, 32); Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 300); diff --git a/Tests/cameras/camera fx 1.js b/Tests/cameras/camera fx 1.js index a8260d2b..009f4975 100644 --- a/Tests/cameras/camera fx 1.js +++ b/Tests/cameras/camera fx 1.js @@ -1,8 +1,10 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + var btn1, btn2, btn3; var fx; + function preload() { game.world.setSize(800, 600, true); game.load.image('blue', 'assets/tests/blue-circle.png'); @@ -14,7 +16,7 @@ btn2 = game.add.button(426, 86, 'yellow', forceFade, this); btn3 = game.add.button(221, 318, 'magenta', fadeWithCallback, this); //fx = game.camera.fx.add(Phaser.FX.Camera.Fade); - } + } function render() { Phaser.DebugUtils.context.fillStyle = '#fff'; Phaser.DebugUtils.context.fillText('Press to fade.', 114 + 90, 34 + 130); diff --git a/Tests/cameras/camera fx 2.js b/Tests/cameras/camera fx 2.js index d8f3a480..bc6603c3 100644 --- a/Tests/cameras/camera fx 2.js +++ b/Tests/cameras/camera fx 2.js @@ -1,8 +1,10 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + var btn1, btn2, btn3; var fx; + function preload() { game.world.setSize(800, 600, true); game.load.image('blue', 'assets/tests/blue-circle.png'); @@ -15,7 +17,7 @@ btn3 = game.add.button(221, 318, 'magenta', flashWithCallback, this); // Usage of flash fx is the same as fade. //fx = game.camera.fx.add(Phaser.FX.Camera.Flash); - } + } function render() { Phaser.DebugUtils.context.fillStyle = '#fff'; Phaser.DebugUtils.context.fillText('Press to flash.', 114 + 90, 34 + 130); diff --git a/Tests/cameras/camera fx 3.js b/Tests/cameras/camera fx 3.js index 989f8d86..72b318fa 100644 --- a/Tests/cameras/camera fx 3.js +++ b/Tests/cameras/camera fx 3.js @@ -1,8 +1,10 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + var btn1, btn2, btn3; var fx; + function preload() { game.world.setSize(800, 600, true); game.load.image('blue', 'assets/tests/blue-circle.png'); @@ -15,7 +17,7 @@ btn3 = game.add.button(221, 318, 'magenta', shakeWithCallback, this); // Usage of shake fx is the same as fade and flash. //fx = game.camera.fx.add(Phaser.FX.Camera.Shake); - } + } function render() { Phaser.DebugUtils.context.fillStyle = '#fff'; Phaser.DebugUtils.context.fillText('Press to shake.', 114 + 90, 34 + 130); diff --git a/Tests/cameras/camera rotation.js b/Tests/cameras/camera rotation.js index 8a81cf3c..b677a210 100644 --- a/Tests/cameras/camera rotation.js +++ b/Tests/cameras/camera rotation.js @@ -1,36 +1,45 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('melon', 'assets/sprites/melon.png'); } + var car; var miniCam; + function create() { game.world.setSize(3000, 3000, true); game.stage.backgroundColor = 'rgb(20,20,50)'; - for(var i = 0; i < 1000; i++) { + + for (var i = 0; i < 1000; i++) { game.add.sprite(game.world.randomX, game.world.randomY, 'melon'); } + game.camera.transform.origin.setTo(0.5, 0.5); game.camera.texture.opaque = true; game.camera.texture.backgroundColor = 'rgb(0,0,0)'; game.camera.setPosition(game.stage.centerX, game.stage.centerY); + //game.camera.setPosition(200, 0); game.camera.setSize(320, 320); } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.rotation -= 2; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.rotation += 2; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 32); } diff --git a/Tests/cameras/camera scale.js b/Tests/cameras/camera scale.js index fa0b4b60..1943b482 100644 --- a/Tests/cameras/camera scale.js +++ b/Tests/cameras/camera scale.js @@ -1,14 +1,18 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + var zombieCamera; + var zombie; var walkSpeed = 2, direction = 1; + function preload() { game.world.setSize(1280, 600, true); game.load.image('ground', 'assets/tests/ground-2x.png'); game.load.image('river', 'assets/tests/river-2x.png'); game.load.image('sky', 'assets/tests/sky-2x.png'); + game.load.spritesheet('zombie', 'assets/sprites/metalslug_monster39x40.png', 39, 40); } function create() { @@ -16,40 +20,48 @@ game.add.sprite(0, 0, 'sky'); game.add.sprite(0, 360, 'ground'); game.add.sprite(0, 400, 'river'); + // Create zombie spirte zombie = game.add.sprite(480, 336, 'zombie'); zombie.animations.add('walk', null, 30, true); zombie.animations.play('walk'); + // Create a small camera which looks at the zombie. // Use the same settings as the default camera. zombieCamera = game.add.camera(0, 0, 800, 600); + // Use x and y properties to set the target area. zombieCamera.x = 420; zombieCamera.y = 240; + // Resize the camera so that it will only look at 200x200 area. zombieCamera.setSize(200, 200); + // Scale the camera to 2.0, now its target will be 100x100. zombieCamera.transform.scale.setTo(2.0, 2.0); + // Use setPosition() method to set where the camera rendered // on the screen. zombieCamera.setPosition(0, 0); } function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { zombieCamera.x -= 2; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { zombieCamera.x += 2; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { zombieCamera.y -= 2; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { zombieCamera.y += 2; } + // zombie wandering update zombie.x += walkSpeed * direction; - if(zombie.x > 540 || zombie.x < 440) { + if (zombie.x > 540 || zombie.x < 440) { // Change walk direction. direction *= -1; + // Flip zombie's animation. zombie.texture.flippedX = !zombie.texture.flippedX; } diff --git a/Tests/cameras/camera texture.js b/Tests/cameras/camera texture.js index a84f408a..3924aff5 100644 --- a/Tests/cameras/camera texture.js +++ b/Tests/cameras/camera texture.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { game.world.setSize(800, 600, true); game.load.image('background', 'assets/misc/water_texture.jpg'); diff --git a/Tests/cameras/follow styles.js b/Tests/cameras/follow styles.js index 88a59aa1..8af7c3cf 100644 --- a/Tests/cameras/follow styles.js +++ b/Tests/cameras/follow styles.js @@ -1,9 +1,12 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + var ufo, speed = 4; + var btn0, btn1, btn2, btn3; var style = 'default'; + function preload() { game.world.setSize(1280, 800, true); game.load.image('ground', 'assets/tests/ground-2x.png'); @@ -12,7 +15,9 @@ game.load.image('cloud0', 'assets/tests/cloud-big-2x.png'); game.load.image('cloud1', 'assets/tests/cloud-narrow-2x.png'); game.load.image('cloud2', 'assets/tests/cloud-small-2x.png'); + game.load.spritesheet('button', 'assets/buttons/follow-style-button.png', 224, 70); + game.load.spritesheet('ufo', 'assets/sprites/ufo.png', 24, 21); } function create() { @@ -23,13 +28,16 @@ game.add.sprite(200, 120, 'cloud0').transform.scrollFactor.setTo(0.3, 0.1); game.add.sprite(-60, 120, 'cloud1').transform.scrollFactor.setTo(0.5, 0.1); game.add.sprite(900, 170, 'cloud2').transform.scrollFactor.setTo(0.7, 0.1); + // ufo spirte ufo = game.add.sprite(360, 240, 'ufo'); ufo.animations.add('fly', null, 30, false); ufo.animations.play('fly'); ufo.transform.origin.setTo(0.5, 0.5); + // make camera follows ufo game.camera.follow(ufo); + // follow style switch buttons btn0 = game.add.button(16, 40, 'button', lockonFollow, 0, 0, 0); btn1 = game.add.button(16, 120, 'button', platformerFollow, 1, 1, 1); @@ -37,25 +45,26 @@ btn3 = game.add.button(16, 280, 'button', topdownTightFollow, 3, 3, 3); } function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { ufo.x -= speed; ufo.rotation = -15; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { ufo.x += speed; ufo.rotation = 15; } else { ufo.rotation = 0; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { ufo.y -= speed; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { ufo.y += speed; } } function render() { - if(game.camera.deadzone) { + if (game.camera.deadzone) { Phaser.DebugUtils.renderRectangle(game.camera.deadzone, 'rgba(240, 112, 111, 0.4)'); } + // game.camera.renderDebugInfo(400, 16); Phaser.DebugUtils.context.fillStyle = '#fff'; Phaser.DebugUtils.context.fillText('Click buttons to switch between different styles.', 360, 32); diff --git a/Tests/cameras/hide from camera.js b/Tests/cameras/hide from camera.js index fabbd81f..6fc8a761 100644 --- a/Tests/cameras/hide from camera.js +++ b/Tests/cameras/hide from camera.js @@ -1,43 +1,54 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + var radar; var ships = []; + var enemyCamera; + function preload() { game.load.image('radar-surface', 'assets/tests/radar-surface.png'); game.load.image('ship', 'assets/sprites/asteroids_ship_white.png'); game.load.image('enemy-ship', 'assets/sprites/asteroids_ship.png'); } + function create() { - // Add enemies and our ship the the world. - for(var i = 0; i < 4; i++) { + for (var i = 0; i < 4; i++) { ships.push(game.add.sprite(100 + i * 10, 280 + i * 16, 'enemy-ship')); } + var ourShip = game.add.sprite(160, 300, 'ship'); ships.push(ourShip); + // Radar sprite is a HUD. radar = game.add.sprite(0, 0, 'radar-surface'); + // Make the default camera rendered on the left half screen. game.camera.setSize(400, 600); game.camera.texture.backgroundColor = 'rgb(0,50,100)'; game.camera.texture.opaque = true; + // Add a new camera and render it on the right half screen. // The newly created is the enemies' camera, which cannot "see" our ship. enemyCamera = game.add.camera(400, 0, 400, 600); enemyCamera.texture.backgroundColor = 'rgb(100,0,50)'; enemyCamera.texture.opaque = true; + // Hide our ship on the enemies' camera. enemyCamera.hide(ourShip); } + function update() { - for(var i = 0; i < ships.length; i++) { + for (var i = 0; i < ships.length; i++) { ships[i].x += 4; - if(ships[i].x > 400) { + + if (ships[i].x > 400) { ships[i].x = 40; } } } + function render() { Phaser.DebugUtils.renderText('Left is the player\'s camera and right is the enemies\' camera.', 32, 32); } diff --git a/Tests/cameras/multi camera.js b/Tests/cameras/multi camera.js index ecaf01ff..4b0727d5 100644 --- a/Tests/cameras/multi camera.js +++ b/Tests/cameras/multi camera.js @@ -1,14 +1,18 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + var zombieCamera; + var zombie; var walkSpeed = 2, direction = 1; + function preload() { game.world.setSize(1280, 600, true); game.load.image('ground', 'assets/tests/ground-2x.png'); game.load.image('river', 'assets/tests/river-2x.png'); game.load.image('sky', 'assets/tests/sky-2x.png'); + game.load.spritesheet('zombie', 'assets/sprites/metalslug_monster39x40.png', 39, 40); } function create() { @@ -16,38 +20,45 @@ game.add.sprite(0, 0, 'sky'); game.add.sprite(0, 360, 'ground'); game.add.sprite(0, 400, 'river'); + // Create zombie spirte zombie = game.add.sprite(480, 336, 'zombie'); zombie.animations.add('walk', null, 30, true); zombie.animations.play('walk'); + // Create a small camera which looks at the zombie. // Use the same settings as the default camera. zombieCamera = game.add.camera(0, 0, 800, 600); + // Use x and y properties to set the target area. zombieCamera.x = 420; zombieCamera.y = 240; + // Resize the camera so that it will only look at 200x200 area. zombieCamera.setSize(200, 200); + // Use setPosition() method to set where the camera rendered // on the screen. zombieCamera.setPosition(0, 0); } function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { zombieCamera.x -= 2; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { zombieCamera.x += 2; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { zombieCamera.y -= 2; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { zombieCamera.y += 2; } + // zombie wandering update zombie.x += walkSpeed * direction; - if(zombie.x > 540 || zombie.x < 440) { + if (zombie.x > 540 || zombie.x < 440) { // Change walk direction. direction *= -1; + // Flip zombie's animation. zombie.texture.flippedX = !zombie.texture.flippedX; } diff --git a/Tests/cameras/scrollfactor 1.js b/Tests/cameras/scrollfactor 1.js index 9f5ee199..531fc101 100644 --- a/Tests/cameras/scrollfactor 1.js +++ b/Tests/cameras/scrollfactor 1.js @@ -1,30 +1,37 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.world.setSize(1920, 1200, true); + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); game.load.image('ball', 'assets/sprites/shinyball.png'); } + function create() { game.add.sprite(0, 0, 'backdrop'); - for(var i = 0; i < 400; i++) { + + for (var i = 0; i < 400; i++) { var tempBall = game.add.sprite(game.world.randomX * 2, game.world.randomY * 2, 'ball'); tempBall.transform.scrollFactor.setTo(2, 2); } } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 32); } diff --git a/Tests/cameras/scrollfactor 2.js b/Tests/cameras/scrollfactor 2.js index bcb5b569..7417cddd 100644 --- a/Tests/cameras/scrollfactor 2.js +++ b/Tests/cameras/scrollfactor 2.js @@ -1,28 +1,34 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.world.setSize(1600, 800, true); + game.load.image('disk', 'assets/pics/devilstar_demo_download_disk.png'); } + function create() { - for(var i = 0; i < 10; i++) { + for (var i = 0; i < 10; i++) { var temp = game.add.sprite(600 + (10 * i), 200 + (10 * i), 'disk'); temp.transform.scrollFactor.setTo(i / 2, i / 2); } } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 32); } diff --git a/Tests/cameras/scrollfactor compare.js b/Tests/cameras/scrollfactor compare.js index 8cd2b944..4463c7fd 100644 --- a/Tests/cameras/scrollfactor compare.js +++ b/Tests/cameras/scrollfactor compare.js @@ -13,22 +13,24 @@ function create() { // background sky, which does not move at all game.add.sprite(0, 0, 'sky').transform.scrollFactor.setTo(0, 0); + // clouds with different scroll factor which moves slower than camera game.add.sprite(200, 120, 'cloud0').transform.scrollFactor.setTo(0.3, 0.3); game.add.sprite(-60, 120, 'cloud1').transform.scrollFactor.setTo(0.5, 0.3); game.add.sprite(900, 170, 'cloud2').transform.scrollFactor.setTo(0.7, 0.3); + // forground objects which moves equal or faster than camera game.add.sprite(0, 360, 'ground').transform.scrollFactor.setTo(0.5, 0.5); game.add.sprite(0, 400, 'river').transform.scrollFactor.setTo(1.3, 1.3); } function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 3; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 3; } } function render() { // game.camera.renderDebugInfo(32, 32); - } + } })(); diff --git a/Tests/cameras/world sprite.js b/Tests/cameras/world sprite.js index 79c45b75..37f3a8aa 100644 --- a/Tests/cameras/world sprite.js +++ b/Tests/cameras/world sprite.js @@ -2,53 +2,39 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.world.setSize(1920, 1200, true); + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); game.load.image('ball', 'assets/sprites/mana_card.png'); } + var ball; + function create() { game.add.sprite(0, 0, 'backdrop'); + ball = game.add.sprite(200, 200, 'ball'); + ball.body.velocity.x = 50; ball.transform.scale.setTo(2, 2); } + function update() { - /* - if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) - { - game.camera.x -= 4; - //ball.x -= 4; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) - { - game.camera.x += 4; - //ball.x += 4; - } - - if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) - { - game.camera.y -= 4; - //ball.y -= 4; - } - else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) - { - game.camera.y += 4; - //ball.y += 4; - } - */ - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { ball.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { ball.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { ball.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { ball.y += 4; } } + function render() { Phaser.DebugUtils.renderCameraInfo(game.camera, 32, 32); Phaser.DebugUtils.renderSpriteInfo(ball, 32, 200); diff --git a/Tests/groups/bring to top 1.js b/Tests/groups/bring to top 1.js index 1c04b58f..5e9d05c2 100644 --- a/Tests/groups/bring to top 1.js +++ b/Tests/groups/bring to top 1.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('beast', 'assets/pics/shadow_of_the_beast2_karamoon.png'); game.load.image('snot', 'assets/pics/nslide_snot.png'); @@ -9,52 +10,66 @@ game.load.image('coke', 'assets/sprites/cokecan.png'); game.load.image('disk', 'assets/sprites/oz_pov_melting_disk.png'); } + var group1; var group2; var coke; var disk; + function create() { // Create a background image game.add.sprite(0, 0, 'beast'); + // Create a Group that will sit above the background image group1 = game.add.group(11); + // Create a Group that will sit above Group 1 group2 = game.add.group(11); - // Now let's create some random sprites and enable them all for drag and 'bring to top' - for(var i = 0; i < 10; i++) { + + for (var i = 0; i < 10; i++) { //var tempSprite: Phaser.Sprite = group1.addNewSprite(game.stage.randomX, game.stage.randomY, 'atari1'); //var tempSprite: Phaser.Sprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'atari1'); var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, 'atari1'); + tempSprite.name = 'atari' + i; tempSprite.input.start(i, false, true); tempSprite.input.enableDrag(false, true); + group1.add(tempSprite); + // Sonics //var tempSprite: Phaser.Sprite = group2.addNewSprite(game.stage.randomX, game.stage.randomY, 'sonic'); //var tempSprite: Phaser.Sprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'sonic'); var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, 'sonic'); + tempSprite.name = 'sonic' + i; tempSprite.input.start(10 + i, false, true); tempSprite.input.enableDrag(false, true); + group2.add(tempSprite); } + // Add 2 control sprites into each group - these cannot be dragged but should be bought to the top each time coke = group1.addNewSprite(100, 100, 'coke'); disk = group2.addNewSprite(400, 300, 'disk'); + // Create a foreground image - everything should appear behind this, even when dragged var snot = game.add.sprite(game.stage.centerX, game.stage.height, 'snot'); snot.origin.setTo(0.5, 1); // You can click and drag any sprite but Sonic sprites should always appear above the Atari sprites // and both types of sprite should only ever appear above the background and behind the - } + } + function update() { - if(game.input.keyboard.justReleased(Phaser.Keyboard.ONE)) { + if (game.input.keyboard.justReleased(Phaser.Keyboard.ONE)) { coke.bringToTop(); } - if(game.input.keyboard.justReleased(Phaser.Keyboard.TWO)) { + + if (game.input.keyboard.justReleased(Phaser.Keyboard.TWO)) { disk.bringToTop(); } } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); } diff --git a/Tests/groups/create group 1.js b/Tests/groups/create group 1.js index 893a3208..8aee302a 100644 --- a/Tests/groups/create group 1.js +++ b/Tests/groups/create group 1.js @@ -1,24 +1,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png'); } + var firstGroup; + function create() { // Here we'll create a new Group firstGroup = game.add.group(); - // And add some sprites to it - for(var i = 0; i < 10; i++) { + + for (var i = 0; i < 10; i++) { // Create a new sprite at a random screen location var newSprite = new Phaser.Sprite(game, game.stage.randomX, game.stage.randomY, 'sonic'); + // This set-ups a listener for the event, view your console.log output to see the result newSprite.events.onAddedToGroup.add(logGroupAdd); + // Add the sprite to the Group firstGroup.add(newSprite); } } + function logGroupAdd(sprite, group, zIndex) { console.log('Sprite added to Group', group.ID, 'at z-index:', zIndex); } diff --git a/Tests/groups/display order.js b/Tests/groups/display order.js index cf537b60..4b049682 100644 --- a/Tests/groups/display order.js +++ b/Tests/groups/display order.js @@ -1,29 +1,38 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('atari1', 'assets/sprites/atari130xe.png'); game.load.image('atari2', 'assets/sprites/atari800xl.png'); game.load.image('card', 'assets/sprites/mana_card.png'); } + var items; var card; + function create() { items = game.add.group(); + // Items are rendered in the depth order in which they are added to the Group items.addNewSprite(64, 100, 'atari1'); card = items.addNewSprite(240, 80, 'card'); items.addNewSprite(280, 100, 'atari2'); + game.input.onTap.addOnce(removeCard, this); } + function removeCard() { // Now let's kill the card sprite card.kill(); + game.input.onTap.addOnce(replaceCard, this); } + function replaceCard() { // And bring it back to life again - I assume it will render in the same place as before? var bob = items.getFirstDead(); + bob.revive(); } })(); diff --git a/Tests/groups/swap children.js b/Tests/groups/swap children.js index 51cef254..40295240 100644 --- a/Tests/groups/swap children.js +++ b/Tests/groups/swap children.js @@ -1,18 +1,23 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('atari1', 'assets/sprites/atari130xe.png'); game.load.image('atari2', 'assets/sprites/atari800xl.png'); } + var atari1; var atari2; + function create() { // Items are rendered in the depth order in which they are added to the Group atari1 = game.add.sprite(100, 100, 'atari1'); atari2 = game.add.sprite(250, 90, 'atari2'); + game.input.onTap.add(swapSprites, this); } + function swapSprites() { // The 2 Sprites are in the global world Group, but this will work for any Group: game.world.group.swap(atari1, atari2); diff --git a/Tests/input/bring to top.js b/Tests/input/bring to top.js index ff97e587..3973270f 100644 --- a/Tests/input/bring to top.js +++ b/Tests/input/bring to top.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { game.load.image('atari1', 'assets/sprites/atari130xe.png'); game.load.image('atari2', 'assets/sprites/atari800xl.png'); @@ -11,16 +12,18 @@ game.load.image('diamond', 'assets/sprites/diamond.png'); game.load.image('mushroom', 'assets/sprites/mushroom2.png'); } + function create() { // This returns an array of all the image keys in the cache var images = game.cache.getImageKeys(); - // Now let's create some random sprites and enable them all for drag and 'bring to top' - for(var i = 0; i < 20; i++) { + + for (var i = 0; i < 20; i++) { var tempSprite = game.add.sprite(game.stage.randomX, game.stage.randomY, game.rnd.pick(images)); tempSprite.input.start(i, false, true); tempSprite.input.enableDrag(false, true); } } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); } diff --git a/Tests/input/drag sprite 1.js b/Tests/input/drag sprite 1.js index ccd54b7a..9b864759 100644 --- a/Tests/input/drag sprite 1.js +++ b/Tests/input/drag sprite 1.js @@ -1,20 +1,26 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/atari130xe.png'); } + var sprite; + function create() { sprite = game.add.sprite(200, 200, 'sprite'); + // Enable Input detection. Sprites have this disabled by default, // so you have to start it if you want to interact with them. sprite.input.start(0, false, true); + // This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false) // or if it will snap to the center (true) sprite.input.enableDrag(true); } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32); diff --git a/Tests/input/drag sprite 2.js b/Tests/input/drag sprite 2.js index 20eef4c9..6d014dac 100644 --- a/Tests/input/drag sprite 2.js +++ b/Tests/input/drag sprite 2.js @@ -1,19 +1,26 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/atari800.png'); } + var sprite; + function create() { sprite = game.add.sprite(200, 200, 'sprite'); + sprite.input.start(0, false, true); + sprite.input.enableDrag(true); + // The drag offset allows us to position the sprite relative to the pointer (+ lock) position // In this case it will be positioned -100px above the pointer sprite.input.dragOffset.y = -100; } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32); diff --git a/Tests/input/drag sprite 3.js b/Tests/input/drag sprite 3.js index 8fd10483..202a1ba1 100644 --- a/Tests/input/drag sprite 3.js +++ b/Tests/input/drag sprite 3.js @@ -1,20 +1,28 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/atari800.png'); } + var sprite; + function create() { sprite = game.add.sprite(500, 300, 'sprite'); + sprite.input.start(0, false, true); + // This will ensure the sprite is dragged from its center sprite.input.enableDrag(true); } + function render() { Phaser.DebugUtils.renderSpriteCorners(sprite); + Phaser.DebugUtils.renderInputInfo(32, 32); + Phaser.DebugUtils.renderSpriteInfo(sprite, 32, 200); } })(); diff --git a/Tests/input/game scale 1.js b/Tests/input/game scale 1.js index f0b705fc..bb6b0bf9 100644 --- a/Tests/input/game scale 1.js +++ b/Tests/input/game scale 1.js @@ -2,32 +2,40 @@ (function () { // Here we create a tiny game (320x240 in size) var game = new Phaser.Game(this, 'game', 320, 240, preload, create, update, render); + function preload() { // This sets a limit on the up-scale game.stage.scale.maxWidth = 800; game.stage.scale.maxHeight = 600; + // Then we tell Phaser that we want it to scale up to whatever the browser can handle, but to do it proportionally game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL; + game.load.image('melon', 'assets/sprites/melon.png'); } + function create() { game.world.setSize(2000, 2000); - for(var i = 0; i < 1000; i++) { + + for (var i = 0; i < 1000; i++) { game.add.sprite(game.world.randomX, game.world.randomY, 'melon'); } } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderInputInfo(16, 16); } diff --git a/Tests/input/motion lock 2.js b/Tests/input/motion lock 2.js index 7763e6e4..25fc09eb 100644 --- a/Tests/input/motion lock 2.js +++ b/Tests/input/motion lock 2.js @@ -1,23 +1,31 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/darkwing_crazy.png'); } + var sprite; + function create() { game.stage.backgroundColor = 'rgb(85,85,85)'; + sprite = game.add.sprite(200, 200, 'sprite'); + // Enable Input detection. Sprites have this disabled by default, // so you have to start it if you want to interact with them. sprite.input.start(0, false, true); + // This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false) // or if it will snap to the center (true) sprite.input.enableDrag(); + // This will lock the sprite so it can only be dragged vertically, not horizontally sprite.input.allowHorizontalDrag = false; } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32); diff --git a/Tests/input/motion lock.js b/Tests/input/motion lock.js index b1084922..227eaa68 100644 --- a/Tests/input/motion lock.js +++ b/Tests/input/motion lock.js @@ -1,23 +1,31 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/parsec.png'); } + var sprite; + function create() { game.stage.backgroundColor = 'rgb(85,85,85)'; + sprite = game.add.sprite(200, 400, 'sprite'); + // Enable Input detection. Sprites have this disabled by default, // so you have to start it if you want to interact with them. sprite.input.start(0, false, true); + // This allows you to drag the sprite. The parameter controls if you drag from the position you touched it (false) // or if it will snap to the center (true) sprite.input.enableDrag(); + // This will lock the sprite so it can only be dragged horizontally, not vertically sprite.input.allowVerticalDrag = false; } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32); diff --git a/Tests/input/multitouch.js b/Tests/input/multitouch.js index 583ba9d5..8f724ea7 100644 --- a/Tests/input/multitouch.js +++ b/Tests/input/multitouch.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, null, null, null, render); + function render() { Phaser.DebugUtils.renderPointer(game.input.pointer1); Phaser.DebugUtils.renderPointer(game.input.pointer2); diff --git a/Tests/input/over sprite 1.js b/Tests/input/over sprite 1.js index 60856943..ad2e6f96 100644 --- a/Tests/input/over sprite 1.js +++ b/Tests/input/over sprite 1.js @@ -1,16 +1,21 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/atari130xe.png'); } + var sprite; + function create() { sprite = game.add.sprite(200, 200, 'sprite'); + // Enable Input detection sprite.input.start(0, false, true); } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderSpriteInputInfo(sprite, 300, 32); diff --git a/Tests/input/over sprite 2.js b/Tests/input/over sprite 2.js index 2172f135..1bd49c6b 100644 --- a/Tests/input/over sprite 2.js +++ b/Tests/input/over sprite 2.js @@ -1,23 +1,27 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('sprite', 'assets/sprites/shinyball.png'); } + var sprite; + function create() { - // Create a load of sprites - for(var i = 0; i < 26; i++) { + for (var i = 0; i < 26; i++) { var tempSprite = game.add.sprite(i * 32, 100, 'sprite'); tempSprite.input.start(0, false, true); tempSprite.events.onInputOver.add(dropSprite, this); } } + function dropSprite(sprite) { sprite.body.velocity.y = 300; sprite.input.enabled = false; } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); } diff --git a/Tests/input/point in rotated sprite.js b/Tests/input/point in rotated sprite.js index 65f14e11..285ccd69 100644 --- a/Tests/input/point in rotated sprite.js +++ b/Tests/input/point in rotated sprite.js @@ -1,38 +1,51 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('sprite', 'assets/sprites/atari130xe.png'); } + var sprite; var rotate = false; + function create() { sprite = game.add.sprite(200, 200, 'sprite'); + game.input.onTap.add(rotateIt, this); } + function rotateIt() { - if(rotate == false) { + if (rotate == false) { rotate = true; } else { rotate = false; } } + var inPoint = false; + function update() { - if(rotate) { + if (rotate) { sprite.rotation++; } + inPoint = Phaser.SpriteUtils.overlapsXY(sprite, game.input.x, game.input.y); } + function render() { game.stage.context.save(); game.stage.context.fillStyle = 'rgb(255,0,255)'; + game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y); + Phaser.DebugUtils.renderInputInfo(32, 32); + game.stage.context.fillText('in: ' + inPoint, 300, 32); + game.stage.context.restore(); } })(); diff --git a/Tests/input/rotated sprites.js b/Tests/input/rotated sprites.js index dd5e2ea2..a9a16100 100644 --- a/Tests/input/rotated sprites.js +++ b/Tests/input/rotated sprites.js @@ -1,31 +1,40 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('atari1', 'assets/sprites/atari130xe.png'); game.load.image('atari2', 'assets/sprites/atari800xl.png'); game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png'); } + var atari1; var atari2; var sonic; + function create() { atari1 = game.add.sprite(200, 200, 'atari1'); atari2 = game.add.sprite(500, 400, 'atari2'); sonic = game.add.sprite(400, 500, 'sonic'); + atari1.origin.setTo(0.5, 0.5); atari1.rotation = 35; + atari2.origin.setTo(1, 1); atari2.rotation = 80; + sonic.rotation = 140; + atari1.input.start(0, false, true); atari2.input.start(1, false, true); sonic.input.start(2, false, true); + atari1.input.enableDrag(); atari2.input.enableDrag(); sonic.input.enableDrag(); } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); } diff --git a/Tests/input/snap 1.js b/Tests/input/snap 1.js index ccd7128d..b3d63709 100644 --- a/Tests/input/snap 1.js +++ b/Tests/input/snap 1.js @@ -1,31 +1,40 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('grid', 'assets/tests/debug-grid-1920x1920.png'); game.load.image('atari1', 'assets/sprites/atari130xe.png'); game.load.image('atari2', 'assets/sprites/atari800xl.png'); } + var atari1; var atari2; var sonic; + function create() { game.add.sprite(0, 0, 'grid'); + atari1 = game.add.sprite(128, 128, 'atari1'); atari2 = game.add.sprite(256, 256, 'atari2'); + // Input Enable the sprites atari1.input.start(0, false, true); atari2.input.start(1, false, true); + // Allow dragging atari1.input.enableDrag(); atari2.input.enableDrag(); + // Enable snapping. For the atari1 sprite it will snap as its dragged around and on release. // The snap is set to every 32x32 pixels. atari1.input.enableSnap(32, 32, true, true); + // For the atari2 sprite it will snap only when released, not on drag. atari2.input.enableSnap(32, 32, false, true); } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); } diff --git a/Tests/input/touch priority.js b/Tests/input/touch priority.js index 03a48dea..878161e5 100644 --- a/Tests/input/touch priority.js +++ b/Tests/input/touch priority.js @@ -1,26 +1,32 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, null, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('atari1', 'assets/sprites/atari130xe.png'); game.load.image('atari2', 'assets/sprites/atari800xl.png'); game.load.image('sonic', 'assets/sprites/sonic_havok_sanity.png'); } + var atari1; var atari2; var sonic; + function create() { atari1 = game.add.sprite(100, 100, 'atari1'); atari2 = game.add.sprite(300, 200, 'atari2'); sonic = game.add.sprite(400, 300, 'sonic'); + atari1.input.start(0, false, true); atari2.input.start(1, false, true); sonic.input.start(2, false, true); + atari1.input.enableDrag(); atari2.input.enableDrag(); sonic.input.enableDrag(); } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); } diff --git a/Tests/input/world coordinates.js b/Tests/input/world coordinates.js index 9b1d4d84..bb53a91f 100644 --- a/Tests/input/world coordinates.js +++ b/Tests/input/world coordinates.js @@ -1,26 +1,33 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.world.setSize(1920, 1200, true); + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); } + var test; + function create() { game.add.sprite(0, 0, 'backdrop'); } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderInputInfo(32, 32); Phaser.DebugUtils.renderPointer(game.input.activePointer); diff --git a/Tests/input/world drag.js b/Tests/input/world drag.js index a3efebd6..60f1aa3d 100644 --- a/Tests/input/world drag.js +++ b/Tests/input/world drag.js @@ -1,18 +1,24 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.world.setSize(1920, 1200, true); + game.load.image('backdrop', 'assets/pics/remember-me.jpg'); game.load.image('diamond', 'assets/sprites/diamond.png'); } + var test; + function create() { game.add.sprite(0, 0, 'backdrop'); - for(var i = 0; i < 50; i++) { + + for (var i = 0; i < 50; i++) { var sprite = game.add.sprite(game.world.randomX, game.world.randomY, 'diamond'); sprite.input.start(i, false, true); - if(i < 25) { + + if (i < 25) { sprite.input.enableDrag(false); } else { sprite.input.enableDrag(true); @@ -20,18 +26,21 @@ } } } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { Phaser.DebugUtils.renderCameraInfo(game.camera, 16, 32); Phaser.DebugUtils.renderInputInfo(16, 200); diff --git a/Tests/misc/point1.js b/Tests/misc/point1.js index bae9f933..19800efa 100644 --- a/Tests/misc/point1.js +++ b/Tests/misc/point1.js @@ -1,48 +1,61 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('box2', 'assets/tests/320x200.png'); game.load.image('box1', 'assets/sprites/oz_pov_melting_disk.png'); game.load.image('box', 'assets/sprites/bunny.png'); } + var sprite; var rotate = false; + function create() { game.stage.backgroundColor = 'rgb(0,0,0)'; + sprite = game.add.sprite(game.stage.centerX, game.stage.centerY, 'box'); + //sprite.transform.scale.setTo(0.5, 0.5); sprite.transform.origin.setTo(1, 1); + //sprite.transform.origin.setTo(0.5, 0.5); game.input.onTap.add(rotateIt, this); //game.add.tween(sprite.transform.scale).to({ x: 0.5, y: 0.5 }, 2000, Phaser.Easing.Linear.None, true, 0, true); - } + } + function rotateIt() { - if(rotate == false) { + if (rotate == false) { rotate = true; } else { rotate = false; } } + function update() { - if(rotate) { + if (rotate) { sprite.rotation++; } } + function render() { game.stage.context.save(); game.stage.context.fillStyle = 'rgb(255,0,255)'; + game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y); + game.stage.context.fillRect(sprite.transform.center.x, sprite.transform.center.y, 2, 2); game.stage.context.fillRect(sprite.transform.upperLeft.x, sprite.transform.upperLeft.y, 2, 2); game.stage.context.fillRect(sprite.transform.upperRight.x, sprite.transform.upperRight.y, 2, 2); game.stage.context.fillRect(sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y, 2, 2); game.stage.context.fillRect(sprite.transform.bottomRight.x, sprite.transform.bottomRight.y, 2, 2); + game.stage.context.strokeStyle = 'rgb(255,255,0)'; game.stage.context.strokeRect(sprite.cameraView.x, sprite.cameraView.y, sprite.cameraView.width, sprite.cameraView.height); + game.stage.context.restore(); } })(); diff --git a/Tests/misc/point2.js b/Tests/misc/point2.js index ee550644..a03fe5a1 100644 --- a/Tests/misc/point2.js +++ b/Tests/misc/point2.js @@ -1,45 +1,59 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18); } + var sprite; var rotate = false; + function create() { game.stage.backgroundColor = 'rgb(0,0,0)'; + sprite = game.add.sprite(game.stage.centerX, game.stage.centerY, 'mummy'); + sprite.animations.add('walk'); sprite.animations.play('walk', 20, true); + sprite.transform.scale.setTo(4, 4); + game.input.onTap.add(rotateIt, this); } + function rotateIt() { - if(rotate == false) { + if (rotate == false) { rotate = true; } else { rotate = false; } } + function update() { - if(rotate) { + if (rotate) { sprite.rotation++; } } + function render() { game.stage.context.save(); game.stage.context.fillStyle = 'rgb(255,0,255)'; + game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y); + game.stage.context.fillRect(sprite.transform.center.x, sprite.transform.center.y, 2, 2); game.stage.context.fillRect(sprite.transform.upperLeft.x, sprite.transform.upperLeft.y, 2, 2); game.stage.context.fillRect(sprite.transform.upperRight.x, sprite.transform.upperRight.y, 2, 2); game.stage.context.fillRect(sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y, 2, 2); game.stage.context.fillRect(sprite.transform.bottomRight.x, sprite.transform.bottomRight.y, 2, 2); + game.stage.context.strokeStyle = 'rgb(255,255,0)'; game.stage.context.strokeRect(sprite.cameraView.x, sprite.cameraView.y, sprite.cameraView.width, sprite.cameraView.height); + game.stage.context.restore(); } })(); diff --git a/Tests/misc/point3.js b/Tests/misc/point3.js index b4ea9625..bf0a2039 100644 --- a/Tests/misc/point3.js +++ b/Tests/misc/point3.js @@ -1,46 +1,61 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.atlas('bot', 'assets/sprites/running_bot.png', null, botData); } + var sprite; var rotate = false; + function create() { game.stage.backgroundColor = 'rgb(0,0,0)'; + sprite = game.add.sprite(game.stage.centerX, game.stage.centerY, 'bot'); + sprite.animations.add('run', null, 10, true); + sprite.animations.play('run'); + //sprite.transform.scale.setTo(4, 4); game.input.onTap.add(rotateIt, this); } + function rotateIt() { - if(rotate == false) { + if (rotate == false) { rotate = true; } else { rotate = false; } } + function update() { - if(rotate) { + if (rotate) { sprite.rotation++; } } + function render() { game.stage.context.save(); game.stage.context.fillStyle = 'rgb(255,0,255)'; + game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperLeft.x) + ' y: ' + Math.round(sprite.transform.upperLeft.y), sprite.transform.upperLeft.x, sprite.transform.upperLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.upperRight.x) + ' y: ' + Math.round(sprite.transform.upperRight.y), sprite.transform.upperRight.x, sprite.transform.upperRight.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomLeft.x) + ' y: ' + Math.round(sprite.transform.bottomLeft.y), sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y); game.stage.context.fillText('x: ' + Math.round(sprite.transform.bottomRight.x) + ' y: ' + Math.round(sprite.transform.bottomRight.y), sprite.transform.bottomRight.x, sprite.transform.bottomRight.y); + game.stage.context.fillRect(sprite.transform.center.x, sprite.transform.center.y, 2, 2); game.stage.context.fillRect(sprite.transform.upperLeft.x, sprite.transform.upperLeft.y, 2, 2); game.stage.context.fillRect(sprite.transform.upperRight.x, sprite.transform.upperRight.y, 2, 2); game.stage.context.fillRect(sprite.transform.bottomLeft.x, sprite.transform.bottomLeft.y, 2, 2); game.stage.context.fillRect(sprite.transform.bottomRight.x, sprite.transform.bottomRight.y, 2, 2); + game.stage.context.strokeStyle = 'rgb(255,255,0)'; game.stage.context.strokeRect(sprite.cameraView.x, sprite.cameraView.y, sprite.cameraView.width, sprite.cameraView.height); + game.stage.context.restore(); } + var botData = '{"frames": [{"filename": "running bot.swf/0000","frame": { "x": 34, "y": 128, "w": 56, "h": 60 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 2, "w": 56, "h": 60 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0001","frame": { "x": 54, "y": 0, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0002","frame": { "x": 54, "y": 58, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0003","frame": { "x": 0, "y": 192, "w": 34, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0004","frame": { "x": 0, "y": 64, "w": 54, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0005","frame": { "x": 196, "y": 0, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0006","frame": { "x": 0, "y": 0, "w": 54, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0007","frame": { "x": 140, "y": 0, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0008","frame": { "x": 34, "y": 188, "w": 50, "h": 60 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 3, "y": 2, "w": 50, "h": 60 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0009","frame": { "x": 0, "y": 128, "w": 34, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0010","frame": { "x": 84, "y": 188, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }}]}'; })(); diff --git a/Tests/mobile/sprite test 1.js b/Tests/mobile/sprite test 1.js index c202e4ae..7686e492 100644 --- a/Tests/mobile/sprite test 1.js +++ b/Tests/mobile/sprite test 1.js @@ -1,45 +1,59 @@ /// (function () { var game = new Phaser.Game(this, 'game', 320, 400, preload, create); + var emitter; + function preload() { game.load.image('backdrop1', 'assets/pics/atari_fujilogo.png'); game.load.image('backdrop2', 'assets/pics/acryl_bladerunner.png'); game.load.image('jet', 'assets/sprites/carrot.png'); + // This can help a lot on crappy old Android phones :) //game.framerate = 30; game.stage.backgroundColor = 'rgb(0,0,0)'; + //game.stage.scaleMode = Phaser.StageScaleMode.SHOW_ALL; game.stage.scaleMode = Phaser.StageScaleMode.EXACT_FIT; //game.stage.scaleMode = Phaser.StageScaleMode.NO_SCALE; - } + } + var pic1; var pic2; + function create() { console.log('created now'); + game.stage.enableOrientationCheck(false, true, 'backdrop2'); + pic1 = game.add.sprite(0, 0, 'backdrop1'); pic2 = game.add.sprite(0, 0, 'backdrop2'); + // Creates a basic emitter, bursting out 50 default sprites (i.e. 16x16 white boxes) emitter = game.add.emitter(game.stage.centerX, game.stage.centerY); emitter.makeParticles('jet', 50, false, 0); emitter.setRotation(0, 0); emitter.start(false, 10, 0.1); + game.stage.scale.enterLandscape.add(goneLandscape, this); game.stage.scale.enterPortrait.add(gonePortrait, this); + game.onRenderCallback = render; } + function goneLandscape() { pic1.visible = true; pic2.visible = false; } + function gonePortrait() { pic1.visible = false; pic2.visible = true; } + function render() { game.stage.context.fillStyle = 'rgb(255,0,0)'; game.stage.context.font = '20px Arial'; //game.stage.context.fillText("ttc: " + game._raf.timeToCall.toString(), 0, 64); - } + } })(); diff --git a/Tests/particles/graphic emitter.js b/Tests/particles/graphic emitter.js index bcd4d846..e2c6e601 100644 --- a/Tests/particles/graphic emitter.js +++ b/Tests/particles/graphic emitter.js @@ -1,10 +1,13 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + var emitter; + function preload() { game.load.image('jet', 'assets/sprites/jets.png'); } + function create() { emitter = game.add.emitter(game.stage.centerX, game.stage.centerY); emitter.makeParticles('jet', 100, false, 0); diff --git a/Tests/particles/mousetrail.js b/Tests/particles/mousetrail.js index 67b831e8..fcbc46da 100644 --- a/Tests/particles/mousetrail.js +++ b/Tests/particles/mousetrail.js @@ -1,28 +1,36 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + var emitter; + function preload() { game.load.image('jet', 'assets/sprites/particle1.png'); game.load.image('starfield', 'assets/misc/starfield.jpg'); } + var scroller; var emitter; + function create() { scroller = game.add.scrollZone('starfield', 0, 0, 1024, 1024); scroller.setSpeed(0, -1); + emitter = game.add.emitter(game.stage.centerX, game.stage.centerY); emitter.makeParticles('jet', 200); + emitter.texture.globalCompositeOperation = 'lighter'; + emitter.gravity = 300; emitter.setXSpeed(-50, 50); emitter.setYSpeed(-50, -100); emitter.setRotation(0, 0); emitter.start(false, 50, 0.02); } + function update() { emitter.x = game.input.x; emitter.y = game.input.y; //emitter.em - } + } })(); diff --git a/Tests/particles/multiple streams.js b/Tests/particles/multiple streams.js index 056c88f6..94c42ecd 100644 --- a/Tests/particles/multiple streams.js +++ b/Tests/particles/multiple streams.js @@ -1,12 +1,14 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + var emitter1; var emitter2; var emitter3; var emitter4; var emitter5; var emitter6; + function preload() { game.load.image('ball1', 'assets/sprites/aqua_ball.png'); game.load.image('ball2', 'assets/sprites/yellow_ball.png'); @@ -15,19 +17,24 @@ game.load.image('ball5', 'assets/sprites/blue_ball.png'); game.load.image('ball6', 'assets/sprites/green_ball.png'); } + function makeEmitter(emitter, x, y, graphic) { emitter = game.add.emitter(x, y); emitter.gravity = 100; emitter.bounce = 0.5; - if(x == 0) { + + if (x == 0) { emitter.setXSpeed(200, 250); } else { emitter.setXSpeed(-200, -250); } + emitter.setYSpeed(-50, -10); emitter.makeParticles(graphic, 250, false, 0); + return emitter; } + function create() { emitter1 = makeEmitter(emitter1, 0, 50, 'ball1'); emitter2 = makeEmitter(emitter2, 0, 250, 'ball2'); @@ -35,6 +42,7 @@ emitter4 = makeEmitter(emitter4, game.stage.width, 50, 'ball4'); emitter5 = makeEmitter(emitter5, game.stage.width, 250, 'ball5'); emitter6 = makeEmitter(emitter6, game.stage.width, 450, 'ball6'); + emitter1.start(false, 50, 0.05); emitter2.start(false, 50, 0.05); emitter3.start(false, 50, 0.05); @@ -42,7 +50,8 @@ emitter5.start(false, 50, 0.05); emitter6.start(false, 50, 0.05); } + function update() { //game.collide(leftEmitter, rightEmitter); - } + } })(); diff --git a/Tests/particles/sprite emitter.js b/Tests/particles/sprite emitter.js index 524969f6..31fb0269 100644 --- a/Tests/particles/sprite emitter.js +++ b/Tests/particles/sprite emitter.js @@ -1,31 +1,31 @@ +/// +/// +/// 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 __(); }; -/// -/// -/// // Actually we could achieve the same result as this by using a sprite sheet and basic Particle // but it still shows you how to use it properly from TypeScript, so it was worth making var customParticle = (function (_super) { __extends(customParticle, _super); function customParticle(game) { _super.call(this, game); - var s = [ - 'carrot', - 'melon', - 'eggplant', - 'mushroom', - 'pineapple' - ]; + + var s = ['carrot', 'melon', 'eggplant', 'mushroom', 'pineapple']; + this.texture.loadImage(game.math.getRandom(s)); } return customParticle; })(Phaser.ArcadeParticle); + (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + var emitter; + function preload() { game.load.image('carrot', 'assets/sprites/carrot.png'); game.load.image('melon', 'assets/sprites/melon.png'); @@ -33,12 +33,15 @@ var customParticle = (function (_super) { game.load.image('mushroom', 'assets/sprites/mushroom.png'); game.load.image('pineapple', 'assets/sprites/pineapple.png'); } + function create() { emitter = game.add.emitter(game.stage.centerX, 50); emitter.gravity = 100; + // Here we tell the emitter to use our customParticle class // The customParticle needs to extend Particle and must take game:Game as the first constructor parameter, otherwise it's free as a bird emitter.particleClass = customParticle; + emitter.makeParticles(null, 500, false, 0); emitter.start(false, 10, 0.05); } diff --git a/Tests/particles/when particles collide.js b/Tests/particles/when particles collide.js index 08c97b99..61a63e13 100644 --- a/Tests/particles/when particles collide.js +++ b/Tests/particles/when particles collide.js @@ -1,12 +1,15 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + var leftEmitter; var rightEmitter; + function preload() { game.load.image('ball1', 'assets/sprites/aqua_ball.png'); game.load.image('ball2', 'assets/sprites/yellow_ball.png'); } + function create() { leftEmitter = game.add.emitter(0, game.stage.centerY - 200); leftEmitter.gravity = 100; @@ -14,16 +17,19 @@ leftEmitter.setXSpeed(100, 200); leftEmitter.setYSpeed(-50, 50); leftEmitter.makeParticles('ball1', 250, false, 1); + rightEmitter = game.add.emitter(game.stage.width + 20, game.stage.centerY - 200); rightEmitter.gravity = 100; rightEmitter.bounce = 0.5; rightEmitter.setXSpeed(-100, -200); rightEmitter.setYSpeed(-50, 50); rightEmitter.makeParticles('ball2', 250, false, 1); + leftEmitter.start(false, 50, 0.05); rightEmitter.start(false, 50, 0.05); } + function update() { //game.collide(leftEmitter, rightEmitter); - } + } })(); diff --git a/Tests/phaser-debug.js b/Tests/phaser-debug.js index 6a114005..ccb089b3 100644 --- a/Tests/phaser-debug.js +++ b/Tests/phaser-debug.js @@ -7390,85 +7390,120 @@ var Phaser; })(Phaser || (Phaser = {})); /// /** -* Phaser - TimeManager -* -* This is the game clock and it manages elapsed time and calculation of delta values, used for game object motion. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser */ var Phaser; (function (Phaser) { var TimeManager = (function () { /** - * Time constructor - * Create a new Time. + * This is the core internal game clock. It manages the elapsed time and calculation of delta values, + * used for game object motion and tweens. * - * @param game {Phaser.Game} Current game instance. + * @class TimeManager + * @constructor + * @param {Phaser.Game} game A reference to the currently running game. */ function TimeManager(game) { /** - * Elapsed since last frame. - * @type {number} + * Number of milliseconds elapsed since the last frame update. + * @property elapsed + * @public + * @type {Number} */ this.elapsed = 0; /** * Game time counter. * @property time - * @type {number} + * @public + * @type {Number} */ this.time = 0; /** - * How long the game has been paused for. Gets reset each time the game pauses. + * Records how long the game has been paused for. Is reset each time the game pauses. * @property pausedTime - * @type {number} + * @public + * @type {Number} */ this.pausedTime = 0; /** - * Time of current frame. + * The time right now. * @property now - * @type {number} + * @public + * @type {Number} */ this.now = 0; /** - * Elapsed time since last frame. + * Elapsed time since the last frame. * @property delta - * @type {number} + * @public + * @type {Number} */ this.delta = 0; /** * Frames per second. - * @type {number} + * @property fps + * @public + * @type {Number} */ this.fps = 0; /** - * Minimal fps. - * @type {number} + * The lowest rate the fps has dropped to. + * @property fpsMin + * @public + * @type {Number} */ this.fpsMin = 1000; /** - * Maximal fps. - * @type {number} + * The highest rate the fps has reached (usually no higher than 60fps). + * @property fpsMax + * @public + * @type {Number} */ this.fpsMax = 0; /** - * Minimum duration between 2 frames. - * @type {number} + * The minimum amount of time the game has taken between two frames. + * @property msMin + * @public + * @type {Number} */ this.msMin = 1000; /** - * Maximum duration between 2 frames. - * @type {number} + * The maximum amount of time the game has taken between two frames. + * @property msMax + * @public + * @type {Number} */ this.msMax = 0; /** - * How many frames in last second. - * @type {number} + * The number of frames record in the last second. + * @property frames + * @public + * @type {Number} */ this.frames = 0; /** - * Time of last second. - * @type {number} + * The time (in ms) that the last second counter ticked over. + * @property _timeLastSecond + * @private + * @type {Number} */ this._timeLastSecond = 0; + /** + * Records how long the game was paused for in miliseconds. + * @property pauseDuration + * @public + * @type {Number} + */ this.pauseDuration = 0; + /** + * The time the game started being paused. + * @property _pauseStarted + * @private + * @type {Number} + */ this._pauseStarted = 0; this.game = game; @@ -7481,7 +7516,7 @@ var Phaser; } Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", { get: /** - * + * The number of seconds that have elapsed since the game was started. * @method totalElapsedSeconds * @return {Number} */ @@ -7496,7 +7531,7 @@ var Phaser; * Update clock and calculate the fps. * This is called automatically by Game._raf * @method update - * @param {number} raf The current timestamp, either performance.now or Date.now + * @param {Number} raf The current timestamp, either performance.now or Date.now */ TimeManager.prototype.update = function (raf) { this.now = raf; @@ -7523,20 +7558,30 @@ var Phaser; } }; + /** + * Called when the game enters a paused state. + * @method gamePaused + * @private + */ TimeManager.prototype.gamePaused = function () { this._pauseStarted = this.now; }; + /** + * Called when the game resumes from a paused state. + * @method gameResumed + * @private + */ TimeManager.prototype.gameResumed = function () { // Level out the delta timer to avoid spikes this.pauseDuration = this.pausedTime; }; /** - * How long has passed since given time. + * How long has passed since the given time. * @method elapsedSince - * @param {number} since The time you want to measure. - * @return {number} Duration between given time and now. + * @param {Number} since The time you want to measure against. + * @return {Number} The difference between the given time and now. */ TimeManager.prototype.elapsedSince = function (since) { return this.now - since; @@ -7545,15 +7590,15 @@ var Phaser; /** * How long has passed since the given time (in seconds). * @method elapsedSecondsSince - * @param {number} since The time you want to measure (in seconds). - * @return {number} Duration between given time and now (in seconds). + * @param {Number} since The time you want to measure (in seconds). + * @return {Number} Duration between given time and now (in seconds). */ TimeManager.prototype.elapsedSecondsSince = function (since) { return (this.now - since) * 0.001; }; /** - * Set the start time to now. + * Resets the private _started value to now. * @method reset */ TimeManager.prototype.reset = function () { @@ -7818,6 +7863,110 @@ var Phaser; 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; @@ -15737,9 +15886,10 @@ var Phaser; * * @return {Particle} The newly created particle object. */ - //public particle(): ArcadeParticle { - // return new ArcadeParticle(this.game); - //} + GameObjectFactory.prototype.particle = function () { + return new Phaser.ArcadeParticle(this.game); + }; + /** * Create a new Emitter. * @@ -15748,9 +15898,13 @@ var Phaser; * @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): ArcadeEmitter { - // return this._world.group.add(new ArcadeEmitter(this.game, x, y, size)); - //} + GameObjectFactory.prototype.emitter = function (x, y, size) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof size === "undefined") { size = 0; } + return this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size)); + }; + /** * Create a new ScrollZone object with image key, position and size. * @@ -15849,9 +16003,10 @@ var Phaser; * @param emitter The Emitter to add to the Game World * @return {Phaser.Emitter} The Emitter object */ - //public existingEmitter(emitter: ArcadeEmitter): ArcadeEmitter { - // return this._world.group.add(emitter); - //} + GameObjectFactory.prototype.existingEmitter = function (emitter) { + 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. @@ -15888,6 +16043,373 @@ var Phaser; })(); Phaser.GameObjectFactory = GameObjectFactory; })(Phaser || (Phaser = {})); +/// +/** +* Phaser - ArcadeEmitter +* +* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for +* continuous effects like rain and fire. All it really does is launch Particle objects out +* at set intervals, and fixes their positions and velocities accorindgly. +*/ +var Phaser; +(function (Phaser) { + var ArcadeEmitter = (function (_super) { + __extends(ArcadeEmitter, _super); + /** + * Creates a new Emitter object at a specific position. + * Does NOT automatically generate or attach particles! + * + * @param x {number} The X position of the emitter. + * @param y {number} The Y position of the emitter. + * @param [size] {number} Specifies a maximum capacity for this emitter. + */ + function ArcadeEmitter(game, x, y, size) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof size === "undefined") { size = 0; } + _super.call(this, game, size); + + this.x = x; + this.y = y; + this.width = 0; + this.height = 0; + this.minParticleSpeed = new Phaser.Vec2(-100, -100); + this.maxParticleSpeed = new Phaser.Vec2(100, 100); + this.minRotation = -360; + this.maxRotation = 360; + this.gravity = 0; + this.particleClass = null; + this.particleDrag = new Phaser.Vec2(); + this.frequency = 0.1; + this.lifespan = 3; + this.bounce = 0; + this._quantity = 0; + this._counter = 0; + this._explode = true; + this.on = false; + + this.exists = true; + this.active = true; + this.visible = true; + } + /** + * Clean up memory. + */ + ArcadeEmitter.prototype.destroy = function () { + this.minParticleSpeed = null; + this.maxParticleSpeed = null; + this.particleDrag = null; + this.particleClass = null; + this._point = null; + _super.prototype.destroy.call(this); + }; + + /** + * This function generates a new array of particle sprites to attach to the emitter. + * + * @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet. + * @param quantity {number} The number of particles to generate when using the "create from image" option. + * @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!). + * @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box. + * + * @return This Emitter instance (nice for chaining stuff together, if you're into that). + */ + ArcadeEmitter.prototype.makeParticles = function (graphics, quantity, multiple, collide) { + if (typeof quantity === "undefined") { quantity = 50; } + if (typeof multiple === "undefined") { multiple = false; } + if (typeof collide === "undefined") { collide = 0; } + this.maxSize = quantity; + + var totalFrames = 1; + + /* + if(Multiple) + { + var sprite:Sprite = new Sprite(this.game); + sprite.loadGraphic(Graphics,true); + totalFrames = sprite.frames; + sprite.destroy(); + } + */ + var randomFrame; + var particle; + var i = 0; + + while (i < quantity) { + if (this.particleClass == null) { + particle = new Phaser.ArcadeParticle(this.game); + } else { + particle = new this.particleClass(this.game); + } + + if (multiple) { + /* + randomFrame = this.game.math.random()*totalFrames; + */ + } else { + if (graphics) { + particle.texture.loadImage(graphics); + } + } + + if (collide > 0) { + //particle.body.allowCollisions = Types.ANY; + particle.body.type = Phaser.Types.BODY_DYNAMIC; + particle.width *= collide; + particle.height *= collide; + } else { + //particle.body.allowCollisions = Types.NONE; + } + + particle.exists = false; + + // Center the origin for rotation assistance + //particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); + this.add(particle); + + i++; + } + + return this; + }; + + ArcadeEmitter.prototype.preUpdate = function () { + }; + ArcadeEmitter.prototype.postUpdate = function () { + }; + + /** + * Called automatically by the game loop, decides when to launch particles and when to "die". + */ + ArcadeEmitter.prototype.update = function () { + if (this.on) { + if (this._explode) { + this.on = false; + + var i = 0; + var l = this._quantity; + + if ((l <= 0) || (l > this.length)) { + l = this.length; + } + + while (i < l) { + this.emitParticle(); + i++; + } + + this._quantity = 0; + } else { + this._timer += this.game.time.elapsed; + + while ((this.frequency > 0) && (this._timer > this.frequency) && this.on) { + this._timer -= this.frequency; + this.emitParticle(); + + if ((this._quantity > 0) && (++this._counter >= this._quantity)) { + this.on = false; + this._quantity = 0; + } + } + } + } + + _super.prototype.update.call(this); + }; + + /** + * Call this function to turn off all the particles and the emitter. + */ + ArcadeEmitter.prototype.kill = function () { + this.on = false; + this.alive = false; + this.exists = false; + }; + + /** + * Handy for bringing game objects "back to life". Just sets alive and exists back to true. + * In practice, this is most often called by Object.reset(). + */ + ArcadeEmitter.prototype.revive = function () { + this.alive = true; + this.exists = true; + }; + + /** + * Call this function to start emitting particles. + * + * @param explode {boolean} Whether the particles should all burst out at once. + * @param lifespan {number} How long each particle lives once emitted. 0 = forever. + * @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds. + * @param quantity {number} How many particles to launch. 0 = "all of the particles". + */ + ArcadeEmitter.prototype.start = function (explode, lifespan, frequency, quantity) { + if (typeof explode === "undefined") { explode = true; } + if (typeof lifespan === "undefined") { lifespan = 0; } + if (typeof frequency === "undefined") { frequency = 0.1; } + if (typeof quantity === "undefined") { quantity = 0; } + this.revive(); + + this.visible = true; + this.on = true; + + this._explode = explode; + this.lifespan = lifespan; + this.frequency = frequency; + this._quantity += quantity; + + this._counter = 0; + this._timer = 0; + }; + + /** + * This function can be used both internally and externally to emit the next particle. + */ + ArcadeEmitter.prototype.emitParticle = function () { + var particle = this.recycle(Phaser.ArcadeParticle); + + particle.lifespan = this.lifespan; + + //particle.body.bounce.setTo(this.bounce, this.bounce); + Phaser.SpriteUtils.reset(particle, this.x - (particle.width >> 1) + this.game.rnd.integer * this.width, this.y - (particle.height >> 1) + this.game.rnd.integer * this.height); + particle.visible = true; + + if (this.minParticleSpeed.x != this.maxParticleSpeed.x) { + particle.body.velocity.x = this.minParticleSpeed.x + this.game.rnd.integer * (this.maxParticleSpeed.x - this.minParticleSpeed.x); + } else { + particle.body.velocity.x = this.minParticleSpeed.x; + } + + if (this.minParticleSpeed.y != this.maxParticleSpeed.y) { + particle.body.velocity.y = this.minParticleSpeed.y + this.game.rnd.integer * (this.maxParticleSpeed.y - this.minParticleSpeed.y); + } else { + particle.body.velocity.y = this.minParticleSpeed.y; + } + + if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) { + particle.body.angularVelocity = this.minRotation + this.game.rnd.integer * (this.maxRotation - this.minRotation); + } else { + particle.body.angularVelocity = this.minRotation; + } + + if (particle.body.angularVelocity != 0) { + particle.rotation = this.game.rnd.integer * 360 - 180; + } + + //particle.body.drag.x = this.particleDrag.x; + //particle.body.drag.y = this.particleDrag.y; + particle.onEmit(); + }; + + /** + * A more compact way of setting the width and height of the emitter. + * + * @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions). + * @param height {number} The desired height of the emitter. + */ + ArcadeEmitter.prototype.setSize = function (width, height) { + this.width = width; + this.height = height; + }; + + /** + * A more compact way of setting the X velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setXSpeed = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minParticleSpeed.x = min; + this.maxParticleSpeed.x = max; + }; + + /** + * A more compact way of setting the Y velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setYSpeed = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minParticleSpeed.y = min; + this.maxParticleSpeed.y = max; + }; + + /** + * A more compact way of setting the angular velocity constraints of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setRotation = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minRotation = min; + this.maxRotation = max; + }; + + /** + * Change the emitter's midpoint to match the midpoint of a Object. + * + * @param Object {object} The Object that you want to sync up with. + */ + ArcadeEmitter.prototype.at = function (object) { + //this.x = object.body.bounds.halfWidth - (this.width >> 1); + //this.y = object.body.bounds.halfHeight - (this.height >> 1); + }; + return ArcadeEmitter; + })(Phaser.Group); + Phaser.ArcadeEmitter = ArcadeEmitter; +})(Phaser || (Phaser = {})); +/// +/** +* Phaser - ArcadeParticle +* +* This is a simple particle class that extends a Sprite to have a slightly more +* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required. +*/ +var Phaser; +(function (Phaser) { + var ArcadeParticle = (function (_super) { + __extends(ArcadeParticle, _super); + /** + * Instantiate a new particle. Like Sprite, all meaningful creation + * happens during loadGraphic() or makeGraphic() or whatever. + */ + function ArcadeParticle(game) { + _super.call(this, game); + + this.body.type = Phaser.Types.BODY_DYNAMIC; + this.lifespan = 0; + } + /** + * The particle's main update logic. Basically it checks to see if it should be dead yet. + */ + ArcadeParticle.prototype.update = function () { + if (this.lifespan <= 0) { + return; + } + + this.lifespan -= this.game.time.elapsed; + + if (this.lifespan <= 0) { + this.kill(); + } + }; + + /** + * Triggered whenever this object is launched by a Emitter. + * You can override this to add custom behavior like a sound or AI or something. + */ + ArcadeParticle.prototype.onEmit = function () { + }; + return ArcadeParticle; + })(Phaser.Sprite); + Phaser.ArcadeParticle = ArcadeParticle; +})(Phaser || (Phaser = {})); var Phaser; (function (Phaser) { /// diff --git a/Tests/scrollzones/ballscroller.js b/Tests/scrollzones/ballscroller.js index bdda1a84..a341e495 100644 --- a/Tests/scrollzones/ballscroller.js +++ b/Tests/scrollzones/ballscroller.js @@ -2,10 +2,13 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('balls', 'assets/sprites/balls.png'); } + var scroller; + function create() { // The source image (balls.png) is only 102x17 in size, but we want it to create a scroll the size of the whole game window. // We can take advantage of the way a ScrollZone can create a seamless pattern for us automatically. @@ -13,9 +16,11 @@ // for rendering. // We've rounded the height up to 612 because in order to have a seamless pattern it needs to be a multiple of 17 (the height of the source image) scroller = game.add.scrollZone('balls', 0, 0, 800, 612); + // Some sin/cos data for the movement game.math.sinCosGenerator(256, 4, 4, 2); } + function update() { // Cycle through the wave data and apply it to the scroll speed (causes the circular wave motion) scroller.currentRegion.scrollSpeed.x = game.math.shiftSinTable(); diff --git a/Tests/scrollzones/blasteroids.js b/Tests/scrollzones/blasteroids.js index b5d954b8..f8d39de6 100644 --- a/Tests/scrollzones/blasteroids.js +++ b/Tests/scrollzones/blasteroids.js @@ -1,101 +1,123 @@ /// -/// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('nashwan', 'assets/sprites/xenon2_ship.png'); game.load.image('starfield', 'assets/misc/starfield.jpg'); game.load.image('jet', 'assets/sprites/particle1.png'); game.load.image('bullet', 'assets/misc/bullet1.png'); } + var scroller; var emitter; var ship; var bullets; + var speed = 0; var fireRate = 0; var shipMotion; + function create() { scroller = game.add.scrollZone('starfield', 0, 0, 1024, 1024); + emitter = game.add.emitter(game.stage.centerX + 16, game.stage.centerY + 12); emitter.makeParticles('jet', 250, false, 0); emitter.setRotation(0, 0); + // Looks like a smoke trail! //emitter.globalCompositeOperation = 'xor'; // Looks way cool :) emitter.texture.globalCompositeOperation = 'lighter'; + bullets = game.add.group(50); - // Create our bullet pool - for(var i = 0; i < 50; i++) { + + for (var i = 0; i < 50; i++) { var tempBullet = new Phaser.Sprite(game, game.stage.centerX, game.stage.centerY, 'bullet'); tempBullet.exists = false; tempBullet.transform.rotationOffset = 90; + //tempBullet.setBounds(-100, -100, 900, 700); //tempBullet.outOfBoundsAction = Phaser.GameObject.OUT_OF_BOUNDS_KILL; bullets.add(tempBullet); } + ship = game.add.sprite(game.stage.centerX, game.stage.centerY, 'nashwan', Phaser.Types.BODY_DYNAMIC); ship.transform.origin.setTo(0.5, 0.5); + // We do this because the ship was drawn facing up, but 0 degrees is pointing to the right ship.transform.rotationOffset = 90; + game.input.onDown.add(test, this); } + function test(event) { game.stage.scale.startFullScreen(); } + function update() { ship.body.angularVelocity = 0; - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { ship.body.angularVelocity = -200; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { ship.body.angularVelocity = 200; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { speed += 0.1; - if(speed > 10) { + + if (speed > 10) { speed = 10; } } else { speed -= 0.1; - if(speed < 0) { + + if (speed < 0) { speed = 0; } } + //shipMotion = game.motion.velocityFromAngle(ship.rotation, speed); scroller.setSpeed(shipMotion.x, shipMotion.y); - // emit particles - if(speed > 2) { + + if (speed > 2) { // We use the opposite of the motion because the jets emit out the back of the ship // The 20 and 30 values just keep them nice and fast emitter.setXSpeed(-(shipMotion.x * 20), -(shipMotion.x * 30)); emitter.setYSpeed(-(shipMotion.y * 20), -(shipMotion.y * 30)); emitter.emitParticle(); } - if(game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.SPACEBAR)) { fire(); } } + function render() { //ship.body.renderDebugInfo(32, 32); - } + } + function recycleBullet(bullet) { - if(bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) { + if (bullet.exists && bullet.x < -40 || bullet.x > 840 || bullet.y < -40 || bullet.y > 640) { bullet.exists = false; } } + function fire() { - if(game.time.now > fireRate) { + if (game.time.now > fireRate) { var b = bullets.getFirstAvailable(); + b.x = ship.x; b.y = ship.y - 26; + //var bulletMotion = game.motion.velocityFromAngle(ship.rotation, 400); - var bulletMotion = { - x: 0, - y: 0 - }; + var bulletMotion = { x: 0, y: 0 }; + b.revive(); b.rotation = ship.rotation; b.body.velocity.setTo(bulletMotion.x, bulletMotion.y); + fireRate = game.time.now + 100; } } diff --git a/Tests/scrollzones/blasteroids.ts b/Tests/scrollzones/blasteroids.ts index 266e623d..0da877f1 100644 --- a/Tests/scrollzones/blasteroids.ts +++ b/Tests/scrollzones/blasteroids.ts @@ -1,5 +1,4 @@ /// -/// (function () { @@ -12,8 +11,6 @@ game.load.image('jet', 'assets/sprites/particle1.png'); game.load.image('bullet', 'assets/misc/bullet1.png'); - - } var scroller: Phaser.ScrollZone; diff --git a/Tests/scrollzones/parallax.js b/Tests/scrollzones/parallax.js index 6e65a7e8..2fd1c681 100644 --- a/Tests/scrollzones/parallax.js +++ b/Tests/scrollzones/parallax.js @@ -2,24 +2,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('starray', 'assets/pics/auto_scroll_landscape.png'); } + function create() { var zone = game.add.scrollZone('starray'); + // Hide the default region (the full image) zone.currentRegion.visible = false; + var y = 0; var speed = 16; - // The image consists of 10px high scrolling layers, this creates them quickly (top = fastest, getting slower as we move down) - for(var z = 0; z < 32; z++) { + + for (var z = 0; z < 32; z++) { zone.addRegion(0, y, 640, 10, speed); - if(z <= 15) { + + if (z <= 15) { speed -= 1; } else { speed += 1; } - if(z == 15) { + + if (z == 15) { y = 240; speed += 1; } else { diff --git a/Tests/scrollzones/region demo.js b/Tests/scrollzones/region demo.js index 8caff26b..daf398dc 100644 --- a/Tests/scrollzones/region demo.js +++ b/Tests/scrollzones/region demo.js @@ -2,19 +2,25 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('angelDawn', 'assets/pics/game14_angel_dawn.png'); } + var scroller; + function create() { // This creates our ScrollZone centered in the middle of the stage. scroller = game.add.scrollZone('angelDawn', game.stage.centerX - 320, 100); + // By default we won't scroll the full image, but we will create 3 ScrollRegions within it: // This creates a ScrollRegion which can be thought of as a rectangle within the ScrollZone that can be scrolled // independantly - this one scrolls the image of the spacemans head scroller.addRegion(32, 32, 352, 240, 0, 2); + // The head in the top right scroller.addRegion(480, 30, 96, 96, 4, 0); + // The small piece of text scroller.addRegion(466, 160, 122, 14, 0, -0.5); } diff --git a/Tests/scrollzones/scroll window.js b/Tests/scrollzones/scroll window.js index 59c74ee1..d6050133 100644 --- a/Tests/scrollzones/scroll window.js +++ b/Tests/scrollzones/scroll window.js @@ -2,16 +2,21 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('dragonsun', 'assets/pics/cougar_dragonsun.png'); game.load.image('overlay', 'assets/pics/scrollframe.png'); } + var scroller; + function create() { // This creates our ScrollZone. It is positioned at x32 y32 (world coodinates) // and is a size of 352x240 (which matches the window in our overlay image) scroller = game.add.scrollZone('dragonsun', 32, 32, 352, 240); + scroller.setSpeed(2, 2); + game.add.sprite(0, 0, 'overlay'); } })(); diff --git a/Tests/scrollzones/simple scrollzone.js b/Tests/scrollzones/simple scrollzone.js index 3f958cd4..567926a8 100644 --- a/Tests/scrollzones/simple scrollzone.js +++ b/Tests/scrollzones/simple scrollzone.js @@ -2,9 +2,11 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('crystal', 'assets/pics/jim_sachs_time_crystal.png'); } + function create() { // This creates our ScrollZone. It is positioned at x0 y0 (world coodinates) by default and uses // the 'crystal' image from the cache. diff --git a/Tests/scrollzones/skewed scroller.js b/Tests/scrollzones/skewed scroller.js index 81c0c76f..77a4591f 100644 --- a/Tests/scrollzones/skewed scroller.js +++ b/Tests/scrollzones/skewed scroller.js @@ -2,18 +2,23 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('balls', 'assets/sprites/balls.png'); } + var leftFace; var rightFace; var topFace; + function create() { topFace = game.add.scrollZone('balls', 200, 0, 204, 204).setSpeed(0, 2.2); topFace.transform.skew.setTo(0, Math.tan(game.math.radiansToDegrees(-30))); topFace.transform.scale.setTo(1, 1.3); + leftFace = game.add.scrollZone('balls', 110, 264, 204, 204).setSpeed(0, 2.1); leftFace.transform.skew.setTo(0, Math.tan(game.math.radiansToDegrees(30))); + rightFace = game.add.scrollZone('balls', 200, 466, 204, 204).setSpeed(0, 2); rightFace.transform.skew.setTo(0, Math.tan(game.math.radiansToDegrees(-30))); rightFace.transform.scale.setTo(1, 0.8); diff --git a/Tests/sprites/alpha.js b/Tests/sprites/alpha.js index c8faf964..3c5cb12d 100644 --- a/Tests/sprites/alpha.js +++ b/Tests/sprites/alpha.js @@ -1,13 +1,16 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('bunny', 'assets/sprites/bunny.png'); } + function create() { // Here we'll assign the new sprite to the local bunny variable var bunny = game.add.sprite(0, 0, 'bunny'); + // And this sets the alpha of the sprite to 0.5, which is 50% opaque bunny.alpha = 0.5; } diff --git a/Tests/sprites/animate by framename.js b/Tests/sprites/animate by framename.js index f71e1e05..e98c0b0e 100644 --- a/Tests/sprites/animate by framename.js +++ b/Tests/sprites/animate by framename.js @@ -1,33 +1,28 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.atlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); } + var bot; + function create() { bot = game.add.sprite(game.stage.width, 300, 'bot'); + // If you are using a Texture Atlas and want to specify the frames of an animation by their name rather than frame index // then you can use this format: - bot.animations.add('run', [ - 'run00', - 'run01', - 'run02', - 'run03', - 'run04', - 'run05', - 'run06', - 'run07', - 'run08', - 'run09', - 'run10' - ], 10, true, false); + bot.animations.add('run', ['run00', 'run01', 'run02', 'run03', 'run04', 'run05', 'run06', 'run07', 'run08', 'run09', 'run10'], 10, true, false); + bot.animations.play('run'); //bot.velocity.x = -100; - } + } + function update() { bot.x -= 1; - if(bot.x < -bot.width) { + + if (bot.x < -bot.width) { bot.x = game.stage.width; } } diff --git a/Tests/sprites/animation 1.js b/Tests/sprites/animation 1.js index ed5f3d57..327346e3 100644 --- a/Tests/sprites/animation 1.js +++ b/Tests/sprites/animation 1.js @@ -1,21 +1,27 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder // The sprite sheet is a standard frame-by-frame sheet, and each frame is 37 x 45 pixels in size. // The final parameter (18) is the number of frames there are. You can omit this if your frames fill the entire sheet. game.load.spritesheet('mummy', 'assets/sprites/metalslug_mummy37x45.png', 37, 45, 18); } + var mummy; + function create() { mummy = game.add.sprite(game.stage.centerX, game.stage.centerY, 'mummy'); + // Here we add new animation called 'walk'. // As it's the only animation in our sprite sheet we don't need to define the frames being used. mummy.animations.add('walk'); + // This plays the animation at 20 frames per second on a loop (the 3rd parameter) // Try changing the 20 value to something low to slow the speed down, or higher to make it play faster. mummy.animations.play('walk', 20, true); + // This just scales the sprite up so you can see the animation better mummy.transform.scale.setTo(4, 4); } diff --git a/Tests/sprites/animation 2.js b/Tests/sprites/animation 2.js index efb1a109..0bf60f0a 100644 --- a/Tests/sprites/animation 2.js +++ b/Tests/sprites/animation 2.js @@ -1,21 +1,28 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.spritesheet('monster', 'assets/sprites/metalslug_monster39x40.png', 39, 40); } + var monster; + function create() { game.stage.backgroundColor = 'rgb(50,10,10)'; + // Notice the use of 'stage.centerX' - this places the sprite in the middle of the stage without needing to do any extra math monster = game.add.sprite(game.stage.centerX, game.stage.centerY, 'monster'); + // For this animation we pass 'null' for the frames, because we're going to use them all // And we set the frame rate (30) and loop status (true) when we add the animation // If the frame rate and looping is never going to change then it's easier to do it here monster.animations.add('walk', null, 30, true); + // Then you can just call 'play' on its own with no other values to start things going monster.animations.play('walk'); + monster.transform.scale.setTo(2, 2); } })(); diff --git a/Tests/sprites/create sprite 1.js b/Tests/sprites/create sprite 1.js index 85b1c167..eeb85efc 100644 --- a/Tests/sprites/create sprite 1.js +++ b/Tests/sprites/create sprite 1.js @@ -1,10 +1,12 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('bunny', 'assets/sprites/bunny.png'); } + function create() { // This will create a Sprite positioned at the top-left of the game (0,0) // Try changing the 0, 0 values diff --git a/Tests/sprites/origin 5.js b/Tests/sprites/origin 5.js index b11ed064..89592557 100644 --- a/Tests/sprites/origin 5.js +++ b/Tests/sprites/origin 5.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('disk', 'assets/sprites/oz_pov_melting_disk.png'); @@ -9,15 +10,19 @@ game.load.image('fuji3', 'assets/tests/320x200.png'); game.load.image('fuji4', 'assets/tests/320x200g.png'); } + var fuji; var fuji2; var fuji3; + function create() { game.stage.backgroundColor = 'rgb(0,0,0)'; + //game.world.setSize(2000, 1200, true); // The sprite is 320 x 200 pixels in size positioned in the middle of the stage //fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji4'); fuji2 = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji3'); + //fuji2 = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji2'); //fuji3 = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji2'); //fuji.visible = false; @@ -38,31 +43,35 @@ //fuji.transform.origin.setTo(0.5, 0.5); //fuji.transform.origin.setTo(0, 0); fuji2.transform.origin.setTo(1, 1); + //fuji3.transform.origin.setTo(1, 1); game.input.onTap.add(rotateIt, this); //game.stage.clear = false; - } + } + function rotateIt() { //fuji.rotation += 10; fuji2.rotation += 10; //fuji3.rotation += 20; - } + } + function update() { - //fuji.rotation++; - //fuji2.rotation++; - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + var points; var points2; + function render() { // This = the center point //var cx = fuji2.x + (fuji2.width / 2) * cos - (fuji2.height / 2) * sin; @@ -90,6 +99,7 @@ //game.stage.context.fillRect(cx, cy, 4, 4); var sin = Math.sin((fuji2.transform.rotation + fuji2.transform.rotationOffset) * Phaser.GameMath.DEG_TO_RAD); var cos = Math.cos((fuji2.transform.rotation + fuji2.transform.rotationOffset) * Phaser.GameMath.DEG_TO_RAD); + var originX = fuji2.transform.origin.x * fuji2.width; var originY = fuji2.transform.origin.y * fuji2.height; var centerX = 0.5 * fuji2.width; @@ -97,8 +107,10 @@ var distanceX = originX - centerX; var distanceY = originY - centerY; var distance = Math.sqrt(((originX - centerX) * (originX - centerX)) + ((originY - centerY) * (originY - centerY))); + var px = fuji2.x + distance * Math.cos(fuji2.transform.rotation + 45 * Math.PI / 180); var py = fuji2.y + distance * Math.sin(fuji2.transform.rotation + 45 * Math.PI / 180); + game.stage.context.save(); game.stage.context.fillStyle = 'rgb(255,255,0)'; game.stage.context.fillText('rect width: ' + originX + ' height: ' + originY, 32, 32); @@ -107,6 +119,7 @@ game.stage.context.fillText('point of rotation x: ' + fuji2.transform.origin.x + ' y: ' + fuji2.transform.origin.y, 32, 92); game.stage.context.fillText('x: ' + fuji2.x + ' y: ' + fuji2.y, fuji2.x + 4, fuji2.y); game.stage.context.restore(); + game.stage.context.save(); game.stage.context.fillStyle = 'rgba(255,255,255,0.1)'; game.stage.context.arc(fuji2.x, fuji2.y, distance, 0, Math.PI * 2); @@ -224,5 +237,5 @@ */ //game.stage.context.strokeStyle = 'rgb(255,255,0)'; //game.stage.context.strokeRect(fuji.cameraView.x, fuji.cameraView.y, fuji.cameraView.width, fuji.cameraView.height); - } + } })(); diff --git a/Tests/sprites/scale sprite 1.js b/Tests/sprites/scale sprite 1.js index a7d5fd16..1c27652f 100644 --- a/Tests/sprites/scale sprite 1.js +++ b/Tests/sprites/scale sprite 1.js @@ -1,14 +1,18 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('bunny', 'assets/sprites/bunny.png'); } + var smallBunny; + function create() { // Here we'll assign the new sprite to the local smallBunny variable smallBunny = game.add.sprite(0, 0, 'bunny'); + // And now let's scale the sprite by half // You can do either: //smallBunny.scale.x = 0.5; diff --git a/Tests/sprites/scale sprite 2.js b/Tests/sprites/scale sprite 2.js index 9135ec07..24d2046a 100644 --- a/Tests/sprites/scale sprite 2.js +++ b/Tests/sprites/scale sprite 2.js @@ -1,14 +1,18 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('bunny', 'assets/sprites/bunny.png'); } + var bigBunny; + function create() { // Here we'll assign the new sprite to the local bigBunny variable bigBunny = game.add.sprite(0, 0, 'bunny'); + // And now let's scale the sprite by two // You can do either: // smallBunny.transform.scale.x = 2; diff --git a/Tests/sprites/scale sprite 3.js b/Tests/sprites/scale sprite 3.js index a6bb903c..605ca697 100644 --- a/Tests/sprites/scale sprite 3.js +++ b/Tests/sprites/scale sprite 3.js @@ -1,14 +1,18 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('bunny', 'assets/sprites/bunny.png'); } + var bunny; + function create() { // Here we'll assign the new sprite to the local bunny variable bunny = game.add.sprite(0, 0, 'bunny'); + // You don't have to use the same values when scaling a sprite, // here we'll create a short and wide bunny bunny.transform.scale.setTo(3, 0.7); diff --git a/Tests/sprites/scale sprite 4.js b/Tests/sprites/scale sprite 4.js index c1e8490d..1b458a8d 100644 --- a/Tests/sprites/scale sprite 4.js +++ b/Tests/sprites/scale sprite 4.js @@ -1,21 +1,23 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('bunny', 'assets/sprites/bunny.png'); } + var bunny; var tweenUp; var tweenDown; + function create() { // Here we'll assign the new sprite to the local bunny variable bunny = game.add.sprite(0, 0, 'bunny'); + bunny.transform.scale.setTo(0.5, 0.5); + // This time let's scale the sprite by a looped tween - game.add.tween(bunny.transform.scale).to({ - x: 1.5, - y: 1.5 - }, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true); + game.add.tween(bunny.transform.scale).to({ x: 1.5, y: 1.5 }, 2000, Phaser.Easing.Elastic.Out, true, 0, true, true); } })(); diff --git a/Tests/sprites/scale sprite 5.js b/Tests/sprites/scale sprite 5.js index 0735e97f..05b2f8b1 100644 --- a/Tests/sprites/scale sprite 5.js +++ b/Tests/sprites/scale sprite 5.js @@ -1,40 +1,46 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('fuji', 'assets/pics/atari_fujilogo.png'); } + var fuji; var tween; + function create() { game.stage.backgroundColor = 'rgb(0,0,100)'; + // Here we'll assign the new sprite to the local fuji variable fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji'); + // sets origin to the center of the sprite (half the width and half the height) fuji.transform.origin.setTo(0.5, 0.5); + // We'll tween the scale down to zero (which will make the sprite invisible) and then flip it // The end result should look like turning over a card // Create our tween tween = game.add.tween(fuji.transform.scale); + // Start it going scaleLeft(); } + function scaleLeft() { tween.clear(); - tween.to({ - x: 0 - }, 1000); + tween.to({ x: 0 }, 1000); tween.onComplete.add(scaleRight, this); tween.start(); } + function scaleRight() { tween.clear(); - tween.to({ - x: 1 - }, 1000); + tween.to({ x: 1 }, 1000); tween.onComplete.add(scaleLeft, this); tween.start(); + // This line says "if the texture is flippedX then unflip it (set flippedX to false), otherwise set flippedX to true (fuji.texture.flippedX) ? fuji.texture.flippedX = false : fuji.texture.flippedX = true; } diff --git a/Tests/sprites/sprite origin 1.js b/Tests/sprites/sprite origin 1.js index 027133e7..1ea68b88 100644 --- a/Tests/sprites/sprite origin 1.js +++ b/Tests/sprites/sprite origin 1.js @@ -1,19 +1,22 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('fuji', 'assets/pics/atari_fujilogo.png'); } + var fuji; + function create() { game.stage.backgroundColor = 'rgb(0,0,100)'; + // Here we'll assign the new sprite to the local fuji variable fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji'); + // The sprite is 320 x 200 pixels in size // If we don't set an origin then the sprite will rotate around 0,0 - the top left corner - game.add.tween(fuji).to({ - rotation: 360 - }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/sprites/sprite origin 2.js b/Tests/sprites/sprite origin 2.js index 5c700a30..6c9c69c8 100644 --- a/Tests/sprites/sprite origin 2.js +++ b/Tests/sprites/sprite origin 2.js @@ -1,21 +1,25 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('fuji', 'assets/pics/atari_fujilogo.png'); } + var fuji; + function create() { game.stage.backgroundColor = 'rgb(0,0,100)'; + // Here we'll assign the new sprite to the local fuji variable fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji'); + // The sprite is 320 x 200 pixels in size // Here we set the origin to the center of the sprite (half of its width and height, so 160x100) // This will cause it to rotate on its center fuji.transform.origin.setTo(0.5, 0.5); - game.add.tween(fuji).to({ - rotation: 360 - }, 2000, Phaser.Easing.Linear.None, true, 0, true); + + game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/sprites/sprite origin 3.js b/Tests/sprites/sprite origin 3.js index 8ac9181d..752a3549 100644 --- a/Tests/sprites/sprite origin 3.js +++ b/Tests/sprites/sprite origin 3.js @@ -1,21 +1,25 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('fuji', 'assets/pics/atari_fujilogo.png'); } + var fuji; var tween; + function create() { game.stage.backgroundColor = 'rgb(0,0,100)'; + // Here we'll assign the new sprite to the local fuji variable fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji'); + // The sprite is 320 x 200 pixels in size // Here we set the origin to be the bottom-right of the sprite fuji.origin.setTo(1, 1); - game.add.tween(fuji).to({ - rotation: 360 - }, 2000, Phaser.Easing.Linear.None, true, 0, true); + + game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/sprites/sprite origin 4.js b/Tests/sprites/sprite origin 4.js index 8cd87503..64e78776 100644 --- a/Tests/sprites/sprite origin 4.js +++ b/Tests/sprites/sprite origin 4.js @@ -1,41 +1,44 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('fuji', 'assets/pics/atari_fujilogo.png'); } + var fuji; var tweenUp; var tweenDown; + function create() { game.stage.backgroundColor = 'rgb(0,0,100)'; + // Here we'll assign the new sprite to the local fuji variable fuji = game.add.sprite(game.stage.centerX, game.stage.centerY, 'fuji'); + // The sprite is 320 x 200 pixels in size // Here we set the origin to the center of the sprite again, so we can rotate and scale it at the same time fuji.transform.origin.setTo(0.5, 0.5); - game.add.tween(fuji).to({ - rotation: 360 - }, 2000, Phaser.Easing.Linear.None, true, 0, true); + + game.add.tween(fuji).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + tweenUp = game.add.tween(fuji.transform.scale); tweenUp.onComplete.add(scaleDown, this); + tweenDown = game.add.tween(fuji.transform.scale); tweenDown.onComplete.add(scaleUp, this); + scaleUp(); } + function scaleUp() { - tweenUp.to({ - x: 2, - y: 2 - }, 1000, Phaser.Easing.Elastic.Out); + tweenUp.to({ x: 2, y: 2 }, 1000, Phaser.Easing.Elastic.Out); tweenUp.start(); } + function scaleDown() { - tweenDown.to({ - x: 0.5, - y: 0.5 - }, 1000, Phaser.Easing.Elastic.Out); + tweenDown.to({ x: 0.5, y: 0.5 }, 1000, Phaser.Easing.Elastic.Out); tweenDown.start(); } })(); diff --git a/Tests/stage/blur filter.js b/Tests/stage/blur filter.js index b1916385..e8e106bd 100644 --- a/Tests/stage/blur filter.js +++ b/Tests/stage/blur filter.js @@ -1,24 +1,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/remember-me.jpg'); } + function create() { game.world.setSize(1920, 1200); + game.add.sprite(0, 0, 'backdrop'); + // Apply a 4px blur to the entire game (this value can be tweened, modified in-game, etc) game.stage.css3.blur = 4; } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/stage/brightness filter.js b/Tests/stage/brightness filter.js index 02dc7ee5..d3eddba4 100644 --- a/Tests/stage/brightness filter.js +++ b/Tests/stage/brightness filter.js @@ -1,24 +1,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/remember-me.jpg'); } + function create() { game.world.setSize(1920, 1200); + game.add.sprite(0, 0, 'backdrop'); + // Apply a 150% brightness filter to the entire game (this value can be tweened, modified in-game, etc) game.stage.css3.brightness = 150; } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/stage/contrast filter.js b/Tests/stage/contrast filter.js index 0f2b3c94..982540e0 100644 --- a/Tests/stage/contrast filter.js +++ b/Tests/stage/contrast filter.js @@ -1,24 +1,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/remember-me.jpg'); } + function create() { game.world.setSize(1920, 1200); + game.add.sprite(0, 0, 'backdrop'); + // Apply a 250% contrast filter to the entire game (this value can be tweened, modified in-game, etc) game.stage.css3.contrast = 250; } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/stage/grayscale filter.js b/Tests/stage/grayscale filter.js index 89cfb2d1..16dc5901 100644 --- a/Tests/stage/grayscale filter.js +++ b/Tests/stage/grayscale filter.js @@ -1,24 +1,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/remember-me.jpg'); } + function create() { game.world.setSize(1920, 1200); + game.add.sprite(0, 0, 'backdrop'); + // Apply a 100% contrast filter to the entire game (this value can be tweened, modified in-game, etc) game.stage.css3.grayscale = 100; } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/stage/hue rotate filter.js b/Tests/stage/hue rotate filter.js index 6cebd1ce..f58c7a1f 100644 --- a/Tests/stage/hue rotate filter.js +++ b/Tests/stage/hue rotate filter.js @@ -1,26 +1,33 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/large-color-wheel.png'); game.load.image('coke', 'assets/sprites/cokecan.png'); game.load.image('mushroom', 'assets/sprites/mushroom2.png'); } + var hue = 0; + function create() { game.world.setSize(800, 800); + game.add.sprite(0, 0, 'backdrop'); game.add.sprite(30, 20, 'coke'); game.add.sprite(600, 20, 'mushroom'); } + function update() { // The value is given in degrees, so between 0 and 360, hence the wrapValue call below. hue = game.math.wrapValue(hue, 1, 360); + // Apply a hue rotation to the stage game.stage.css3.hueRotate = hue; - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/stage/sepia filter.js b/Tests/stage/sepia filter.js index 39a21e8c..8e36dbb1 100644 --- a/Tests/stage/sepia filter.js +++ b/Tests/stage/sepia filter.js @@ -1,24 +1,30 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('backdrop', 'assets/pics/remember-me.jpg'); } + function create() { game.world.setSize(1920, 1200); + game.add.sprite(0, 0, 'backdrop'); + // Apply a 100% sepia filter to the entire game (this value can be tweened, modified in-game, etc) game.stage.css3.sepia = 100; } + function update() { - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/textures/dynamic texture 1.js b/Tests/textures/dynamic texture 1.js index ab8ba296..4b5bde86 100644 --- a/Tests/textures/dynamic texture 1.js +++ b/Tests/textures/dynamic texture 1.js @@ -1,55 +1,62 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.image('ball', 'assets/sprites/shinyball.png'); } + var wobblyBall; + function create() { // Create our DynamicTexture wobblyBall = game.add.dynamicTexture(32, 64); - // And apply it to 100 randomly positioned sprites - for(var i = 0; i < 100; i++) { + + for (var i = 0; i < 100; i++) { var temp = game.add.sprite(game.world.randomX, game.world.randomY); temp.texture.loadDynamicTexture(wobblyBall); } + // Populate the wave with some data waveData = game.math.sinCosGenerator(32, 8, 8, 2); } + function update() { wobblyBall.clear(); + updateWobblyBall(); } + // This creates a simple sine-wave effect running through our DynamicTexture. // This is then duplicated across all sprites using it, meaning we only have to calculate it once. var waveSize = 8; var wavePixelChunk = 2; var waveData; var waveDataCounter; + function updateWobblyBall() { var s = 0; - var copyRect = { - x: 0, - y: 0, - w: wavePixelChunk, - h: 32 - }; - var copyPoint = { - x: 0, - y: 0 - }; - for(var x = 0; x < 32; x += wavePixelChunk) { + var copyRect = { x: 0, y: 0, w: wavePixelChunk, h: 32 }; + var copyPoint = { x: 0, y: 0 }; + + for (var x = 0; x < 32; x += wavePixelChunk) { copyPoint.x = x; copyPoint.y = waveSize + (waveSize / 2) + waveData[s]; + wobblyBall.context.drawImage(game.cache.getImage('ball'), copyRect.x, copyRect.y, copyRect.w, copyRect.h, copyPoint.x, copyPoint.y, copyRect.w, copyRect.h); + copyRect.x += wavePixelChunk; + s++; } + // Cycle through the wave data - this is what causes the image to "undulate" var t = waveData.shift(); waveData.push(t); + waveDataCounter++; - if(waveDataCounter == waveData.length) { + + if (waveDataCounter == waveData.length) { waveDataCounter = 0; } } diff --git a/Tests/textures/dynamic texture 1.ts b/Tests/textures/dynamic texture 1.ts index d2dc41bf..c1b7218d 100644 --- a/Tests/textures/dynamic texture 1.ts +++ b/Tests/textures/dynamic texture 1.ts @@ -8,11 +8,9 @@ game.load.image('ball', 'assets/sprites/shinyball.png'); - - } - var wobblyBall: Phaser.DynamicTexture; + var wobblyBall: Phaser.Display.DynamicTexture; function create() { diff --git a/Tests/textures/dynamic texture 2.js b/Tests/textures/dynamic texture 2.js index 3c98de4e..c9208054 100644 --- a/Tests/textures/dynamic texture 2.js +++ b/Tests/textures/dynamic texture 2.js @@ -1,41 +1,52 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, null, create, update, render); + var starfield; + var xx = []; var yy = []; var zz = []; var xxx = 0; var yyy = 0; + function create() { // The width of the starfield var star_w = 12000; - for(var i = 0; i < 800; i++) { + + for (var i = 0; i < 800; i++) { xx[i] = Math.floor(Math.random() * star_w * 2) - star_w; yy[i] = Math.floor(Math.random() * star_w * 2) - star_w; zz[i] = Math.floor(Math.random() * 160) + 1; } + starfield = game.add.dynamicTexture(800, 600); } + function update() { starfield.clear(); - for(var i = 0; i < 800; i++) { - if(zz[i] == 1) { + + for (var i = 0; i < 800; i++) { + if (zz[i] == 1) { zz[i] = 100; } + xxx = (xx[i]) / (zz[i]); yyy = (yy[i]) / (zz[i])--; + //var x: number = xxx + game.input.x; //var y: number = yyy + game.input.y; var x = xxx + 400; var y = yyy + 300; var c = '#ffffff'; + //if (zz[i] > 80) c = '#666666'; //else if (zz[i] > 60) c = '#888888' //else if (zz[i] > 40) c = '#aaaaaa'; starfield.setPixel(x, y, c); } } + function render() { starfield.render(); } diff --git a/Tests/textures/dynamic texture 2.ts b/Tests/textures/dynamic texture 2.ts index 9fa030a8..6bb29b0a 100644 --- a/Tests/textures/dynamic texture 2.ts +++ b/Tests/textures/dynamic texture 2.ts @@ -4,7 +4,7 @@ var game = new Phaser.Game(this, 'game', 800, 600, null, create, update, render); - var starfield: Phaser.DynamicTexture; + var starfield: Phaser.Display.DynamicTexture; var xx = []; var yy = []; diff --git a/Tests/textures/filter test.js b/Tests/textures/filter test.js index 961e9f29..900b2ea3 100644 --- a/Tests/textures/filter test.js +++ b/Tests/textures/filter test.js @@ -1,38 +1,42 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update, render); + function preload() { game.load.image('backdrop', 'assets/pics/large-color-wheel.png'); game.load.image('coke', 'assets/sprites/cokecan.png'); game.load.image('mushroom', 'assets/sprites/mushroom2.png'); } + var hue = 0; var texture; + function create() { game.world.setSize(800, 800); + texture = game.add.dynamicTexture(800, 600); + var backdrop = game.add.sprite(0, 0, 'backdrop'); var cokecan = game.add.sprite(30, 20, 'coke'); var mushroom = game.add.sprite(600, 20, 'mushroom'); - texture.assignCanvasToGameObjects([ - backdrop, - cokecan, - mushroom - ]); + + texture.assignCanvasToGameObjects([backdrop, cokecan, mushroom]); + // Rats, filters don't get applied when the canvas is drawn to another canvas. Oh well :) texture.css3.grayscale = 100; } + function update() { // The value is given in degrees, so between 0 and 360, hence the wrapValue call below. hue = game.math.wrapValue(hue, 1, 360); - // Apply a hue rotation to the stage - //game.stage.css3.hueRotate = hue; - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } + function render() { texture.render(); } diff --git a/Tests/textures/filter test.ts b/Tests/textures/filter test.ts index f2d69b7a..e3075a21 100644 --- a/Tests/textures/filter test.ts +++ b/Tests/textures/filter test.ts @@ -14,7 +14,7 @@ } var hue: number = 0; - var texture: Phaser.DynamicTexture; + var texture: Phaser.Display.DynamicTexture; function create() { diff --git a/Tests/textures/starling texture atlas.js b/Tests/textures/starling texture atlas.js index 1a05be32..8a4dabc9 100644 --- a/Tests/textures/starling texture atlas.js +++ b/Tests/textures/starling texture atlas.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { // Starling/Sparrow XML Texture Atlas Method 1 // @@ -8,21 +9,28 @@ game.load.atlas('bits', 'assets/sprites/shoebox.png', 'assets/sprites/shoebox.xml', null, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING); game.load.atlas('bot', 'assets/sprites/shoebot.png', 'assets/sprites/shoebot.xml', null, Phaser.Loader.TEXTURE_ATLAS_XML_STARLING); } + var bits; var bot; + function create() { bot = game.add.sprite(800, 200, 'bot'); bot.animations.add('run'); bot.animations.play('run', 20, true); + bits = game.add.sprite(200, 200, 'bits'); bits.frame = 0; } + function update() { bot.x -= 5; - if(bot.x < -bot.width) { + + if (bot.x < -bot.width) { bot.x = game.stage.width; + bits.frame++; - if(bits.frame == bits.animations.frameTotal - 1) { + + if (bits.frame == bits.animations.frameTotal - 1) { bits.frame = 0; } } diff --git a/Tests/textures/texture atlas 1.js b/Tests/textures/texture atlas 1.js index 9f47abc4..a10e4f78 100644 --- a/Tests/textures/texture atlas 1.js +++ b/Tests/textures/texture atlas 1.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Texture Atlas Method 1 // @@ -8,11 +9,16 @@ // (in this case botData) game.load.atlas('bot', 'assets/sprites/running_bot.png', null, botData); } + var bot; + function create() { bot = game.add.sprite(400, 300, 'bot'); + bot.animations.add('run', null, 20, true); + bot.animations.play('run'); } + var botData = '{"frames": [{"filename": "running bot.swf/0000","frame": { "x": 34, "y": 128, "w": 56, "h": 60 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 2, "w": 56, "h": 60 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0001","frame": { "x": 54, "y": 0, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0002","frame": { "x": 54, "y": 58, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0003","frame": { "x": 0, "y": 192, "w": 34, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0004","frame": { "x": 0, "y": 64, "w": 54, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0005","frame": { "x": 196, "y": 0, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0006","frame": { "x": 0, "y": 0, "w": 54, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0007","frame": { "x": 140, "y": 0, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0008","frame": { "x": 34, "y": 188, "w": 50, "h": 60 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 3, "y": 2, "w": 50, "h": 60 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0009","frame": { "x": 0, "y": 128, "w": 34, "h": 64 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 },"sourceSize": { "w": 56, "h": 64 }},{"filename": "running bot.swf/0010","frame": { "x": 84, "y": 188, "w": 56, "h": 58 },"rotated": false,"trimmed": true,"spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 },"sourceSize": { "w": 56, "h": 64 }}]}'; })(); diff --git a/Tests/textures/texture atlas 2.js b/Tests/textures/texture atlas 2.js index 58f4c1fb..7f464e52 100644 --- a/Tests/textures/texture atlas 2.js +++ b/Tests/textures/texture atlas 2.js @@ -1,6 +1,7 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { // Texture Atlas Method 2 // @@ -8,250 +9,113 @@ // (in this case botData) game.load.atlas('bot', 'assets/sprites/running_bot.png', null, botData); } + var bot; + function create() { bot = game.add.sprite(game.stage.width, 300, 'bot'); + bot.animations.add('run'); bot.animations.play('run', 10, true); } + function update() { bot.x -= 2; - if(bot.x < -bot.width) { + + if (bot.x < -bot.width) { bot.x = game.stage.width; } } + var botData = { "frames": [ { "filename": "running bot.swf/0000", - "frame": { - "x": 34, - "y": 128, - "w": 56, - "h": 60 - }, + "frame": { "x": 34, "y": 128, "w": 56, "h": 60 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 0, - "y": 2, - "w": 56, - "h": 60 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 0, "y": 2, "w": 56, "h": 60 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0001", - "frame": { - "x": 54, - "y": 0, - "w": 56, - "h": 58 - }, + "frame": { "x": 54, "y": 0, "w": 56, "h": 58 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 0, - "y": 3, - "w": 56, - "h": 58 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0002", - "frame": { - "x": 54, - "y": 58, - "w": 56, - "h": 58 - }, + "frame": { "x": 54, "y": 58, "w": 56, "h": 58 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 0, - "y": 3, - "w": 56, - "h": 58 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0003", - "frame": { - "x": 0, - "y": 192, - "w": 34, - "h": 64 - }, + "frame": { "x": 0, "y": 192, "w": 34, "h": 64 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 11, - "y": 0, - "w": 34, - "h": 64 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0004", - "frame": { - "x": 0, - "y": 64, - "w": 54, - "h": 64 - }, + "frame": { "x": 0, "y": 64, "w": 54, "h": 64 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 1, - "y": 0, - "w": 54, - "h": 64 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0005", - "frame": { - "x": 196, - "y": 0, - "w": 56, - "h": 58 - }, + "frame": { "x": 196, "y": 0, "w": 56, "h": 58 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 0, - "y": 3, - "w": 56, - "h": 58 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0006", - "frame": { - "x": 0, - "y": 0, - "w": 54, - "h": 64 - }, + "frame": { "x": 0, "y": 0, "w": 54, "h": 64 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 1, - "y": 0, - "w": 54, - "h": 64 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 1, "y": 0, "w": 54, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0007", - "frame": { - "x": 140, - "y": 0, - "w": 56, - "h": 58 - }, + "frame": { "x": 140, "y": 0, "w": 56, "h": 58 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 0, - "y": 3, - "w": 56, - "h": 58 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0008", - "frame": { - "x": 34, - "y": 188, - "w": 50, - "h": 60 - }, + "frame": { "x": 34, "y": 188, "w": 50, "h": 60 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 3, - "y": 2, - "w": 50, - "h": 60 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 3, "y": 2, "w": 50, "h": 60 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0009", - "frame": { - "x": 0, - "y": 128, - "w": 34, - "h": 64 - }, + "frame": { "x": 0, "y": 128, "w": 34, "h": 64 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 11, - "y": 0, - "w": 34, - "h": 64 - }, - "sourceSize": { - "w": 56, - "h": 64 - } - }, + "spriteSourceSize": { "x": 11, "y": 0, "w": 34, "h": 64 }, + "sourceSize": { "w": 56, "h": 64 } + }, { "filename": "running bot.swf/0010", - "frame": { - "x": 84, - "y": 188, - "w": 56, - "h": 58 - }, + "frame": { "x": 84, "y": 188, "w": 56, "h": 58 }, "rotated": false, "trimmed": true, - "spriteSourceSize": { - "x": 0, - "y": 3, - "w": 56, - "h": 58 - }, - "sourceSize": { - "w": 56, - "h": 64 - } + "spriteSourceSize": { "x": 0, "y": 3, "w": 56, "h": 58 }, + "sourceSize": { "w": 56, "h": 64 } } ], "meta": { @@ -259,10 +123,7 @@ "version": "1.0", "image": "running_bot.png", "format": "RGBA8888", - "size": { - "w": 252, - "h": 256 - }, + "size": { "w": 252, "h": 256 }, "scale": "0.2", "smartupdate": "$TexturePacker:SmartUpdate:fb56f261b1eb04e3215824426595f64c$" } diff --git a/Tests/textures/texture atlas 3.js b/Tests/textures/texture atlas 3.js index 1242d778..b76bc5b4 100644 --- a/Tests/textures/texture atlas 3.js +++ b/Tests/textures/texture atlas 3.js @@ -1,21 +1,27 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { // Texture Atlas Method 3 // // In this example we assume that the TexturePacker JSON data is stored in an external file game.load.atlas('bot', 'assets/sprites/running_bot.png', 'assets/sprites/running_bot.json'); } + var bot; + function create() { bot = game.add.sprite(game.stage.width, 300, 'bot'); + bot.animations.add('run'); bot.animations.play('run', 10, true); } + function update() { bot.x -= 2; - if(bot.x < -bot.width) { + + if (bot.x < -bot.width) { bot.x = game.stage.width; } } diff --git a/Tests/textures/texture atlas 4.js b/Tests/textures/texture atlas 4.js index 20653eac..1a3f1c1d 100644 --- a/Tests/textures/texture atlas 4.js +++ b/Tests/textures/texture atlas 4.js @@ -1,30 +1,39 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Texture Atlas Method 4 // // We load a TexturePacker JSON file and image and show you how to make several unique sprites from the same file game.load.atlas('atlas', 'assets/pics/texturepacker_test.png', 'assets/pics/texturepacker_test.json'); } + var chick; var car; var mech; var robot; var cop; + function create() { game.stage.backgroundColor = 'rgb(40, 40, 40)'; + chick = game.add.sprite(64, 64, 'atlas'); + // You can set the frame based on the frame name (which TexturePacker usually sets to be the filename of the image itself) chick.frameName = 'budbrain_chick.png'; + // Or by setting the frame index //chick.frame = 0; cop = game.add.sprite(600, 64, 'atlas'); cop.frameName = 'ladycop.png'; + robot = game.add.sprite(50, 300, 'atlas'); robot.frameName = 'robot.png'; + car = game.add.sprite(100, 400, 'atlas'); car.frameName = 'supercars_parsec.png'; + mech = game.add.sprite(250, 100, 'atlas'); mech.frameName = 'titan_mech.png'; } diff --git a/Tests/tilemaps/csv tilemap.js b/Tests/tilemaps/csv tilemap.js index 8e659c6c..75ecdcfd 100644 --- a/Tests/tilemaps/csv tilemap.js +++ b/Tests/tilemaps/csv tilemap.js @@ -2,29 +2,33 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { // CSV Tilemap Test // First we load our map data (a csv file) game.load.text('csvtest', 'assets/maps/catastrophi_level2.csv'); + // Then we load the actual tile sheet image game.load.image('csvtiles', 'assets/tiles/catastrophi_tiles_16.png'); } + function create() { // This creates the tilemap using the csv and tile sheet we loaded. // We tell it use to CSV format parser. The 16x16 are the tile sizes. // The 4th parameter (true) tells the game world to resize itself based on the map dimensions or not. game.add.tilemap('csvtiles', 'csvtest', Phaser.Tilemap.FORMAT_CSV, true, 16, 16); } + function update() { - // Simple camera controls - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/tilemaps/map draw.js b/Tests/tilemaps/map draw.js index 9fb9dba1..c20208d3 100644 --- a/Tests/tilemaps/map draw.js +++ b/Tests/tilemaps/map draw.js @@ -2,20 +2,25 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { game.load.text('platform', 'assets/maps/mapdraw.json'); game.load.image('tiles', 'assets/tiles/platformer_tiles.png'); game.load.image('carrot', 'assets/sprites/carrot.png'); } + var map; var emitter; var marker; + function create() { map = game.add.tilemap('tiles', 'platform', Phaser.Tilemap.FORMAT_TILED_JSON); map.setCollisionRange(21, 53); map.setCollisionRange(105, 109); + game.camera.texture.opaque = true; game.camera.texture.backgroundColor = 'rgb(47,154,204)'; + marker = game.add.sprite(0, 0); marker.texture.width = 16; marker.texture.height = 16; @@ -27,13 +32,15 @@ //emitter.gravity = 150; //emitter.bounce = 0.8; //emitter.start(false, 20, 0.05); - } + } + function update() { // Collide everything with the map //map.collide(); marker.x = game.math.snapToFloor(game.input.worldX, 16); marker.y = game.math.snapToFloor(game.input.worldY, 16); - if(game.input.mousePointer.isDown) { + + if (game.input.mousePointer.isDown) { map.putTile(marker.x, marker.y, 32); } } diff --git a/Tests/tilemaps/tiled layers.js b/Tests/tilemaps/tiled layers.js index 6d72c56c..8dc1e043 100644 --- a/Tests/tilemaps/tiled layers.js +++ b/Tests/tilemaps/tiled layers.js @@ -2,31 +2,36 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { // Tiled Tilemap Test // First we load our map data (a json file exported from the map editor Tiled) // This data file has several layers within it. Phaser will render them all. game.load.text('jsontest', 'assets/maps/multi-layer-test.json'); + // Then we load the actual tile sheet image game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png'); } + var map; + function create() { // This creates the tilemap using the json data and tile sheet we loaded. // We tell it to use the Tiled JSON format parser. map = game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON); //map.currentLayer. - } + } + function update() { - // Simple camera controls - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/tilemaps/tiled tilemap.js b/Tests/tilemaps/tiled tilemap.js index 876ab223..70727249 100644 --- a/Tests/tilemaps/tiled tilemap.js +++ b/Tests/tilemaps/tiled tilemap.js @@ -2,29 +2,33 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create, update); + function preload() { // Tiled Tilemap Test // First we load our map data (a json file exported from the map editor Tiled) game.load.text('jsontest', 'assets/maps/test.json'); + //myGame.loader.addTextFile('jsontest', 'assets/maps/multi-layer-test.json'); // Then we load the actual tile sheet image game.load.image('jsontiles', 'assets/tiles/platformer_tiles.png'); } + function create() { // This creates the tilemap using the json data and tile sheet we loaded. // We tell it to use the Tiled JSON format parser. game.add.tilemap('jsontiles', 'jsontest', Phaser.Tilemap.FORMAT_TILED_JSON); } + function update() { - // Simple camera controls - if(game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { + if (game.input.keyboard.isDown(Phaser.Keyboard.LEFT)) { game.camera.x -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.RIGHT)) { game.camera.x += 4; } - if(game.input.keyboard.isDown(Phaser.Keyboard.UP)) { + + if (game.input.keyboard.isDown(Phaser.Keyboard.UP)) { game.camera.y -= 4; - } else if(game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { + } else if (game.input.keyboard.isDown(Phaser.Keyboard.DOWN)) { game.camera.y += 4; } } diff --git a/Tests/tweens/bounce.js b/Tests/tweens/bounce.js index f60c87bc..7349697e 100644 --- a/Tests/tweens/bounce.js +++ b/Tests/tweens/bounce.js @@ -1,20 +1,25 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('atari', 'assets/sprites/atari130xe.png'); } + var atari; + function create() { atari = game.add.sprite(300, 0, 'atari'); + startBounceTween(); } + function startBounceTween() { atari.y = 0; + var bounce = game.add.tween(atari); - bounce.to({ - y: 500 - }, 1000 + Math.random() * 3000, Phaser.Easing.Bounce.Out); + + bounce.to({ y: 500 }, 1000 + Math.random() * 3000, Phaser.Easing.Bounce.Out); bounce.onComplete.add(startBounceTween, this); bounce.start(); } diff --git a/Tests/tweens/pause test.js b/Tests/tweens/pause test.js index 1178e1b4..bf4ff3b3 100644 --- a/Tests/tweens/pause test.js +++ b/Tests/tweens/pause test.js @@ -1,14 +1,16 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { game.load.image('atari', 'assets/sprites/atari130xe.png'); } + var atari; + function create() { atari = game.add.sprite(300, 0, 'atari'); - game.add.tween(atari).to({ - y: 500 - }, 5000, Phaser.Easing.Bounce.Out, true, 5000); + + game.add.tween(atari).to({ y: 500 }, 5000, Phaser.Easing.Bounce.Out, true, 5000); } })(); diff --git a/Tests/tweens/tween loop 1.js b/Tests/tweens/tween loop 1.js index 9978703a..529ab087 100644 --- a/Tests/tweens/tween loop 1.js +++ b/Tests/tweens/tween loop 1.js @@ -1,21 +1,25 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('swirl', 'assets/pics/color_wheel_swirl.png'); } + var swirl; + function create() { // Here we'll assign the new sprite to the local swirl variable swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); + // Increase the size of the sprite a little so it covers the edges of the stage swirl.scale.setTo(1.4, 1.4); + // Set the origin to the middle of the Sprite to get the effect we need swirl.origin.setTo(0.5, 0.5); + // Create a tween that rotates a full 360 degrees and then repeats (loop set to true) - game.add.tween(swirl).to({ - rotation: 360 - }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); } })(); diff --git a/Tests/tweens/tween loop 2.js b/Tests/tweens/tween loop 2.js index d005dbc1..ca7239f2 100644 --- a/Tests/tweens/tween loop 2.js +++ b/Tests/tweens/tween loop 2.js @@ -1,25 +1,26 @@ /// (function () { var game = new Phaser.Game(this, 'game', 800, 600, preload, create); + function preload() { // Using Phasers asset loader we load up a PNG from the assets folder game.load.image('swirl', 'assets/pics/color_wheel_swirl.png'); } + var swirl; + function create() { // Here we'll assign the new sprite to the local swirl variable swirl = game.add.sprite(game.stage.centerX, game.stage.centerY, 'swirl'); + // Increase the size of the sprite a little so it covers the edges of the stage swirl.scale.setTo(1.4, 1.4); + // Set the origin to the middle of the Sprite to get the effect we need swirl.origin.setTo(0.5, 0.5); + // Create a tween that rotates a full 360 degrees and then repeats (loop set to true) - game.add.tween(swirl).to({ - rotation: 360 - }, 2000, Phaser.Easing.Linear.None, true, 0, true); - game.add.tween(swirl.transform.scale).to({ - x: 4, - y: 4 - }, 4000, Phaser.Easing.Linear.None, true, 0, true, true); + game.add.tween(swirl).to({ rotation: 360 }, 2000, Phaser.Easing.Linear.None, true, 0, true); + game.add.tween(swirl.transform.scale).to({ x: 4, y: 4 }, 4000, Phaser.Easing.Linear.None, true, 0, true, true); } })(); diff --git a/build/phaser-debug.js b/build/phaser-debug.js index 6a114005..ccb089b3 100644 --- a/build/phaser-debug.js +++ b/build/phaser-debug.js @@ -7390,85 +7390,120 @@ var Phaser; })(Phaser || (Phaser = {})); /// /** -* Phaser - TimeManager -* -* This is the game clock and it manages elapsed time and calculation of delta values, used for game object motion. +* @author Richard Davey +* @copyright 2013 Photon Storm Ltd. +* @license https://github.com/photonstorm/phaser/blob/master/license.txt MIT License +* @module Phaser */ var Phaser; (function (Phaser) { var TimeManager = (function () { /** - * Time constructor - * Create a new Time. + * This is the core internal game clock. It manages the elapsed time and calculation of delta values, + * used for game object motion and tweens. * - * @param game {Phaser.Game} Current game instance. + * @class TimeManager + * @constructor + * @param {Phaser.Game} game A reference to the currently running game. */ function TimeManager(game) { /** - * Elapsed since last frame. - * @type {number} + * Number of milliseconds elapsed since the last frame update. + * @property elapsed + * @public + * @type {Number} */ this.elapsed = 0; /** * Game time counter. * @property time - * @type {number} + * @public + * @type {Number} */ this.time = 0; /** - * How long the game has been paused for. Gets reset each time the game pauses. + * Records how long the game has been paused for. Is reset each time the game pauses. * @property pausedTime - * @type {number} + * @public + * @type {Number} */ this.pausedTime = 0; /** - * Time of current frame. + * The time right now. * @property now - * @type {number} + * @public + * @type {Number} */ this.now = 0; /** - * Elapsed time since last frame. + * Elapsed time since the last frame. * @property delta - * @type {number} + * @public + * @type {Number} */ this.delta = 0; /** * Frames per second. - * @type {number} + * @property fps + * @public + * @type {Number} */ this.fps = 0; /** - * Minimal fps. - * @type {number} + * The lowest rate the fps has dropped to. + * @property fpsMin + * @public + * @type {Number} */ this.fpsMin = 1000; /** - * Maximal fps. - * @type {number} + * The highest rate the fps has reached (usually no higher than 60fps). + * @property fpsMax + * @public + * @type {Number} */ this.fpsMax = 0; /** - * Minimum duration between 2 frames. - * @type {number} + * The minimum amount of time the game has taken between two frames. + * @property msMin + * @public + * @type {Number} */ this.msMin = 1000; /** - * Maximum duration between 2 frames. - * @type {number} + * The maximum amount of time the game has taken between two frames. + * @property msMax + * @public + * @type {Number} */ this.msMax = 0; /** - * How many frames in last second. - * @type {number} + * The number of frames record in the last second. + * @property frames + * @public + * @type {Number} */ this.frames = 0; /** - * Time of last second. - * @type {number} + * The time (in ms) that the last second counter ticked over. + * @property _timeLastSecond + * @private + * @type {Number} */ this._timeLastSecond = 0; + /** + * Records how long the game was paused for in miliseconds. + * @property pauseDuration + * @public + * @type {Number} + */ this.pauseDuration = 0; + /** + * The time the game started being paused. + * @property _pauseStarted + * @private + * @type {Number} + */ this._pauseStarted = 0; this.game = game; @@ -7481,7 +7516,7 @@ var Phaser; } Object.defineProperty(TimeManager.prototype, "totalElapsedSeconds", { get: /** - * + * The number of seconds that have elapsed since the game was started. * @method totalElapsedSeconds * @return {Number} */ @@ -7496,7 +7531,7 @@ var Phaser; * Update clock and calculate the fps. * This is called automatically by Game._raf * @method update - * @param {number} raf The current timestamp, either performance.now or Date.now + * @param {Number} raf The current timestamp, either performance.now or Date.now */ TimeManager.prototype.update = function (raf) { this.now = raf; @@ -7523,20 +7558,30 @@ var Phaser; } }; + /** + * Called when the game enters a paused state. + * @method gamePaused + * @private + */ TimeManager.prototype.gamePaused = function () { this._pauseStarted = this.now; }; + /** + * Called when the game resumes from a paused state. + * @method gameResumed + * @private + */ TimeManager.prototype.gameResumed = function () { // Level out the delta timer to avoid spikes this.pauseDuration = this.pausedTime; }; /** - * How long has passed since given time. + * How long has passed since the given time. * @method elapsedSince - * @param {number} since The time you want to measure. - * @return {number} Duration between given time and now. + * @param {Number} since The time you want to measure against. + * @return {Number} The difference between the given time and now. */ TimeManager.prototype.elapsedSince = function (since) { return this.now - since; @@ -7545,15 +7590,15 @@ var Phaser; /** * How long has passed since the given time (in seconds). * @method elapsedSecondsSince - * @param {number} since The time you want to measure (in seconds). - * @return {number} Duration between given time and now (in seconds). + * @param {Number} since The time you want to measure (in seconds). + * @return {Number} Duration between given time and now (in seconds). */ TimeManager.prototype.elapsedSecondsSince = function (since) { return (this.now - since) * 0.001; }; /** - * Set the start time to now. + * Resets the private _started value to now. * @method reset */ TimeManager.prototype.reset = function () { @@ -7818,6 +7863,110 @@ var Phaser; 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; @@ -15737,9 +15886,10 @@ var Phaser; * * @return {Particle} The newly created particle object. */ - //public particle(): ArcadeParticle { - // return new ArcadeParticle(this.game); - //} + GameObjectFactory.prototype.particle = function () { + return new Phaser.ArcadeParticle(this.game); + }; + /** * Create a new Emitter. * @@ -15748,9 +15898,13 @@ var Phaser; * @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): ArcadeEmitter { - // return this._world.group.add(new ArcadeEmitter(this.game, x, y, size)); - //} + GameObjectFactory.prototype.emitter = function (x, y, size) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof size === "undefined") { size = 0; } + return this._world.group.add(new Phaser.ArcadeEmitter(this.game, x, y, size)); + }; + /** * Create a new ScrollZone object with image key, position and size. * @@ -15849,9 +16003,10 @@ var Phaser; * @param emitter The Emitter to add to the Game World * @return {Phaser.Emitter} The Emitter object */ - //public existingEmitter(emitter: ArcadeEmitter): ArcadeEmitter { - // return this._world.group.add(emitter); - //} + GameObjectFactory.prototype.existingEmitter = function (emitter) { + 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. @@ -15888,6 +16043,373 @@ var Phaser; })(); Phaser.GameObjectFactory = GameObjectFactory; })(Phaser || (Phaser = {})); +/// +/** +* Phaser - ArcadeEmitter +* +* Emitter is a lightweight particle emitter. It can be used for one-time explosions or for +* continuous effects like rain and fire. All it really does is launch Particle objects out +* at set intervals, and fixes their positions and velocities accorindgly. +*/ +var Phaser; +(function (Phaser) { + var ArcadeEmitter = (function (_super) { + __extends(ArcadeEmitter, _super); + /** + * Creates a new Emitter object at a specific position. + * Does NOT automatically generate or attach particles! + * + * @param x {number} The X position of the emitter. + * @param y {number} The Y position of the emitter. + * @param [size] {number} Specifies a maximum capacity for this emitter. + */ + function ArcadeEmitter(game, x, y, size) { + if (typeof x === "undefined") { x = 0; } + if (typeof y === "undefined") { y = 0; } + if (typeof size === "undefined") { size = 0; } + _super.call(this, game, size); + + this.x = x; + this.y = y; + this.width = 0; + this.height = 0; + this.minParticleSpeed = new Phaser.Vec2(-100, -100); + this.maxParticleSpeed = new Phaser.Vec2(100, 100); + this.minRotation = -360; + this.maxRotation = 360; + this.gravity = 0; + this.particleClass = null; + this.particleDrag = new Phaser.Vec2(); + this.frequency = 0.1; + this.lifespan = 3; + this.bounce = 0; + this._quantity = 0; + this._counter = 0; + this._explode = true; + this.on = false; + + this.exists = true; + this.active = true; + this.visible = true; + } + /** + * Clean up memory. + */ + ArcadeEmitter.prototype.destroy = function () { + this.minParticleSpeed = null; + this.maxParticleSpeed = null; + this.particleDrag = null; + this.particleClass = null; + this._point = null; + _super.prototype.destroy.call(this); + }; + + /** + * This function generates a new array of particle sprites to attach to the emitter. + * + * @param graphics If you opted to not pre-configure an array of Sprite objects, you can simply pass in a particle image or sprite sheet. + * @param quantity {number} The number of particles to generate when using the "create from image" option. + * @param multiple {boolean} Whether the image in the Graphics param is a single particle or a bunch of particles (if it's a bunch, they need to be square!). + * @param collide {number} Whether the particles should be flagged as not 'dead' (non-colliding particles are higher performance). 0 means no collisions, 0-1 controls scale of particle's bounding box. + * + * @return This Emitter instance (nice for chaining stuff together, if you're into that). + */ + ArcadeEmitter.prototype.makeParticles = function (graphics, quantity, multiple, collide) { + if (typeof quantity === "undefined") { quantity = 50; } + if (typeof multiple === "undefined") { multiple = false; } + if (typeof collide === "undefined") { collide = 0; } + this.maxSize = quantity; + + var totalFrames = 1; + + /* + if(Multiple) + { + var sprite:Sprite = new Sprite(this.game); + sprite.loadGraphic(Graphics,true); + totalFrames = sprite.frames; + sprite.destroy(); + } + */ + var randomFrame; + var particle; + var i = 0; + + while (i < quantity) { + if (this.particleClass == null) { + particle = new Phaser.ArcadeParticle(this.game); + } else { + particle = new this.particleClass(this.game); + } + + if (multiple) { + /* + randomFrame = this.game.math.random()*totalFrames; + */ + } else { + if (graphics) { + particle.texture.loadImage(graphics); + } + } + + if (collide > 0) { + //particle.body.allowCollisions = Types.ANY; + particle.body.type = Phaser.Types.BODY_DYNAMIC; + particle.width *= collide; + particle.height *= collide; + } else { + //particle.body.allowCollisions = Types.NONE; + } + + particle.exists = false; + + // Center the origin for rotation assistance + //particle.transform.origin.setTo(particle.body.bounds.halfWidth, particle.body.bounds.halfHeight); + this.add(particle); + + i++; + } + + return this; + }; + + ArcadeEmitter.prototype.preUpdate = function () { + }; + ArcadeEmitter.prototype.postUpdate = function () { + }; + + /** + * Called automatically by the game loop, decides when to launch particles and when to "die". + */ + ArcadeEmitter.prototype.update = function () { + if (this.on) { + if (this._explode) { + this.on = false; + + var i = 0; + var l = this._quantity; + + if ((l <= 0) || (l > this.length)) { + l = this.length; + } + + while (i < l) { + this.emitParticle(); + i++; + } + + this._quantity = 0; + } else { + this._timer += this.game.time.elapsed; + + while ((this.frequency > 0) && (this._timer > this.frequency) && this.on) { + this._timer -= this.frequency; + this.emitParticle(); + + if ((this._quantity > 0) && (++this._counter >= this._quantity)) { + this.on = false; + this._quantity = 0; + } + } + } + } + + _super.prototype.update.call(this); + }; + + /** + * Call this function to turn off all the particles and the emitter. + */ + ArcadeEmitter.prototype.kill = function () { + this.on = false; + this.alive = false; + this.exists = false; + }; + + /** + * Handy for bringing game objects "back to life". Just sets alive and exists back to true. + * In practice, this is most often called by Object.reset(). + */ + ArcadeEmitter.prototype.revive = function () { + this.alive = true; + this.exists = true; + }; + + /** + * Call this function to start emitting particles. + * + * @param explode {boolean} Whether the particles should all burst out at once. + * @param lifespan {number} How long each particle lives once emitted. 0 = forever. + * @param frequency {number} Ignored if Explode is set to true. Frequency is how often to emit a particle. 0 = never emit, 0.1 = 1 particle every 0.1 seconds, 5 = 1 particle every 5 seconds. + * @param quantity {number} How many particles to launch. 0 = "all of the particles". + */ + ArcadeEmitter.prototype.start = function (explode, lifespan, frequency, quantity) { + if (typeof explode === "undefined") { explode = true; } + if (typeof lifespan === "undefined") { lifespan = 0; } + if (typeof frequency === "undefined") { frequency = 0.1; } + if (typeof quantity === "undefined") { quantity = 0; } + this.revive(); + + this.visible = true; + this.on = true; + + this._explode = explode; + this.lifespan = lifespan; + this.frequency = frequency; + this._quantity += quantity; + + this._counter = 0; + this._timer = 0; + }; + + /** + * This function can be used both internally and externally to emit the next particle. + */ + ArcadeEmitter.prototype.emitParticle = function () { + var particle = this.recycle(Phaser.ArcadeParticle); + + particle.lifespan = this.lifespan; + + //particle.body.bounce.setTo(this.bounce, this.bounce); + Phaser.SpriteUtils.reset(particle, this.x - (particle.width >> 1) + this.game.rnd.integer * this.width, this.y - (particle.height >> 1) + this.game.rnd.integer * this.height); + particle.visible = true; + + if (this.minParticleSpeed.x != this.maxParticleSpeed.x) { + particle.body.velocity.x = this.minParticleSpeed.x + this.game.rnd.integer * (this.maxParticleSpeed.x - this.minParticleSpeed.x); + } else { + particle.body.velocity.x = this.minParticleSpeed.x; + } + + if (this.minParticleSpeed.y != this.maxParticleSpeed.y) { + particle.body.velocity.y = this.minParticleSpeed.y + this.game.rnd.integer * (this.maxParticleSpeed.y - this.minParticleSpeed.y); + } else { + particle.body.velocity.y = this.minParticleSpeed.y; + } + + if (this.minRotation != this.maxRotation && this.minRotation !== 0 && this.maxRotation !== 0) { + particle.body.angularVelocity = this.minRotation + this.game.rnd.integer * (this.maxRotation - this.minRotation); + } else { + particle.body.angularVelocity = this.minRotation; + } + + if (particle.body.angularVelocity != 0) { + particle.rotation = this.game.rnd.integer * 360 - 180; + } + + //particle.body.drag.x = this.particleDrag.x; + //particle.body.drag.y = this.particleDrag.y; + particle.onEmit(); + }; + + /** + * A more compact way of setting the width and height of the emitter. + * + * @param width {number} The desired width of the emitter (particles are spawned randomly within these dimensions). + * @param height {number} The desired height of the emitter. + */ + ArcadeEmitter.prototype.setSize = function (width, height) { + this.width = width; + this.height = height; + }; + + /** + * A more compact way of setting the X velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setXSpeed = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minParticleSpeed.x = min; + this.maxParticleSpeed.x = max; + }; + + /** + * A more compact way of setting the Y velocity range of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setYSpeed = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minParticleSpeed.y = min; + this.maxParticleSpeed.y = max; + }; + + /** + * A more compact way of setting the angular velocity constraints of the emitter. + * + * @param Min {number} The minimum value for this range. + * @param Max {number} The maximum value for this range. + */ + ArcadeEmitter.prototype.setRotation = function (min, max) { + if (typeof min === "undefined") { min = 0; } + if (typeof max === "undefined") { max = 0; } + this.minRotation = min; + this.maxRotation = max; + }; + + /** + * Change the emitter's midpoint to match the midpoint of a Object. + * + * @param Object {object} The Object that you want to sync up with. + */ + ArcadeEmitter.prototype.at = function (object) { + //this.x = object.body.bounds.halfWidth - (this.width >> 1); + //this.y = object.body.bounds.halfHeight - (this.height >> 1); + }; + return ArcadeEmitter; + })(Phaser.Group); + Phaser.ArcadeEmitter = ArcadeEmitter; +})(Phaser || (Phaser = {})); +/// +/** +* Phaser - ArcadeParticle +* +* This is a simple particle class that extends a Sprite to have a slightly more +* specialised behaviour. It is used exclusively by the Emitter class and can be extended as required. +*/ +var Phaser; +(function (Phaser) { + var ArcadeParticle = (function (_super) { + __extends(ArcadeParticle, _super); + /** + * Instantiate a new particle. Like Sprite, all meaningful creation + * happens during loadGraphic() or makeGraphic() or whatever. + */ + function ArcadeParticle(game) { + _super.call(this, game); + + this.body.type = Phaser.Types.BODY_DYNAMIC; + this.lifespan = 0; + } + /** + * The particle's main update logic. Basically it checks to see if it should be dead yet. + */ + ArcadeParticle.prototype.update = function () { + if (this.lifespan <= 0) { + return; + } + + this.lifespan -= this.game.time.elapsed; + + if (this.lifespan <= 0) { + this.kill(); + } + }; + + /** + * Triggered whenever this object is launched by a Emitter. + * You can override this to add custom behavior like a sound or AI or something. + */ + ArcadeParticle.prototype.onEmit = function () { + }; + return ArcadeParticle; + })(Phaser.Sprite); + Phaser.ArcadeParticle = ArcadeParticle; +})(Phaser || (Phaser = {})); var Phaser; (function (Phaser) { ///