views:

99

answers:

4

What is the best cross-browser way to get a flat mouse coordinate input data and simple callback for mouse events for my rectangular game area on my web page, even when it has loads of larger and smaller images and text string overlaid haphazard onto it?

And what is the best way to insert or remove a text string or semi-transparent image overlay at an arbitrary location (and Z order, specified relative to existing objects) in a board game rectangle with cross-browser DHTML?

And how can I stop the user selecting part or all of my montage of images (I just want them to interact with it as if it was Flash), and can I stop the right click menus coming up in IE, FF etc?

I want to do this without Flash because I want something that will work both on desktops and on iPhone and potentially other mobile platforms too.

I appreciate there are serious limitations (eg less image scaling capabilities, not vector, no rotation capability) to what I can do if I'm not using Flash but I'm very interested to know what capabilities are available.

Are there perhaps any frameworks available to make it easier than coding from scratch?

Would J/Query be a good match for some of the requirements? What else do I need?

+3  A: 

jQuery is excellent at doing this. I used jQuery's UI and Ajax functionality to implement the frontend for a game of chess.

I made it a little easier by creating an 8-by-8 table with unique div names for each tile, so Javascript can access them by getting the elements by id. If you can't create something like that, you do have the option of placing elements anywhere on the page (either absolute or relative to a given element). You can also easily change the z-index, including when the use is dragging a piece or when they have dropped it.

As far as disable right click and item selection goes, that's something that I didn't figure out how to do. You might want to take a look at some other Ajax games like Grand Strategy, which are much more polished than my experiment and may have figured out how to do this.

Kaleb Brasee
Thanks for the info. I've got started building a proof-of-concept on shared hosting.
martinr
+3  A: 

I would recommend Google Web Toolkit. It lets you program in Java, which gives you all the type-safety and nice IDE functionality that Java entails, but compiles to Javascript so that you can just run it in a browser. It also does a ton of optimization and supports tons of features.

Travis Gockel
This is very interesting as well, I might use it if I add multiplayer, but I can only select one answer as correct.
martinr
+2  A: 

There are two main APIs for working with arbitrary drawing and positioning on the web, Canvas and SVG.

Take a look at Chrome Canvas Experiments and the Raphael Javascript toolkit to see some examples and Javascript abstractions.

Michael Greene
Interesting. It is not clear whether Raphael supports Android/iPhone but these platforms have <canvas> tags so I'll hack Raphael up a bit to make a library for desktops/mobiles plus (for my limited requirements set) add fallback to standard DHTML when required. Thank you Michael.
martinr
+1  A: 

The key is element.style.position = 'absolute'. To illustrate just what's possible here's how far I've managed to push javascript (and from scratch at that!):

slebetman