Page 1 of 1

visually recode c# to javascript

Posted: Tue Sep 09, 2014 7:09 pm
by Mardonis
Does anyone know of a book or tutorial or any information on how to visually look at a C# program and try to recode it into javascript? Like maybe look at this thing in C# and that would be equevalant to that in javascript. Thank you. For example:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;
namespace New2DRPG.CoreComponents
{
 public class GameScreen : Microsoft.Xna.Framework.DrawableGameComponent
 {
 private List<GameComponent> childComponents;
 public GameScreen(Game game)
 : base(game)
 {
 childComponents = new List<GameComponent>();
 Visible = false;
 Enabled = false;
 }
 public List<GameComponent> Components
 {
 get { return childComponents; }
 }
 public override void Initialize()
 { base.Initialize();
 }
 public override void Update(GameTime gameTime)
 {
 foreach (GameComponent child in childComponents)
 {
 if (child.Enabled)
 {
 child.Update(gameTime);
 }
 }
 base.Update(gameTime);
 }
 public override void Draw(GameTime gameTime)
 {
 foreach (GameComponent child in childComponents)
 {
 if ((child is DrawableGameComponent) &&
 ((DrawableGameComponent) child).Visible)
 {
 ((DrawableGameComponent) child).Draw(gameTime);
 }
 }
 base.Draw(gameTime);
 }
 public virtual void Show()
 {
 Visible = true;
 Enabled = true;
 }
 public virtual void Hide()
 {
 Visible = false;
 Enabled = false;
 }
 }
}
I presume the public virtual void Show(){} down down below in the code mentioned above could be coded into javascript as:

Code: Select all

function Show() {
    'use strict';
    var visible, enabled;

    visible = true;
    enabled = true;
}
Just having a hard time in trying to think out what it would look like and what to look for in conversion.
Also this code was used as an example from the website tutorial on showing how to make a C# game with XNA. http://xnagpa.net/rpgtutorials.html

Re: visually recode c# to javascript

Posted: Tue Sep 09, 2014 7:35 pm
by hallsofvallhalla
I am not sure you are going to have much luck trying to recode a XNA game to Javascript. Most of your code relies on libraries.

You might be better off coding it from scratch using a HTML5 engine.

Re: visually recode c# to javascript

Posted: Wed Sep 10, 2014 11:57 pm
by Jackolantern
A lot of the logic will be translatable, but as Halls said, a ton of XNA's nuts and bolts are library calls. And that isn't directly portable. Probably your best bet would be to learn an HTML5 game library, so when you see a procedure in XNA to, for example, set the background to blue, you know how to do it in HTML5. Then you could port the logic to Javascript. But the organization is going to be vastly different. C# is a highly OOP language and is strictly typed with generics. This is a completely different paradigm compared to Javascript.