Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm a programming beginner.

I made a tiny one scene point and click adventure game to try to understand simple game logic and came up with this: CreateJS features prototypes for creating bitmap images, sprites and sounds objects. I create them and define their properties in a corresponding function (for example images(); spritesheets(), sounds()...). I then create functions for each animation sequence and "game level" functions, which handle user interactions and play the according animations and sounds for a certain event (when the level is complete, the current level function calls the next level function). And I end up with quite the mess.

What would be the "standard (if something like that exists)" OOP approach to structure simple game data and interactions like that?

I thought about making game.images, game.sprites, game.sounds objects, which contain all the game data with its properties using CreateJS constructors. game.spriteAnimations and game.tweenAnimations objects for sprite animations and tweens and a game.levelN object, which communicates with a game.interaction object, processing user interaction. Does this make any sense?

How do you structure your simple game code? Thanks in advance!

share|improve this question
Game development in javascript is a bit different than in other languages, because javascript is only a scripting language for the browser and it's intended to be used differently. People like Douglas Crockford who devote their time to researching better ways of using javascript, arrive to the conclusion that you shouldn't try to use it as you would another imperative language. It's fundamentally different. Also be careful with OOP concepts in javascript. My point is: make sure you really know JS before doing anything serious like gamedev. – rootlocus Nov 19 '12 at 22:51
@rootlocus: Why would you say that? Except for forced asynchronous content loading i didn't find antyhing different when comparing 2d games in javascript and xna games. The oop does not work in javascript out of the box (obviously, since there are prototypes) but with things like TypeScript, there is not much difference between typescript and c#. Also there is almost no difference between scripting language and programming language - since c# can be used for scripting too. – Kikaimaru Nov 20 '12 at 11:49
@Kikaimaru: You're right, those are the major differences. Also you can't load any kind of files. 3D models have to be JSON, shaders have to be JSON, and the only reason texture loading works is because browsers understand image files ( even though they are supposed to be handled differently ). And you shouldn't force asynchronous content loading. You should use some sort of event driven system, or proxies ( like actionscript ). That makes it different enough for me. – rootlocus Nov 20 '12 at 17:19
@rootlocus: well normally you use your own model formats, and when you know how to load model file in any other language, you can extremely easily convert it to json. And asynchronous content loading is a good thing that should be done even on desktop games. Shaders are not json files they are shader files. By the way you can also parse xml in javascript out of the box. And using new HTML5 FileAPI and FileReader you can load anything you want. – Kikaimaru Nov 22 '12 at 16:19
I am not sure I understand you question; would something like this directory/scene concept help you: – oberhamsi Nov 29 '12 at 15:22
up vote 1 down vote accepted

Well maybe all what you're saying leads to one conclusion you need to get a higher level game framework that will handle more of the not-so-easy low level stuff for you.

I know of Ganvas (free), ImpactJS (paid), Construct 2 (free/paid for more features), Unity(paid). Other gamedev folks might have other framework ideas.

But if you feel CreateJS is a too tiny framework for you, go search for a more developped framework first. Developing a framework by yourself or even extending an existing one is a huge task (especially if you target both desktop browsers and smartphones) that no one should under-estimate.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.