Jump to content

  • Log In with Google      Sign In   
  • Create Account


EmployeeNumber8

Member Since 08 Mar 2006
Offline Last Active Jan 30 2014 11:05 AM
-----

#5047647 drawing a design of coins from an xml file or json file.

Posted by EmployeeNumber8 on 28 March 2013 - 08:20 AM

if this is all that you have on that file, then it would be more efficient (space and time to load) to use a simple text file with one pattern per line.

 

It would be even more efficient to not use a separate file at all. You can simply use an array.

 

 

 

Start with a default.

var coins = [0,0,0,0,0,0,0,0];

 

Now every time you execute this line of code, it will return an array of random 1's and 0's

 

coins.map(function() { return +(Math.random() > 0.5) });

 

 

 

As an aside - When you're dealing with JavaScript pretend "xml" is a bad word. Always use JSON.




#5039719 HTML5 game development tools

Posted by EmployeeNumber8 on 05 March 2013 - 03:37 PM

Sublime Text 2 is a very nice cross platform IDE. If you are coming over from Visual Studio, then I think you'll like it.

 

Google Closure Compiler is your best option for compilation/minification of your scripts. There is also a command line version of the compiler on the Closure Tools home page.

 

Firefox and Chrome push out updates very often, so to make sure you're ahead of the game ...

Get the dev channel version of Firefox  and the dev channel version of Chrome. Why? You can catch bugs and report them for Chrome here and for Firefox here ... and they may get fixed before that version in the release channel gets deployed to the masses (the dev channel browsers are a couple versions ahead). You can also use new features/API not yet available in the release channel.

 

You need Firebug for Firefox.

Chrome comes with built in debugging tools, just press F12.

 

Basically - an IDE isn't enough.

 

Internet Explorer is going to be a big issue ... most developers are innovating in Firefox and Chrome. The more that happens the more Internet Explorer gets phased out when it comes to advanced in-browser apps and games.




#5037579 How to redefine variable in Javascript

Posted by EmployeeNumber8 on 28 February 2013 - 07:31 AM

That is something you need to use the debugger for. 

 

Here is how it is done in Chrome




#5037315 How to redefine variable in Javascript

Posted by EmployeeNumber8 on 27 February 2013 - 02:33 PM

bullets.push(new CreateBullet(jet1.getX(),jet1.getY()));

 

Based on the CreateBullet function, that code will result in a bug. It should be:

bullets.push(CreateBullet(jet1.getX(),jet1.getY()));

 

Just have to drop the new




#5037307 How to redefine variable in Javascript

Posted by EmployeeNumber8 on 27 February 2013 - 02:25 PM

I see that you had this at first:

// My bullet code
function CreateBullet(startX, startY)
{
   var x = startX;
   var y = startY;

   var Bullet = function()
   {
   }

   Bullet.prototype.draw = function(){
     bullet.update();
          for(b in bullets){
                ctxBullet.drawImage(bulletImage, jet1.getX(), jet1.getY());
                 b.move(1,0);
           } 
   }

   Bullet.prototype.getX = function()
   {
      return x;
   }

   Bullet.prototype.update = function(){
      ctxBullet.clearRect(0, 0, 800, 600);
   }
   
   Bullet.prototype.getY = function()
   {
      return y;
   }
   
   Bullet.prototype.move = function(dx,dy)
   {
      x += dx;
      y += dy;
   }
   return new Bullet();
}

 

 

Which is fine, but I see a bug in the draw function. I'm sure you can spot it too. You are using bullet.update() but it should be this.update();




#5037285 How to redefine variable in Javascript

Posted by EmployeeNumber8 on 27 February 2013 - 01:57 PM

I thought this code would be an infinite loop, but oddly enough it works.

Even though it works, you should name the prototype differently. It should be a Bullet prototype.

 

// My bullet code
function CreateBullet(startX, startY)
{
   var x = startX;
   var y = startY;
   var dx = 0;
   var dy = 0;

   var CreateBullet = function()
   {
   }

   CreateBullet.prototype.getX = function()
   {
      return x;
   }

   CreateBullet.prototype.getY = function()
   {
      return y;
   }
   
   CreateBullet.prototype.move = function()
   {
      x += dx;
      y += dy;
      return this;
   }
   return new CreateBullet();
}



#5036683 How to redefine variable in Javascript

Posted by EmployeeNumber8 on 26 February 2013 - 07:06 AM

