Author Topic: just starting out in java/html  (Read 60020 times)

0 Members and 1 Guest are viewing this topic.

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
just starting out in java/html
« on: January 10, 2014 »
hi every one,

i started this topic because i would like too learn as much as possible about coding in html/java i started modifying some of combatkings code last night but it all went horribly wrong. i think a good first step would be too ask what sort of environment do you guys set up too develop app/demos.

last night i was just using notepad then saving the html file dragging it into firefox and trying too debug/trace variables with the firefox debugger. it was all really rather cumbersome and taking far too much time.

so i guess a good first step would be too get comfortable with the available tools and see what you guys have learned over the years.. all the do's and dont's  :cheers:
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #1 on: January 10, 2014 »
My first tip is debugging:

*1 Have a div tag below your demo, such as this:
Code: [Select]
<div id="debug"></div>
*2 At the start of your main program cycle, add this line of JavaScript:
Code: [Select]
document.getElementById("debug").innerHTML = "";
*3 At every point in your JS where you need to monitor a variable, insert this code:
Code: [Select]
document.getElementById("debug").innerHTML += "#variable_name# = " + #variable_name# + "<br />";where #variable_name# is replaced by the name of the variable being monitored, but without the hashes.

Most modern browsers have developer tools, but this is the most consistent method I've found for debugging.

All the best in exploring JS. :D
« Last Edit: January 11, 2014 by combatking0 »
You are our 9001st visitor.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #2 on: January 10, 2014 »
that is perfect ck!!!

that will make my life much much easier thanks mate, i have been looking at various web development tools tonight and the one i keep coming back too is firebug it lets you edit code in real time have you had any experience with any of these tools? i would like too get the environment feeling a little more like the visual studio ide.

thanks again.
Challenge Trophies Won:

Offline Gore Motel

  • C= 64
  • **
  • Posts: 45
  • Karma: 18
    • View Profile
    • Gore Motel
Re: just starting out in java/html
« Reply #3 on: January 11, 2014 »
At the moment I'm trying to learn WebGL and I'm writing code in an editor called Brackets (works on Windows, Linux and OSX).

The great thing about it is that it allows for live development in Chrome. When you activate the Live Preview feature, it opens your project in Chrome and any changes you make in your HTML or CSS files are updated instantly, and any changes you make in your JS files are updated as soon as you save the file.

Let's say you're working on a horizontal menu using CSS and trying to figure out the spacing between menu items. It gets tedious to make changes using Notepad, saving the file, then switching back to the browser and reloading the page. In Brackets, you can just run it as a smaller window on top of your browser (or on a second monitor), change some values in your CSS file and see the HTML file being updated in real-time.

And an example in JS: you're trying to draw stuff on the canvas, but you're not exactly sure where you want to place it, or what size it should be. Using Brackets, you can just modify your code, save the file and immediately see the changes.

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #4 on: January 11, 2014 »
IE9+, Chrome and Firefox all display their developer tools when you press F12. The other major competitors (Safari, Opera) might work in a similar way, but I haven't tested them.

Brackets sounds excellent. K+ for recommending this one. You're one step ahead of me with WebGL, Gore Motel.
You are our 9001st visitor.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #5 on: January 11, 2014 »
thank you guys!!

@gore motel that sounds like the ticket! k++

when i get a little time too sit down tonight im going too try a raycaster out so ill post where i get too.. gulp :)
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: just starting out in java/html
« Reply #6 on: January 11, 2014 »
The dev tools in IE are really pretty good.  You can set breakpoints, skip over code and have it break on exceptions.
I use VS to type in my code and just F5 the browser.  At least then I get intellisense.  VS can also debug javascript but that's massive overkill.
btw. Java and JavaScript are two totally different things, related only by having a similar name.
Cheers,
Jim
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #7 on: January 12, 2014 »
Thanks for clearing up the JS / JavaScript difference, Jim. I've been using JS as a shorthand for JavaScript, but it could cause some confusion further down the line if I keep doing that.
You are our 9001st visitor.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #8 on: January 12, 2014 »
for someone starting out its very easy too get confused between the two. i must admit up until recently i really didn't have a clue there was a difference  ;D.

cheers for the tips too jim. so it is possible too use intellisense? that would make a massive difference! ill have too give a similar set up a go.

well tonight i finally managed after coding for the last five hours too get a basic raycaster i had been working on in fb ported over too javascript using the canvas. i was making some of the most stupid mistakes you guys would lol.. like cnvs.fillstyle = "rgb(255,100,100)"; missing out the capital S in fillstyle so then i was getting no color etc.. but i think i finally have a pretty good grasp of things.

now i just need a good method of how too accept control inputs i need 4 inputs for forward back turn left and turn right. i would ideally like too have my code compatible with touch screen devices but i am really not sure what too look into.

oh one other thing. i notice you set your form too only invoke the main function at every 40 millisecs or 25fps ck. is there any particular reason why its set at this or should it be ok too go too various different refresh rates.

thanks everyone.
« Last Edit: January 12, 2014 by ninogenio »
Challenge Trophies Won:

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: just starting out in java/html
« Reply #9 on: January 12, 2014 »
->CK  -  I said Java and Javascript are different.  For me JS and Javascript mean the same thing - the files have a .js extension.  Java source code usually ends with .java.

Quote
so it is possible to use intellisense
Yes, autocomplete, go to definition across multiple files etc. all work if you use VS as your editor.

Quote
i notice you set your form to only invoke the main function at every 40 millisecs or 25fps ck. is there any particular reason why its set at this or should it be ok to go to various different refresh rates.
You can do this in a number of ways.  If you use setInterval then your code will get called at (or around) that interval, unless of course the last one is still running.  So if you set it too fast you'll end up just skipping some calls, or having some delayed.  Javascript is single-threaded in the browser always.
In my xmas tree demo, I set a single shot setTimeout at the end of each frame, which means at least none will get missed and the frames are spaced evenly even if they took a long time to render.
I suspect neither is a particularly accurate timer, I don't think you can really guarantee perfect 60Hz stuff on the web.

Jim
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #10 on: January 12, 2014 »
thanks jim!!

i used setInterval and set it too 16ms i dont know what the difference would be between this and setTimeout. i hope i have used it properly.

well i figured out key presses and other things so. here is my first little project i hope i have used the various java script items properly. if any body sees anything i am doing that's not great could you please point it out too me as it really was a bit of a stumble in the dark.

cheers guys i doubt i would have gotten this far into my learning without the helping hand!

edit- i should say the keys are w for strafe forward s too strafe back and arrow left arrow right too rotate cam.
« Last Edit: January 12, 2014 by ninogenio »
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #11 on: January 12, 2014 »
->CK  -  I said Java and Javascript are different.  For me JS and Javascript mean the same thing - the files have a .js extension.  Java source code usually ends with .java.

Between Java, JavaScript, JScript, JQuery and sleep deprivation I'm a bit confused. I'm ready for a holiday again, and I've only been back to work for a week ;) All I know about Java is that I don't want to install the SDK again - it was a pain in the bottom.

Anyway, I prefer 25fps for no good reason - most machines these days should be able to do 30fps or 40fps with few or no problems. Seems a bit odd that I have nostalgia for a frame rate. Time I upgraded!

I noticed during the recent Christmas competition that my entry was running slower on my laptop than it was on my work desktop when I was using setTimeout() at the end of each frame, but setInterval() made things more consistent, so only a very slow machine should start to skip frames.

As for mouse position and key inputs, I have built a couple of functions to deal with them.
Add the following to the body tag:
Code: [Select]
<body onKeydown="control(1, event);" onKeyup="control(0, event);">Then add the following to the canvas tag:
Code: [Select]
<canvas id="canvas_id" width="canvas_width" height="canvas_height" onMouseMove="mouseCon(event);" style="cursor:none;"> where canvas_id, canvas_width and canvas_height are your preferred settings. The style attribute hides the mouse pointer should you want to add a custom pointer in the demo, such as a cross-hair :)

Next in your JavaScript code, create these variables:
Code: [Select]
var keyboard = new Array();
var mouseX = 400, mouseY = 300;
// Firefox Check
var ffx = false;
var cnvsX = 0, cnvsY = 0;

Then add this code which should run only once before the main program function:
Code: [Select]
// If the browser is Firefox, locate the canvas position in the document
if(navigator.userAgent.indexOf("Firefox") > -1){
ffx = true;
cnvsX = c.offsetLeft;
cnvsY = c.offsetTop;
}
// Reset the keyboard
for(i = 0; i < 256; i++){
keyboard[i] = 0;
}
Also add these functions:
Code: [Select]
// Keyboard Controls
var control = function(et, evt){
if(ffx){
event = evt;
}
keyboard[event.keyCode] = et;
}

// Mouse Movement Control
var mouseCon = function(evt){
if(ffx){
event = evt;
mouseX = event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft - cnvsX;
mouseY = event.clientY + document.body.scrollTop + document.documentElement.scrollTop - cnvsY;
}else{
mouseX = event.offsetX;
mouseY = event.offsetY;
}
}

With each key press (or release), the keyboard array entries will be set to either 0 or 1. The following page contains a list of common key codes - these codes match with the addresses in the keyboard array: http://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

