Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Setting Offset of Draggable DIV
- offset.left = Math.round((my.x*tile.width)-(screen.width/2));
- if((my.y % 2) == 0){
- offset.left = Math.round((my.x*tile.width)-(screen.width/2)+(tile.width/2));
- }
- offset.top = Math.round((my.y*(tile.height/2))-(screen.height/2)+(tile.height/2));
- $('screen').append('<div class="map" style="left:'+(offset.left*-1)+'px;top:'+(offset.top*-1)+'px"></div>');
- //Calculate Start X/Y End X/Y to draw tiles
- var startX = Math.floor(offset.left/tile.width)-1; //+1 and -1 makes one line more than needed to display
- var endX = Math.round((offset.left+screen.width)/tile.width)+1;
- var startY =Math.floor(offset.top/tile.height)*2-1;
- var endY =Math.round((offset.top+screen.height)/tile.height)*2+1;
- for(var y = startY;y<=endY;y++){
- for(var x= startX;x<=endX;x++){
- //draw tile
- }
- }
Add Comment
Please, Sign In to add comment