Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 13 Aug 2006
Offline Last Active Oct 11 2014 04:55 PM

#4990025 Javascript - Better to instantiate variables, or leave them undefined?

Posted by on 14 October 2012 - 06:55 AM

In Javascript, if I know a variable type, but not necessarily the value, is it better on memory or run-time performance to instantiate it with a 'dummy' value, or is it better to just leave it undefined, and then only instantiate it when it is first needed?

For example...

var array1;
var number1;
var string1;
/* vs */
var array2 = [];
var number2 = 0.0;
var string2 = "";

// later in code...
function onInit(){
number1 = 3.142;
number2 = 2.718;
string1 = "Hello";
string2 = "World";

Is it best to fill the variable with a dummy 'type' or just leave it 'undefined' ?

#4985525 As a beginner in Game Programming, I just realized something.

Posted by on 30 September 2012 - 04:57 PM

I would have to agree with glhf about networking. Even a high score system is daunting to the beginner programmer. On the other hand, I am a perfectionist, and unfortunately there is no 'perfect' UI, which is probably why I have such a hard time with them myself.

What gets me are what I call 'What If' situations... what if the user presses down the mouse button, then drags onto my UI button? What if they push down, then drag off? What if they push the UI button, drag off, then drag back on, and let go? Should I have an on-hover effect? Should it glow? What color? Should there be a 'down' effect, for when the user presses down, but has not released yet? Should the event happen on mouse DOWN or on mouse UP?

These are the things that keep me up at night!!!! :D

So yeah... networking and multi-player games are a real pain in the ass, but UI elements are a close contender.

#4894752 HTML5+Canvas Game Loop Critique

Posted by on 17 December 2011 - 06:22 AM

I have been working on this for a while now, going back and forth between several game loops, and I finally found one that I am happy with (for now). It looks a bit extravagant, but... whatever.

I have tested it with Chrome 15.0.874.x, Firefox 8.0, and IE 9.0.8.x and no issues so far (except with my lame collision detection). I also tried it with my Droid phone, and although the FPS is pretty low, it still works ok.

This is a 'frame rate independent' game loop for HTML5 Canvas.

// earlier in code: setInterval(GameLoop, 1)

var FPS = 60; // fps
var PS = 1/FPS; // physics step
var last = Date.now()/1000;
var accrued = 0.0; // accrued time (betwen physics steps)

var GameLoop=function(){
	if(false == _this.paused){
		var now = Date.now()/1000;
		var dt = ((now-last) > .2) ? .2 : now-last; // time between frames
		last = now;
		accrued += dt; // add dt to accrued
		if(dt > PS){ // if dt is more than a physics step
			Update(dt-(accrued-PS)); // bring positions up to 1 full physics step
			CheckCollisions(); // check collisions
			accrued -= PS; // deduct 1 physics step from time
			while(accrued >= PS){ // if accrued still greater tha a physics step
				Update(PS); // move positions ahead 1 step
				CheckCollisions(); // check collisions
				accrued -= PS; // deduct 1 physics step from accrued
			dt = accrued;
		else{ // if dt is less than a physics step
			if(accrued >= PS){ // if accrued time is more than a physics step
				Update(dt-(accrued-PS)); // bring positions up to one full physics step
				CheckCollisions(); // check collisions
				accrued -= PS; // deduct the physics step from accrued
				dt = accrued;
		last = Date.now()/1000; // for paused game
	if(dt > 0.0){
	Render(); // render images

You can see it in action on my ... 'game_1' demo: http://www.html5.bun...me_1/game1.html

FYI, I disabled the right mouse click, just for future game ideas. I'll be putting in sounds and animated images / particles and emitters soon...

Please let me know what you think...

#4889702 [web] JavaScript game loop

Posted by on 02 December 2011 - 01:06 AM

EDIT: I am now using this game loop:
// setInterval(GameLoop, 1);

var FPS = 50;
var dt = 1/FPS; // synthetic delta time
var last = Date.now()/1000;
var accrued = 0.0;
var ri = 0.0; // render interpolation

	var now = Date.now()/1000;
	accrued += (now-last);
	while(accrued > dt){
		accrued -= dt;
	ri = (accrued/dt); // calculate render interpolation
	Render(ri); // pass it to render moving images
	last = now;
Let me know if you find any 'issues' with this :) I have been working on it for a couple days weeks now, and like the results.

You can test out the game loop on my html5 test page...


There is an 800x600 canvas with 1000 'targets' bouncing around the screen.

Here is my updated game loop for html5 canvas. It works well for both 'fast' and 'slow' computers...
// setInterval(GameLoop, 1);
var old_time = Date.now();
var FPS = 1/60;
function GameLoop(){
	var new_time = Date.now();
	var dt = ((new_time - old_time)/1000);
	while(dt > FPS){
		dt -= FPS;
	old_time = new_time;

#4815612 Alpha Testers needed for Marine Defense game.

Posted by on 25 May 2011 - 08:42 AM

I'm looking for anyone interested in helping me alpha test a WIP game we are calling 'Marine Defense'.

It is a mix between 3rd person shooter, Tower Defense, and Gauntlet Legends game play.

Right now we have the basic framework and a few weapons working, and just need people to test out the installation, UI and level loading systems. The alpha will also come with the tutorial map, so there will be a few monsters for you to shoot. :)

Here are a couple early prototype videos:

I'm still working out a few kinks, but I am hoping the Alpha will be ready by the end of the week (interpreted as Friday night midnight).

To 'sign up' for beta, just go to bunzaga.com, register, and then post a reply in the Marine Defense forums topic 'Marine Defense Alpha Sign Up':


I will then add your username to the Beta group.

Thanks in advance, and I'm happy to answer any questions people might have about me, the game, the engine we are using (World Weaver), etc.