
madmenyo
Members-
Posts
38 -
Joined
-
Last visited
Never
Everything posted by madmenyo
-
I fixed it by calling the function game() everytime a down key is pressed. But, it still does not work in firefox.... i tested it in IE 7, opera and firefox. whats different about FF?
-
whoops, fixed that but that probably happened after i started to get stressed and started testing stuff out to make it work. It still does not work, i edit the script above -edit- errrr.... i can't
-
Hey I'm creating my first game. I am proud to say i just made a script that moves a square with the arrow keys OMG . But just as i thought i'm starting to understand javascript a problem occurs. When everything worked i wanted to add the function game() but that just does not change the background when i have squareman below that 350 or lower... Heres the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <head> <title>Super squareman</title> <style> #gamebox { margin:auto; border: 1px solid black; width:512px; height:512px; background-color: rgb(192,192,192); } #squareman { position:relative; top: 240px; left: 240px; width:32px; height:32px; background-color:#900; border: 1px solid black; } </style> <script language="javascript"> //instance squareman var squareman; var timer; var squaremanTop = 240; var squaremanLeft = 240; function init() { squareman = document.getElementById('squareman'); document.onkeydown = keyListener; game() } //key detection function function keyListener(e) { if(!e) { e = window.event; } if (e.keyCode==37 && squaremanLeft > 0) { squaremanLeft -= 4; squareman.style.left = squaremanLeft + 'px'; } if (e.keyCode==39 && squaremanLeft < 480) { squaremanLeft += 4; squareman.style.left = squaremanLeft + 'px'; } if (e.keyCode==38 && squaremanTop > 0) { squaremanTop -= 4; squareman.style.top = squaremanTop + 'px'; } if (e.keyCode==40 && squaremanTop < 480) { squaremanTop += 4; squareman.style.top = squaremanTop + 'px'; } } function game() { if (squaremanTop < 350) { gamebox.style.backgroundColor = 'rgb(128,0,0)'; squareman.style.backgroundColor = 'rgb(0,128,0)'; } } </script> </head> <body onload="init()"> <div id="gamebox"> <div id="squareman"> </div> </div> </body> </html>
-
It seems i have solved it. window.onload = renderTileMap(tileMap, images, 5, 5, 32, 32); //last line of the script If i delete this and put a onload in the body element it DOES show the map i have drawn. <BODY onLoad="renderTileMap(tileMap,images,5,5,32,32)"> Whats the difference between the 2? why won't my images get loaded with the javascript and they do if i put the function in the body? Does this have consequences in the future for when i want to make a character move or have the window only show 3*3 images? Or for anything else related to further build with this script?
-
It might have been that, i have been messing around with some stuff and it miraculously fixed it.... not the most genius way to fix something but it will do for now .
-
Hey, I am totally new to javascript and i want to create a interactive map for my PHP game. Obviously i will not be able to just code it instantly so i wanna do this step by step and first let java draw a map from an Array for me. Unfortunately but expected i can't even pull this off . Firebug gives me (error: parentDiv is null) stated in the function addImage this function gets called by another function renderTileMap div parent stated in this function should feed the attribute. Mind, i rewritten the code from another another file that has a simple tile map and lets a player move a character. I have looked thorugh the whole code for things i forgot to include but can't find anything. Offcourse i did include the open.jp and wall.jpg. Am i close? Or am i totally off with this and should i start javascript with something more easy? -EDIT-Error: parentDiv is null Source File: file:///C:/xampp/htdocs/projects/java/myfirstmap/tilemap.html Line: 31 <html> <title>My first tile map</title> <head> <script language="JavaScript"> function addImage(parentDiv, elementName, filename, x, y, height, width) { elementName = document.createElement("img"); elementName.src = filename; elementName.style.position = 'absolute'; elementName.style.left = x + 'px'; elementName.style.top = y + 'px'; elementName.style.width = width + 'px'; elementName.style.height = height + 'px'; elementName.style.right = x + width + 'px'; elementName.style.bottom = y + height + 'px'; parentDiv.appendChild(elementName); } tileMap = [ [1 ,1 ,1 ,1 ,1], [1 ,0 ,0 ,0 ,1], [1, 0, 0, 0, 1], [1, 0, 0, 0, 1], [1, 1 ,1 ,1 ,1], ]; images = new Array(); images[0] = "open.jpg"; images[1] = "wall.jpg"; function renderTileMap(tileMap, tiles, width, height, tileWidth, tileHeight) { var divParent = document.getElementById('ParentImage'); for(y = 0; y < height; y++) //Loop Height for(x = 0; x < width; x++) //Loop Width { addImage(divParent, tiles[y * width + x], images[tileMap[y][x]], x * tileWidth, y * tileHeight, tileWidth, tileHeight); } } window.onload = renderTileMap(tileMap, images, 5, 5, 32, 32); </SCRIPT> </HEAD> <BODY> <DIV ID="ParentImage"></DIV> </BODY> </HTML>
-
seems more of a error in the design phase? I mean if you have a fixed total widt like 576px it's not really possible to add 3 columns with 192px width and padding . Otherwise, make cells 204px width with 12 px 1 side padding they become 192px... or i don't get what your asking .
-
I think you need to make that left div to float:left; then another div for the content. and put those divs inside a div that stays below the top div. <div top> </div> < div middle> <div left> <--- float this to left </div <div content> <---- you can float this left too. </div> </div> <bottem> </div>
-
Yeah, Like i said the PHP file is even displaying other styles from the same CSS sheet where the body style is in. But it just displays a white body. In dreamweaver i actually get the body color to change if i put it on design view..... but it just won't work in firefox (the only browser i have , yeah need others but screw IE i boycot that ).
-
I just like to add you can design a site in let's say photoshop then cut it to pieces and assemble it again in div's. Do this partly or for your whole website, your choice. This way you can create all kind of these effects, the sky is actually the limit.
-
Hey guys, For starters i have this in the head of my HTML inside my .PHP file. <link href="styles.css" rel="stylesheet" type="text/css" /> I already have done some CSS work in the styles.css like some divs that function like tables. These work perfectly. The problem is when i add this to the styles.css : body { background-color: black; } It won't work in my PHP file. If i embed the style inside the body element like this it does work.... : <body style="background-color: black;"> </body> Obviously i want it to work inside my CSS file. What can be the source of the problem? Tx!
-
I actually had to reverse $slotcounter and $weaponrows for it to work, i don't know why but it works like it should. i speneded like 2 hours on this The bracket is from another statement, i shouldn't have included that in the code sorry,
-
Hey, for each loop $slotcounter returns me "4" .... wich is weird because i do get 4 buttons displayed. print $_POST['wslot']; return only slot4 to mo wichever button i click. I need it to be button 1,2,3,4 <?php if (isset($_POST['useweapon'])) { print $_POST['useweapon']; echo "</br>"; print $_POST['wslot']; } } ?> <form action="" method="post"> <?php $slotcounter = 1; //while ($slotcount['weaponslots'] >= $slotcounter) while ($slotcounter <= 4) { ?> <input type="hidden" value="slot<?php echo $slotcounter;?>" name="wslot"> <INPUT TYPE="image" SRC="images/slot<?php echo $slotcounter;?>.jpg" HEIGHT="11" WIDTH="11" BORDER=0 ALT="^" name="useweapon" value="<?php echo $weaponrows['weaponID'];?>"> <?php $slotcounter++; } ?> </form>