Author Topic: Game Design Megathread  (Read 357654 times)

Can you not just say "var getID = document.getElementById"?

https://dl.dropboxusercontent.com/u/8406402/Experimental/runtime.html
heres a text thing i did but never finished or worked on more.

and no Kingdaro, you need to include the ID

code
you're gonna get some syntax errors if you use that code!
but for real though that's still a mess. jQuery is miles better

like look at this
document.getElementsByTagName("p").style.color = "blue";
that doesn't make every p element blue. it just results in an error
notably:
document.getElementsByTagName("p");
does not return any elements. just "[]" for some reason
I don't even know how to solve that

although, apparently, the same thing happens with jquery. dunno what's up with that but at least it's still easier to achieve "[]"
all you gotta type is $("p"); to get the same result

SUPER FIGHTING ROBOT

CAMERA



Appliance Masters coming up

you're gonna get some syntax errors if you use that code!
but for real though that's still a mess. jQuery is miles better

like look at this
document.getElementsByTagName("p").style.color = "blue";
that doesn't make every p element blue. it just results in an error
notably:
document.getElementsByTagName("p");
does not return any elements. just "[]" for some reason
I don't even know how to solve that

although, apparently, the same thing happens with jquery. dunno what's up with that but at least it's still easier to achieve "[]"
all you gotta type is $("p"); to get the same result

Because ElementsByTagName and ElementsByClassName return arrays. To get the first, you'd use
Code: [Select]
document.getElementsByTagName('p')[0].style.color = "blue";

To apply it to all, you'd use a for loop.
Code: [Select]
var tags = document.getElementsByTagName('p');
for(i = 0; i < tags.length; i++) {
   tags[i].style.color = "blue";
}

Yeah I know it's long, which is one of the reasons why jQuery was made, but having to load up jQuery for small tasks is much slower.
Also it might return [] if there's no p tags. This'll happen if the script is before the element in HTML because the script is ran before the elements are created. Add the script to the end of the page or use
Code: [Select]
window.onload = function() {
   code;
};

i think it goes this way for jQuery
Code: [Select]
$(document).ready({
   code;
});

Because ElementsByTagName and ElementsByClassName return arrays.
jesus christ
idk why this stuff never occurs to me until it's too late
I mean that's so simple

Does anyone here know C++?


and no Kingdaro, you need to include the ID
I figured out why it doesn't work, and this isn't why. It's because simply setting the variable to another function won't give the new function the correct binding to this. For that, you would use .bind() to make sure the correct this is used, which in this case is document. This is the shortest way I know of to shorten the document functions:


var byId = document.getElementById.bind(document)
var byClass = document.getElementsByClassNa me.bind(document)
var byTag = document.getElementsByTagName .bind(document)

I figured out why it doesn't work, and this isn't why. It's because simply setting the variable to another function won't give the new function the correct binding to this. For that, you would use .bind() to make sure the correct this is used, which in this case is document. This is the shortest way I know of to shorten the document functions:


var byId = document.getElementById.bind(document)
var byClass = document.getElementsByClassNa me.bind(document)
var byTag = document.getElementsByTagName .bind(document)

oh you were referring to that.

yeah javascript = is litterally what it means
you can stuff anything into a variable.
you can pass a function into another function and have a third function nested in that first one ()
i suppose being able to store anything into a variable is both cool and sort of a hinderance.


I finally got shadow maps working in my game engine :D
https://www.youtube.com/watch?v=h7j0r84JhFc



make the shadows higher res
If I did that I'd need to change the shader code also to not look so bad.


I'll make optimizations and improvements later, I'm just happy I got it working.