Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Images change on key pressed

    Hi everyone!
    I'm trying to make a simple small game in JavaScript. It's a character that runs around climbing and descending on ladders which is in fact a .gif that changes position when I press the arrows. I've already did this and now I need to put in other characters with which the main character should interact. The problem is that the script doesn't insert more than one picture at the same time, so it shows only the last image declared. The script works fine for the characters put in individually as you can see in these two examples http://www.d.a.n.s.home.ro/test/anim...nimaniac2.html , http://www.d.a.n.s.home.ro/test/anim...animaniac.html (where there is no edge press the down arrow to continue). Can anyone please help and tell me how to change more than one image in the same HTML on key-pressed? It's a HTML file that calls upon a .js file. I know the game isn't something grate, it's more for my practice, plus it's just at it's beginnings so I hope I woun't get lots of bad critics . Thanks a lot!

  • #2
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    where's the script with them both together? post it and I'll take a look.

    sounds like you need to make an array to hold the various characters and then do the image swapping for each element in that array.

    var chars=new Array()
    chars[0]=man
    chars[1]=dog

    when you get to the swapping

    for (num=0,num<chars.length;num++){(your function to switch image for character) num}


    post what you got. Good job so far. You should have no problem. Next you have to make some enemies.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the nice thoughts, TinyScript! The script, being a little longer, I'll give you the link to where it is, Firefox will automatically open it as text, IE will ask you to download it: http://www.d.a.n.s.home.ro/test/animaniac/script.js. Here's the HTML file :

    <html>

    <head>
    <title>Animaniac</title>
    <script type="text/javascript" SRC="script.js" ></script>
    <link rel="stylesheet" type="text/css" href="style.css"/>
    </head>

    <body onload="frames(event);" onkeypress="frames(event);" id="pageBody">
    </body>

    </html>

    That's it. Nice and small, only the script is long having lots of IFs, what picture to put in the current coordinates.
    One more thing, making an "educated" guess I found out what I was doing wrong: I was getting the content of the HTML page and passing it a photo, thus canceling everything I've put there before, realizing that instead of inserting each photo individually I have to concatenate them (since the insertion is made through a string) and insert all of them through the same line. Now it works just fine and you can see it on the page animaniac.html from my last post. Here's the link to the mistaken script, so you can easier understand the problem and how I've fixed it: http://www.d.a.n.s.home.ro/test/animaniac/script2.js. Thanks for everything! The game will most probably get an update everyday and it will remain on the same page, animaniac.html, if you'll be interested in it. Probably I will ask you for help again


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •