Tuesday 2 February 2021

 TypeScript VS JavaScript for Cocos Creator

With the cocos creator game development tool, two languages are supported for the development of games. The engine is built on top of cocos2d-X that uses C++ for the development of games but cocos creator itself supports Javascript and typeScript for game development. I generally prefer to use TypeScript in my projects so I will try to make you understand why that is my choice.



A brief distinction on the two languages (Javascript vs TypeScript)

Fellows, there is nothing complicated about the two languages in the discussion today if you understand that TypeScript is a superset of JavaScript. Think of TypeScript like JavaScript's older brother. The two languages in more ways are similar than different. Now there are differences between the two just like there are differences between brothers even if they are twins right? both languages are now using the ES6 in their latest variation but let's talk about it from the point of cocos creator.

  1. TypeScript can be strongly typed and that has a number of benefits. Strongly typed languages allow you to explicitly mention the type of variables that you want to use. you could for example want to use a number or a string. You can work with strongly typed variables with this and I find it useful coming from a C++ background. 
  2. Error messages are easier to understand in my view because the interpreter or console 👀 understands the strongly typed TypeScript. JavaScript is loosely typed so debugging JavaScript, even for web developers can be a bit messy.
  3. The Cocos Creator generated .TS file is easier and less intimidating for newcomers to the engine than the JavaScript one. There is a lot of code in the .JS. Now, the code does the same thing and when you read it through, you will see that it is the same functions working but still, TypeScript is easier on the eyes. TypeScript is easier for newcomers.
  4. For people that do not know TypeScript. You can write JavaScript code in TypeScript files and it will be just as valid. You cannot write Typescript code in a JavaScript file but you can write JavaScript in a Typescript file. So if you are a JavaScript developer, fear not ! ! !
  5. For those that want to do game development even in other engines like Unity or Unreal. C# and C++ syntax will be closer to TypeScript than vanilla JavaScript. You might want to get used to TypeScript if you want to know a lot more about game engines.
The important thing to note: There is no performance difference when using either language. I cannot find evidence for one language being faster in the files I have looked into.  You are just as fast with either language because they use a similar if not the same ECMAscript engine.

Saturday 2 January 2021

About

                                                       
Welcome to SweshiInc,

This blog is about game development using a number of tools. Most of the focus is on open source or free tools for making different parts of games. 


The blog posts teach game development concepts especially using the cocos products and supplementary tools that work with those products such as Cocos Creator2D and 3D. Other blog posts review different versions of the game engines and I share my thoughts on some things happening in the industry. Subscribe to the blog to stay updated with insights, tutorials, and views on game development if you are interested in that kind of stuff.