Click to See Complete Forum and Search --> : javascript game code rework
kgrimm3678
04-18-2005, 04:01 PM
I am working on a game for our community festival webiste at http://lafayetteapplefest.org/games/chase/index.html and I am trying to reconfigure it to be reflective of our apple theme. I found a script at http://javascript.internet.com/games/buzzy---the-reflex-tester.html which I am trying to change. The game is configured to select between background colors. I would like to select between images so that the images can be red or green apples instead of a red or yellowgreen background. They use
if(objBox.backgroundColor == "yellowgreen")
{
document.buzzy.txtScore.value = eval(document.buzzy.txtScore.value) + 1;
}
else
{
wrongClicks = wrongClicks + 1;
objBox.backgroundColor = "red";
setTimeout('objBox.backgroundColor = "white"',200);
Couldn't I do the same thing with images? How do I rework the script to select images instead of background? So far I've only managed to change the background colors on my page.
Thanks!
Karen
Ultimater
04-18-2005, 04:10 PM
The first rule in JavScript is to never use the fuction eval!
Replace that eval function call with a parseFloat function call.
Also setTimeout('objBox.backgroundColor = "white"',200); won't work unless objBox is a gobal varible. I assume that objBox is a gobal varible set to an element with .style included for non NS browsers.
phpnovice
04-18-2005, 07:48 PM
The first rule in JavScript is to never use the fuction eval!
Well, I wouldn't say "never" -- just don't use it until you know when and how to use it properly. ;)
...definitely don't use it when it is not required.
kgrimm3678
04-18-2005, 09:48 PM
Okay but my question still stands. How do I get the image property to change instead of the background property. I didn't write the script. I'm just trying to customize it. There's alot more code. I just didn't think you wanted to see the whole thing. I need to know how to change the objBox.backgroundColor to say something like objBox.image= "apple.gif"',200); or something else ????
Karen
if(objBox.backgroundColor == "yellowgreen")
{
document.buzzy.txtScore.value = parseFloat(document.buzzy.txtScore.value) + 1;
}
else
{
wrongClicks = wrongClicks + 1;
objBox.backgroundColor = "red";
setTimeout('objBox.backgroundColor = "white"',200);
Ultimater
04-18-2005, 09:52 PM
objBox.background="url(apple.gif)"
phpnovice
04-18-2005, 10:39 PM
If you want to change just the background image:
object.style.backgroundImage = "url(apple.gif)";
otherwise:
object.style.background = "color url(apple.gif) repeat attachment position";
kgrimm3678
04-18-2005, 11:05 PM
Yup, that worked! Hooray!!! I used the url(apple.gif) option and that seems to work just fine. Thanks! I really appreciate your quick response.
There are still a couple things I don't understand about the script I am working on. I would rather a smiley face when they responded quickly enough instead of a mad face if they are too slow. So I will work on finding that part. I would also like to take off the "Are you ready to start" popup box option and just have the start button control the action. But it's way past my snooze time and I can't see straight anymore. But if you have any additional suggestions or comments, I would love to hear what you have to say.
http://lafayetteapplefest.org/games/chase/index.html
Thanks again!
Karen