hi i working on my mmo game and i added map to game but i want players can browse map by drag
any one have idea or source code?
Printable View
hi i working on my mmo game and i added map to game but i want players can browse map by drag
any one have idea or source code?
You can use the mousedown, mousemove and mouseup events to detect dragging. Here's a simple dragging example:
Code:<style>
#map { background-color: red; cursor: move; position: absolute; width: 100px; height: 100px; }
</style>
<div id="map">Map</div>
<script>
var isDraggingMap = false;
function mapDragStartHandler(event) {
isDraggingMap = true;
return mapDragMoveHandler(event);
}
function mapDragMoveHandler(event) {
if (isDraggingMap) {
var map = document.getElementById('map');
map.style.left = (event.pageX-50)+'px';
map.style.top = (event.pageY-50)+'px';
return false;
}
}
function mapDragEndHandler(event) {
if (isDraggingMap) {
isDraggingMap = false;
return false;
}
}
document.getElementById('map').addEventListener('mousedown', mapDragStartHandler);
document.addEventListener('mousemove', mapDragMoveHandler);
document.addEventListener('mouseup', mapDragEndHandler);
</script>
thank you very much i don't know whats i must say for thank you
but i think you have error in this example code don't work
ihope you can add more example for help me thank you
The example I posted works perfectly in both Google Chrome and Firefox. If you're using an older version of IE you'll have to use attachEvent instead of addEventListener.
(Also note that I've omitted obvious html tags such as doctype, <html> and <body>. Maybe that's causing problems for you if you just copied and pasted the code.)
ok error come from IE its work good with firefox thank you again