ShadyCoco Posted October 2, 2011 Posted October 2, 2011 Hey, I'm using a tile based game engine writen in PHP,mysql, java (small amount) and I really want to add keyboard movement along side pressing buttons (on screen) to move. Any ideas on what language I should use to do it? Quote
Dave Posted October 2, 2011 Posted October 2, 2011 Hey, I'm using a tile based game engine writen in PHP,mysql, java (small amount) and I really want to add keyboard movement along side pressing buttons (on screen) to move. Any ideas on what language I should use to do it? You wanna use javascript and just capture which key is hit then run the function. Quote
Danny696 Posted October 2, 2011 Posted October 2, 2011 Well, daves answered it, but may I ask why are you using PHP, MySQL and Java? Quote
ShadyCoco Posted October 2, 2011 Author Posted October 2, 2011 It's a really old engine :/ Trying to bring it to the new ages :) Quote
Danny696 Posted October 2, 2011 Posted October 2, 2011 Wouldnt it be easier to make it all in Java then? Quote
Dave Posted October 2, 2011 Posted October 2, 2011 It's a really old engine :/ Trying to bring it to the new ages :) Do you by any chance mean Javascript? Cause Java is a completely different language. Quote
ShadyCoco Posted October 2, 2011 Author Posted October 2, 2011 Yeah sorry haven't had much sleep :S **javascript** Quote
ShadyCoco Posted October 4, 2011 Author Posted October 4, 2011 I', using this but it don't seem to be collecting it. function getkey(e) { if (window.event) return window.event.keyCode; else if (e) return e.which; else return null; } function redir(key) { var rkey = getkey(key); if(rkey == 119) { document.location.href="index.php?x=200&y=100"; } if(rkey == 115) { document.location.href="index.php?x=200&y=200"; } if(rkey == 97) { document.location.href="index.php?x=150&y=150"; } if(rkey == 100) { document.location.href="index.php?x=250&y=150"; } } Quote
Joel Posted October 4, 2011 Posted October 4, 2011 Why not create a div and then move it using something like: var speed = 4; document.getElementById('THE_ID_OF_THE_DIV').style.top += speed; Quote
Djkanna Posted October 4, 2011 Posted October 4, 2011 (edited) If your using the jQuery library, you may have better luck using the jKey plugin Then you do something like (portion taken from their samples page): [js] $(document).jKey('up, left, down, right, up+right, up+left, down+right, down+left', function (key) { //Current location is y = 2 x = 2 if (key == 'up') { player.location = 'n:3,2'; // North, y =3, x =2 } else if (key == 'down') { player.location = 's:1,2'; // South y = 1, x = 2 } else if (key == 'left') { player.location = 'w:2,1'; // West y = 2, x = 1 } else if (key == 'right') { player.location = 'e:2,3'; // East y = 2, x = 3 } else if (key == 'up+right') { player.location = 'ne:3,3'; // N'East y=3, x = 3 } //So on and so forth. }); [/js] for example. Urgh didn't see your previous code Shady, would have saved me thinking of an appropriate value for the updated location. T.T Edited October 4, 2011 by Djkanna Quote
ShadyCoco Posted October 5, 2011 Author Posted October 5, 2011 you always give good answers kanna thanks <3 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.