Sign in to follow this  

Is it inefficient to use Unity to turn 32kb of Javascript into a mobile app? Are there alternatives?

This topic is 480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What is Unity actually doing?  Is it simply wrapping a shell around the code, or compiling it into lower level code?

 

It possible to just make a simple app that is merely a browser, and run the js game code in that?

 

Part of the reason I ask is that my game code is <32kb and all I need is a menu and a way to connect to a server for PvP. The remainder will be all game trees, so a lot of recursion.

 

I tried a Unity built Minesweeper clone, which is a similarly simple, grid based puzzle.  It took forever to load.  The project has ~50x more objects than I have functions and is ~10,000x bigger.

 

Unity seems more like a graphics engine and mine is not a graphics-based game.

 

 

 

 

Share this post


Link to post
Share on other sites

I personally don't like Unity, I find it time consuming and messy compared to other solutions but I know it has a lot of marketing behind it and many of my students do seem to like it.

 

Perhaps just be aware that Javascript in Unity (actually called Unityscript) and Javascript for web browsers are very different. So you might have to end up recoding quite a lot of your work if it is already standard Javascript.

 

You can make an app that just surrounds a web browser and run your game in that, it would work. I don't know what the components are called but you can pretty much just drag and drop it in using the visual designers.

 

Edit: What unity does for web exporting is convert its compiled .NET code (Unityscript/C# etc...) to C++ with il2cpp then it uses Mozilla's free and open-source transpiler to compile the c++ to very low level Javascript (asm.js). This is faster than normal javascript because it can be optimized well (although isnt very human friendly to develop with directly). The output binaries are very large because Unity, as an off the shelf product provides a lot of things even if you dont use them and doesn't strip out everything you dont need.

Edited by Karsten_

Share this post


Link to post
Share on other sites

Thank you Karsten!!!  Nearly everything Unity offers, I don't need. But because it is a game, the pat answer has been "use Unity."  (I ran into a similar problem when I first developed the code. When I'd hit a bump with a simple function, the standard answer was "use a library". It turned out that everything I needed to do could be accomplished in pure JS. 

 

Followup Question: Is using a massive library for a single function also inefficient?  (I suspect it's a different process than what's going in with Unity.)

Share this post


Link to post
Share on other sites

If you are using pure JS, you can use cocos2d-js library or Phaser. You can use three.js for 3D. Wrap them with Crosswalk so it focuses on Chromium browser engine and not worry much on device differences (except for WebGL device-level features). That should give only what you need and definitely lower the file size and initial loading time.

Edited by Alectora

Share this post


Link to post
Share on other sites

Actually there are plentiful JavaScript game engines and libraries for both 2D and 3D. Here is a short incomplete list of some popular ones: HTML 5 Game Engines. Unity is targeted towards .NET developers and more suitable for PC/Console/Mobile games. While it can do browser games, I believe it is an overkill in most cases.

Edited by vanka78bg

Share this post


Link to post
Share on other sites

Followup Question: Is using a massive library for a single function also inefficient?  (I suspect it's a different process than what's going in with Unity.)

 

Personally I feel that dragging in a library just for a single function is a bad decision overall. It is not elegant and often causes problems with maintanance later on.

 

However... I must be wrong on this because I see so many Javascript developers drag in all sorts of crazy dependencies for doing extremely simple tasks. I am sure you have already seen the word "JQuery" pop up many many times on help forums. Always, without fail just to split a string, some weirdo will suggest JQuery.

 

But that said, I am in the fortunate position of being able to avoid working with developers such as these ;)

 

Edit:

It reminds me of the time when someone dragged in the GLM maths library into our [b]database project[/b] just to use the vec3 length function. The compiler we had on our build server didn't support such an old version of GLM and so when it came out why he had done this, It certainly didn't inspire much confidence in any of his later decisions. I think he later went on to use glm again, just for glm::detail::tvec1<T> or something just to zero initialize member variables... I did chuckle ;)

Edited by Karsten_

Share this post


Link to post
Share on other sites

Personally I feel that dragging in a library just for a single function is a bad decision overall. It is not elegant and often causes problems with maintanance later on.
 
