Jump to content

HTML5/Canvas Problem


ShadowEnforcer
 Share

Recommended Posts

Hello,

I have a little problem with the code from my own browsergame. The browsergame is for the moment a client in combination with a server where you start with an ship and fly through an huge map. The player clicks on a point on the map and fly with the ship to this point. When the player draggs the mouse, while he is clicking on this point, the player is flying further and further. When he moves the mouse, the ship would be reinserted into the canvas element und moves to the exactly point. My problem is now, that I register an mousemove event, everytime the player draggs the mouse while clicking on this point, but the player is to fast each more often he's moving the mouse. When he only click on this point, the player moves with the correct speed. Here is the code for the movement.

mousemove++;
velX = (tx1 / dist1) * speed;
velY = (ty1 / dist1) * speed;
velX = velX/1.6;
velY = velY/1.6;
posX1 += velX;
posY1 += velY;
backgroundX -= velX;
backgroundY -= velY;
backgroundX1 -= velX*background_factor;
backgroundY1 -= velY*background_factor;
var playerX1 = 960-backgroundX1;
var playerY1 = 461-backgroundY1;
playerX = playerX1;
playerY = playerY1;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...