Since you start out with...

 

var jet1 = Jet();

 

then that means in following code there is potential bug, can you spot it?

 

   Jet.prototype.draw = function(){
     jet1.update();
     ctxJet.drawImage(plane, x, y);
      
   }

 

 

What if you create another jet with var jet2 = Jet(); 




#5036680 How to redefine variable in Javascript

Posted by EmployeeNumber8 on 26 February 2013 - 06:53 AM

As Mito pointed out. Your bug is here:

function checkKeyDown(e) {
    var keyID = e.keyCode || e.which;
    if (keyID === 38 ) { //up arrow     
        jet1.setDX = 1;
        jet1.dx = 1;    
    }
}

 

jet1.setDX is a function, so you have to go jet1.setDX(1);

jet1.dx is "private", so you can't access it that way.




#5034194 Help moving a picture with JavaScript

Posted by EmployeeNumber8 on 19 February 2013 - 10:07 AM

Maybe it is your keyListener function? You attach keyListener to document.onkeydown and document.onkeyup, but keyListener has no code in it.




#5034164 Help moving a picture with JavaScript

Posted by EmployeeNumber8 on 19 February 2013 - 08:30 AM

There are many approaches, but I personally like this one.

 

 

function CreateBullet(startX, startY)
{
   //these will be private
   var x = startX || 0;
   var y = startY || 0;

   var Bullet = function()
   {
   }

   Bullet.prototype.getX = function()
   {
      return x;
   }
   
   Bullet.prototype.getY = function()
   {
      return y;
   }
   
   Bullet.prototype.move = function(dx,dy)
   {
      x += dx;
      y += dy;
      return this;
   }

   return new Bullet();
}

var bullet = CreateBullet(0,0);
bullet.move(1,2);



#5030460 How to publish html5 javascript game.

Posted by EmployeeNumber8 on 09 February 2013 - 01:53 PM

Take a look at c9.io  

 

You can use it for free, and it has a browser based IDE, so you can make changes on the fly.




#5029040 html5/javascript best way to add sound

Posted by EmployeeNumber8 on 05 February 2013 - 09:13 AM

The best thing to do is to use the WebAudio api, and fallback to creating Audio elements if WebAudio is not supported. The reason you want to fallback to the Audio tag is because it is very limited. I find that IE doesn't do a great job with multiple Audio elements. Chrome doesn't do a good job either. Last time I checked - Chrome creates TWO threads for each Audio element, and there is a hard limit of 100 threads (I think), so if you're not careful your app will crash, randomly, and you'll have no idea why.

The chrome://media-internals/ about page can help you see how many are in use due to Audio. 

 

You will also need to create audio in MP3 format and OGG format since IE does not currently support OGG, and last time I checked, Firefox does not support MP3.

Mozilla actually does not support WebAudio yet, but it is in the works.

 

 

HTML5 audio is a pain if you're doing something advanced.

 

If you don't want to deal with this stuff yourself, then you can just use an audio framework like Howlerjs




#5023951 Whats wrong with this code?

Posted by EmployeeNumber8 on 21 January 2013 - 10:40 AM

setTimeout(GameLoop, animate, collect, 33);

 

 

You should pass 2 parameters to setTimeout: The first being the function that will execute, the second being the delay before the function is executed.

 

 

 

arcadeButton.click(function(){
GameLoop();
playGame = true;
});

 

 

"playGame = true" should be above "GameLoop()"

 

 

 

Based on your code, you want the game loop to look a little more like this:

function GameLoop()
{
   if(playGame)
   {
      collect();
      animate();

      setTimeout(GameLoop, 33);
   }
};	

 

Run your game logic, animate, then use setTimeout to simulate a loop.




#5023901 Whats wrong with this code?

Posted by EmployeeNumber8 on 21 January 2013 - 08:29 AM

Just change this...

arcadeButton.click(function(){
   num = 11;
});
 
console.log(num);

 

 

 

 

to this...

arcadeButton.click(function(){
   num = 11;
   console.log(num);
});
 



#5023211 javascript buttons help

Posted by EmployeeNumber8 on 19 January 2013 - 11:12 AM

I bet there is some issue in the the game logic somewhere, causing the game to end. It doesn't sound like a button issue.

 

Maybe open up the console in Chrome/Firebug and manually start the game, and see what happens. Use the debugger and step through your code.






PARTNERS