phaser-framework

Working with TypeScript

Phaser environment setup (Asp.Net MVC5 - Typescript - Visual Studio 2015)

Create a new ASP.Net Project:

enter image description here

Select the empty template:

enter image description here

Add two new folders: App and Scripts in the root folder:

enter image description here

Add npm configuration file in the root folder:

enter image description here

{
    "version": "1.0.0",
    "name": "phaser.js.environment.setup",
    "private": true,
      "devDependencies": {
        "gulp": "3.9.1",
        "phaser": "2.6.2"
      }
}

Add gulp configuration file in the root folder:

enter image description here

Add typings folder in Scripts folder:

enter image description here

Gulp task:

/// <binding ProjectOpened='install' />

var gulp = require('gulp');

gulp.task('phaser-setup-typings', function () {
    gulp.src([
        './node_modules/phaser/typescript/pixi.d.ts',
        './node_modules/phaser/typescript/p2.d.ts',
        './node_modules/phaser/typescript/phaser.d.ts',
    ])
   .pipe(gulp.dest('./Scripts/typings'));
});

gulp.task('phaser-setup', function () {
    gulp.src([
        './node_modules/phaser/build/phaser.min.js',
    ])
   .pipe(gulp.dest('./Scripts/'));
});

gulp.task('install', ['phaser-setup-typings', 'phaser-setup']);

Run the install task:

enter image description here

Add a typescript file in the App folder:

enter image description here

Add an MVC controller:

enter image description here

using System.Web.Mvc;

namespace PhaserSetUp.Controllers
{
    public class HomeController : Controller
    {
        // GET: Home
        public ActionResult Index()
        {
            return View();
        }
    }
}

Add web optimization nuget package:

Install-Package Microsoft.AspNet.Web.Optimization

enter image description here

Add BundleConfig.cs class into the App_Start folder:

using System.Web.Optimization;

namespace PhaserSetUp.App_Start
{
    public class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            bundles.Add(new ScriptBundle("~/bundles/app").Include(
                        "~/App/app.js"));
        }
    }
}

Edit the Global.asax

using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Http;

namespace PhaserSetUp
{
    public class Global : HttpApplication
    {
        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup
            AreaRegistration.RegisterAllAreas();
            GlobalConfiguration.Configure(WebApiConfig.Register);
            RouteConfig.RegisterRoutes(RouteTable.Routes);  
            BundleConfig.RegisterBundles(BundleTable.Bundles);         
        }
    }
}

Add a View:

enter image description here

@using System.Web.Optimization
<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>@ViewBag.Title</title>
</head>
<body>
    <div>
        @RenderBody()
    </div>
    <script src="../../Scripts/phaser.min.js"></script>
    @Scripts.Render("~/bundles/app")
</body>
</html>

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow