Showing posts with label js. Show all posts
Showing posts with label js. Show all posts

Wednesday, 23 March 2011

Sunday, 21 November 2010

JS Game programming main loop

Use this piece of JS to repeatedly call update() method every 10ms.

Handy for game loops!

setInterval(update, 10);


http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/

Full breakout game guide with keypress, mouse & animation

Saturday, 25 September 2010

Javascript Color Looping

If you find yourself looping thru JS code to tweak the color settings:

// Sets myColor to be the Hex AA + a sample integer
var myColor= 0xAA + parseInt(20)

// toString(16) turns a decimal int into a Hex value.
var colorToUse = myColor.toString(16)

Saturday, 7 November 2009

Javascript inserting nodes

Remember when using the 'insertBefore' method that the node you **think** is the parent isn't necessarily the parent.


<h1 id='header'>
  <p id='beforeMe' />
</h1>


So dont do :

header = document.getElementById('header');
beforeMe = document.getElementById('beforeMe');
header.insertBefore(newNode, beforeMe );


Instead do this:

beforeMe = document.getElementById('beforeMe');
beforeMe.parentNode.insertBefore(newNode, beforeMe );

Wednesday, 19 August 2009

JS - Get object which called this method

Sample HTML + JS.

JS gets the tag which originally called the JS method. It can then read the value on the original 'input' tag


<html>
<head>
<script>
  function flipFormTarget(e) {
    alert(e.value)
    document.getElementById('old-form').setAttribute('action', e.value);

  }
</script>
</head>
<body>
<br><input type = 'radio'  value = 'top one' onclick="flipFormTarget(this)" checked>top option
<br><input type = 'radio'  value = 'bottom one' onclick="flipFormTarget(this)"> bottom
</body>
</html>