처음에는 내 질문의 투표를보기가 약간 실망했습니다. Stackoverflow는 새로운 사람들이 여기에 코드를 작성하려고 할 때 많은 문제가 있다고 생각할 수 있습니다.하지만 그건 내가 묻는 것이 아닙니다.
어쨌든 "문제를 공유하면 솔루션을 공유합니다"라고 생각하면 tw_hoff의 도움으로 코드가 수정되어 이제는 모두 작동합니다. 로컬 스토리지에 좌표를 저장하기 때문에 페이지를 새로 고치면이 예제 HTML이 같은 위치에있게됩니다. 나는 두 개의 예제 이미지를 추가했다. (왼쪽 하나는 farm.png, 오른쪽은 tile.png, html 페이지와 같은 디렉토리에 저장한다.)


실제 코드 :
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Game map demo</title>
<style>
body { margin: 0; padding: 0; }
</style>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<div id="map" style="position: absolute; overflow: hidden; width: 100%; height: 100%; background-color: darkgreen;">
<div id="content" style="white-space: nowrap;">
</div>
</div>
<script>
for(i = 0; i < 20; i++) {
for(j = 0; j < 20; j++) {
var tile;
if((i == 4 || i == 5) && (j == 2 || j == 3)) {
tile = 'farm';
} else {
tile = 'tile';
}
$("#content").append('<div style="background: url(\'' + tile + '.png\'); width: 128px; height: 128px; position: absolute; margin-left: ' + (i * 128) + 'px; margin-top: ' + (j * 128) + 'px;"></div>');
}
}
$("body").css("-webkit-user-select","none");
$("body").css("-moz-user-select","none");
$("body").css("-ms-user-select","none");
$("body").css("-o-user-select","none");
$("body").css("user-select","none");
var down = false;
var current_left = 0;
var current_top = 0;
if(localStorage.getItem("current_left") && localStorage.getItem("current_top")) {
current_left = Number(localStorage.getItem("current_left"));
current_top = Number(localStorage.getItem("current_top"));
console.log(current_left);
$("#content").css('marginLeft', (current_left) + 'px');
$("#content").css('marginTop', (current_top) + 'px');
}
$(document).mousedown(function() {
down = true;
}).mouseup(function() {
down = false;
});
var cache_pageX;
var cache_pageY;
$("#map").mousemove(function(event) {
if(down == true) {
current_left += (-1 * (cache_pageX - event.pageX));
if(current_left > 0)
current_left = 0;
if(current_left < (-2560 + $("#map").width()))
current_left = (-2560 + $("#map").width());
current_top += (-1 * (cache_pageY - event.pageY));
if(current_top > 0)
current_top = 0;
if(current_top < (-2560 + $("#map").height()))
current_top = (-2560 + $("#map").height());
localStorage.setItem("current_left", current_left);
localStorage.setItem("current_top", current_top);
$("#content").css('marginLeft', (current_left) + 'px');
$("#content").css('marginTop', (current_top) + 'px');
}
cache_pageX = event.pageX;
cache_pageY = event.pageY;
});
</script>
</body>
</html>
, 그것은 여전히 몇 가지 작업을 필요로하고 작업 물론 많은 실제로 게임에서 사용할 수 있지만이 부분 작품과 나는 경우 희망 다른 사람이 이제까지 같은 문제가있을 수 있습니다 stackoverflow 내 솔루션에 대한 그들에게 올바른 방향으로 밀어 준다 :).
도움을 주신 분께 감사드립니다.
샘플 코드가 없으면 도움이되지 않습니다. – Oen44
코드는 없으므로 실제로는 코드 샘플이 없습니다. 나는 작동 할 수있는 개념을 찾으려고 노력하고있다. 그런 다음 코드를 작성할 것이다. (필자는 누군가 내 코드를 작성하지 않을 것이라고 기대한다.) 나는 어디서부터 시작해야하는지 전혀 모른다. –
이 질문은 스택 오버플로에 너무 광범위하다고 생각합니다. 일반적으로 당신은 당신 자신이 뭔가를 시도하고 붙어있을 때 특정한 질문을해야합니다 ... – Badacadabra