OZONE Asylum
Forums
DHTML/Javascript
20 Liners - January 08 - Dynamics
This page's ID:
29836
Search
QuickChanges
Forums
FAQ
Archives
Register
Edit Post
Who can edit a post?
The poster and administrators may edit a post. The poster can only edit it for a short while after the initial post.
Your User Name:
Your Password:
Login Options:
Remember Me On This Computer
Your Text:
Insert Slimies »
Insert UBB Code »
Close
Last Tag
|
All Tags
UBB Help
Nice. One more way to cut down lines in event handling is to use the || operator to provide a fallback/default value, e.g:[code]var x = Math.round(Math.random()*540)+50; if (e.pageX) x = e.pageX; var y = Math.round(Math.random()*380)+50; if (e.pageY) y = e.pageY;[/code]becomes[code]var x = (e||{}).pageX||Math.round(Math.random()*540)+50; var y = (e||{}).pageY||Math.round(Math.random()*380)+50;[/code]Notice the [i](e||{})[/i] which fixes the JS error of trying to access a property of [i]e[/i] when [i]shoot()[/i] is called by the setInterval() Also instead of clearing the explosion manually, you could constantly do a [i]fillRect(0,0,540,480)[/i] in [i]rgba(0,0,0,.2)[/i] for instance. Hope that helps, [url=http://www.p01.org/][img]http://poi.ribbon.free.fr/files/p01_ozoneasylum_sig_dk.gif[/img][/url] [small](Edited by [url=http://www.ozoneasylum.com/user/2185]poi[/url] on 01-08-2008 00:35)[/small]
Loading...
Options:
Enable Slimies
Enable Linkwords
« Backwards
—
Onwards »