[web] Help with my game

Started by
7 comments, last by markr 18 years ago
Hello gamdev, I am trying to fix my game to be compatible with firefox. I am just &#106avascript. I know I could use other things but its a really simple game with not really good graphics. It works just fine in IE but in Firefox or Mozilla when you press the space bar to jump in moves the webpage down and messes up the screen. Here is a link so you can see the problem. Link My guess it that it is writting some html down there, becuase on the main menu it doesn't do that. To create my sprites I am using this java script.

this.obj = document.createElement("IMG");
document.getElementsByTagName("body").item(0).appendChild(this.obj);


There might be some unexplained html somwhere else that I cannot find. Well my question to you isn't to fix it but is there a way that I can disable the page going down like that or what would cause that? Thanks for your help. **** EDIT **** - I have put a window.scroll(0,0); in there to debug the rest of the game. I know its a hacky way to do it. Is there anything else I can do? [Edited by - cptrnet on April 19, 2006 1:30:35 PM]
If you insist on saying "DUH", try to make a post that makes a little more sense
Advertisement
You also have a problem with your messageboxes at gameover. They loop between Gameover and You died!. I used Firefox to play the game.
bi-FreeSoftware
Yeah I know there are a ton of problems with the firefox version that I need to work out, this is just the main one because no one can play it with the screen jumping like that.
If you insist on saying "DUH", try to make a post that makes a little more sense
Does anyone have any ideas?
If you insist on saying "DUH", try to make a post that makes a little more sense
Basically what's probably happening is that the keyboard event from the spacebar has some default action - scrolling the page down.

In order to use the spacebar usefully for something else, you need to block the default action of that event.

The normal way to do this is by calling event.preventDefault() - which is the DOM events thing (As ever, MSIE has a completely different way of doing this).

Mark
on w3 it says that the scroll event is not cancelable in which it gives a defintion of that saying you cannot cancel the event. Maybe I am misinterpreting this becuase I cannot find any real examples of canceling the scroll event or preventing the default. All my searches in google have come up with nothing. Maybe its because I really don't know what I am looking for. Can anyone help me with the preventDefault() function?
If you insist on saying "DUH", try to make a post that makes a little more sense
Just a suggestion, wouldn't it be easier to change the jump key to a different key? Shift for example?
Progress is born from the opportunity to make mistakes.

My prize winning Connect 4 AI looks one move ahead, can you beat it? @nickstadb
That would be such a pain to push shift. Space bar is huge and for fast reactions I think it would better to hit a bigger key than a smaller one. Besides I ran into another problem when you hit the down arrow key, not that theres any functionality there but what if someone hits it. I just can't change keys because the problem will still be there.
If you insist on saying "DUH", try to make a post that makes a little more sense
The scroll event may not be cancellable, but the key press event should be. If you cancel the keyboard event, it won't then generate a scroll request.

I am pretty sure I've done this before, so either

- Mozilla allows the event to be cancelled anyway, shunning the W3 spec
OR
- The keyboard event is cancellable.

Mark

This topic is closed to new replies.

Advertisement