Jump to content

Changing values as mouse moves..


EchoFool

Recommended Posts

Hey

 

 

I am trying to create a scrolling affect with my mouse where by the user left clicks and drags to "scroll" the canvas.

 

 

But i am having difficulty applying it.

 

 

This is currently what i have done:

 


function mouseCheck(e){
	var x = e.pageX;
	var y = e.pageY;
	ymouse=(2*(y-canvas.offsetTop-tilesh)-x+canvas.offsetLeft+tilesw)/2;
	xmouse=x+ymouse-tilesw-25-canvas.offsetLeft
		ymouse=Math.round(ymouse/32)/2;
	xmouse=Math.round(xmouse/64);

	document.title = "tileY:" + ymouse + " | tileX:" + xmouse; //display grid position
}



function init(){  //this executes on load of page
var canvas = document.getElementById("canvas");  
canvas.addEventListener("mousemove", mouseCheck, false);


var ctx = canvas.getContext("2d"); 
ctx.canvas.width  = canvas.width;
ctx.canvas.height = canvas.height;


var offset_x; //view position x
var offset_y; //view position y

 

 

The two issues i have is:

1) How do i add a "on left click" but also where the mouse button is still pressed?

2) I need to calculate how far the mouse has moved in x or y direction and assign it to offset_x and offset_y

 

Any one have any idea ? =/

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.