visually recode c# to javascript

C++, C#, Java, PHP, ect...
Post Reply
Mardonis
Posts: 139
Joined: Wed Jun 29, 2011 7:54 pm

visually recode c# to javascript

Post 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
User avatar
hallsofvallhalla
Site Admin
Posts: 12023
Joined: Wed Apr 22, 2009 11:29 pm

Re: visually recode c# to javascript

Post 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.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: visually recode c# to javascript

Post 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.
The indelible lord of tl;dr
Post Reply

Return to “Coding”