However... I must be wrong on this because I see so many Javascript developers drag in all sorts of crazy dependencies for doing extremely simple tasks. I am sure you have already seen the word "JQuery" pop up many many times on help forums.


Hey, JQuery is usually a good choice, because it provides you with a lot of functionality that you're probably going to use later. It's a bit like seeing someone struggle with text manipulation using char*, and telling them to use std::string instead. They may not really need everything that std::string provides, but you may as well have it.

 

But Javascript developers do far worse things than that - you may have heard of the left-pad incident where someone removed a trivial library from the NPM package manager, one that adds a few spaces to the left side of a string to make it up to a certain length, and tons of important software was immediately broken because they depended on it indirectly.

 

However, this is not really an argument against using 3rd party libraries - it's an argument against:

  • deploying software by relying on every user having access to collaborative package managers
  • installing packages by name and expecting them to never be revoked, replaced, or moved
  • hiding a dependency's dependencies from the user
  • making your standard libraries so anaemic that you can't do much without pulling in 3rd party code or reinventing your own wheels
  • etc.

If a library does what you want, has already been tried and tested, and doesn't harm you or your users in some way (e.g. increased download times, difficulty of maintenance, security risks), then it's almost always more sensible to use it than to roll your own alternative.

Edited by Kylotan

Share this post


Link to post
Share on other sites

They may not really need everything that std::string provides, but you may as well have it.

 

Hmm, its closer to pointing people towards Qt, just to use QString to concatinate two char* together ;)

 

But yes, I see your point but I still do see too many Javascript developers dragging in JQuery for very trivial things.

Share this post


Link to post
Share on other sites

 

They may not really need everything that std::string provides, but you may as well have it.

 

Hmm, its closer to pointing people towards Qt, just to use QString to concatinate two char* together ;)

 

But yes, I see your point but I still do see too many Javascript developers dragging in JQuery for very trivial things.

 

 

I see the opposite.  Most JavaScript developers I know treat JQuery as though it is part of JavaScript.  Some of the newer developers have never programmed JavaScript without it and most new introductory Javascript textbooks start with right from the beginning the main reason being that to access the DOM in a consistent way across multiple browsers requires a lot of boilerplate code.

Share this post


Link to post
Share on other sites

Wow.  I'm glad I found this place!  So much good information!  (Of course, now there a part of me not going "maybe I should nut up and learn Objective C b/c bitwise operations will almost certainly come in handy later".)  

 

@Kylotan re: "Why do you think Unity will do these things for you, and why can't you do them in Javascript?"

 

Basically because Unity packages and compiles the code, and seems "automate" the process of PvP. (i.e. I'm such a raw beginner,  it could reduce learning time for getting the first iteration out there.)

Edited by beginnerdev

Share this post


Link to post
Share on other sites

I'm not sure that's so true these days - the DOM is pretty well standardised at the moment. http://youmightnotneedjquery.com/

 

 

The DOM is standardised but, few browsers follow the standard and the ones that do follow the standard have their own interpretation of it.  The link you provided only has 3 different versions of IE to show their examples and one or two of these may be enough to sway some people into using a library. Once you add Firefox, Chrome, Safari, Edge and Opera you start to get a whole slew of differences.  

 

The point of the link that developers should be aware of what JQuery is doing (A lot of them aren't) and not telling them that they don't need it.

Share this post


Link to post
Share on other sites

Buster2000: I agree that it's not telling people not to use JQuery, and in fact I think using JQuery is a good idea. But saying "few browsers follow the standard" is really not true any more. It hasn't been true for quite some years. There are still quirks and some non-standard extensions, and if you're targeting the fewer than 1% of people who still use IE7 then it's a consideration. But for most typical DOM manipulation you don't need to worry about it.

 

beginnerdev: Sorry, I misunderstood your initial question. Unity can probably do what you want but you don't need to compile the code. It also won't handle everything you need for PvP for you, although there are some built-in networking features which you may want to research. You're probably best off sticking with JS, using one of the suggestions above to make it into an app, and using some other technology for your server operations. There are companies that will host simple servers and provide game services for you - look into Photon, GameSparks, etc.

Share this post


Link to post
Share on other sites

This topic is 480 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this