Please let me know if I have missed something or designed something which is horribly inefficient.
You are our 9001st visitor.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #12 on: January 12, 2014 »
wow thanks for that ck!!

in the raycasting demo i posted above i used a different method for keystrokes. i went with a

c.addEventListener( "keydown", DoKeyDown, true);
c.setAttribute('tabindex','0');

which gives my canvas focus and invokes the DoKeyDown function.

but i like your way.. it's far more like i am used too. and also the tips for the mouse/crosshair will be invaluable :cheers:
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #13 on: January 12, 2014 »
k++ on that raycaster - it looks brilliantly retro! I've got an idea or two for it as well.

I'm glad you like my input functions. The keyboard function can handle multiple keys being pressed simultaneously, up to 4 on most systems.
You are our 9001st visitor.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #14 on: January 13, 2014 »
thanks ck.

this was just something too dip my toes in the water. it's actually towards a first person pacman ive always wanted too do. i really wanted too do textures/floor and seiling casting but i dont think that would be possible in its current position. next up im going too try and do this in webgl and sample the textures in shaders. too do it all properly.

what ideas did you have for it? cheers..
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #15 on: January 13, 2014 »
There was a game called Combat for the Atari 2600 - these graphics are just right for a 3D version of it!
You are our 9001st visitor.
Challenge Trophies Won:

Offline Gore Motel

  • C= 64
  • **
  • Posts: 45
  • Karma: 18
    • View Profile
    • Gore Motel
Re: just starting out in java/html
« Reply #16 on: January 13, 2014 »
For animations you might want to consider requestAnimationFrame (and use setInterval as a fallback for older browsers).

requestAnimationFrame will try to match the display's refresh rate, and will fire less frequently when the browser window/tab is minimized (or in the background).

More about it from Mozilla and creativeJS.

Offline Yaloopy

  • Death From Above
  • DBF Aficionado
  • ******
  • Posts: 2875
  • Karma: 35
    • View Profile
    • UltraPaste
Re: just starting out in java/html
« Reply #17 on: January 13, 2014 »
Quote
so it is possible to use intellisense
Yes, autocomplete, go to definition across multiple files etc. all work if you use VS as your editor.

I've been using VS2010 for some web stuff but some CSS(3?) commands just don't register with it. rgba(...) for example just gets lost. I've no internet connection at home so maybe I'm just missing an update.

Brackets looks great, giving it a download now.
Fuck L. Ron Hubbard and fuck all his clones.
Challenge Trophies Won:

Offline ninogenio

  • Pentium
  • *****
  • Posts: 1668
  • Karma: 133
    • View Profile
Re: just starting out in java/html
« Reply #18 on: January 13, 2014 »
There was a game called Combat for the Atari 2600 - these graphics are just right for a 3D version of it!

ahh i know the one ck! me and my cousin used too end up rolling around the floor fighting over that one  ;D.. yes i can actually see that working with this basic raycasting really really nicely. you could have a direct port of the game running in the hud and just ray cast everything too the left, that would be really cool  8)

i have been wanting too do a pacman with a spin for a while and i got the idea a few days ago too try a raycasted version.

For animations you might want to consider requestAnimationFrame (and use setInterval as a fallback for older browsers).

requestAnimationFrame will try to match the display's refresh rate, and will fire less frequently when the browser window/tab is minimized (or in the background).

More about it from Mozilla and creativeJS.

ahh another top tip there gore motel! thanks very much i will look deeper into this thanks very much!


Quote
so it is possible to use intellisense
Yes, autocomplete, go to definition across multiple files etc. all work if you use VS as your editor.

I've been using VS2010 for some web stuff but some CSS(3?) commands just don't register with it. rgba(...) for example just gets lost. I've no internet connection at home so maybe I'm just missing an update.

Brackets looks great, giving it a download now.

i coded the last half of that little project with brackets and its very very good, it actually does intellisense and so far i never had any issues using it. another plus is that its really lightweight and doesn't take precious resources etc
Challenge Trophies Won:

Offline combatking0

  • JavaScript lives!
  • Senior Member
  • DBF Aficionado
  • ********
  • Posts: 4569
  • Karma: 235
  • Retroman!
    • View Profile
    • Combat King's Barcode Battler Home
Re: just starting out in java/html
« Reply #19 on: January 13, 2014 »
I've hosted my adaptation of your raycaster at http://fx.barcodebattler.co.uk/waveSphere/jsraycaster.htm with support for multiple key control.

I'll be making changes to it to support a floor and possibly a sky when I figure out how it works.
You are our 9001st visitor.
Challenge Trophies Won: