User prompt
player not following the cursor when it is close to it!
User prompt
Increase speed of player
User prompt
Please fix the bug: 'TypeError: Cannot read properties of undefined (reading 'x')' in or related to this line: 'var dx = game.mouse.x - playerNode.x;' Line Number: 110
User prompt
When cursor close to the player move it to it.
User prompt
Add magnetic function between cursor and player after the mouse button clicked on player.
User prompt
If hold by cursor on the player constrain player to cursor and follow it on the screen. if button mouse not clicked release the player.
User prompt
Add drage function for player and cursor
User prompt
Scale player
User prompt
Set the player movement by dragging it when holding cursor on it then move it to up or right or down or left
User prompt
the player not moving after holding cursor on it and move it any directon
User prompt
Make the player track the cursor movement after mouse button clicked on player object asset.
User prompt
Move the player object with the cursor after been clicked
User prompt
Make player follow cursor if i hold on it
User prompt
If i hold on the player by cursor hold the player movement and if i move the cursor when i'm holding on the player move it with me.
User prompt
If I'm holding on the player and drage drage player with cursor
User prompt
don't move player if i hold on it
User prompt
Move player with cursor exact same time by moving cursor not when i click
User prompt
I can't move the player from its point!
User prompt
Please fix the bug: 'Uncaught TypeError: playerNode.containsPoint is not a function' in or related to this line: 'if (playerNode.containsPoint(obj.global)) {' Line Number: 69
User prompt
Make the player can be dragged by click in it and hold to move it any freely vertical up or down and horizontal right or left.
User prompt
Hold player to cursor when player clicked by mouse button and don't move it.
User prompt
Make the player drageable
User prompt
Please fix the bug: 'TypeError: game.getChildrenByType is not a function' in or related to this line: 'var mazeWalls = game.getChildrenByType(MazeWall);' Line Number: 64
User prompt
Please fix the bug: 'ReferenceError: MazeWall is not defined' in or related to this line: 'var mazeWalls = game.getChildrenByType(MazeWall);' Line Number: 56
User prompt
Add collision to the player to hold it and moving on the maze
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Classes ****/ // Define the MazeWall class var MazeWall = Container.expand(function () { var self = Container.call(this); }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var isDragging = false; var dragNode = null; var distance = 0; //Declare method for handling move events on game. function handleMove(x, y, obj) { // If the player is being dragged if (isDragging && dragNode) { // Calculate the direction of the cursor from the player var directionX = x - dragNode.x; var directionY = y - dragNode.y; var directionLength = Math.sqrt(directionX * directionX + directionY * directionY); // Normalize the direction directionX /= directionLength; directionY /= directionLength; // Move the player towards the cursor dragNode.x += directionX * distance; dragNode.y += directionY * distance; } } // Set its anchor and pivot point to top left (x: 0.0, y: 0.0). // Retrieve a non-attached LK asset named 'Background1'. var backgroundNode = LK.getAsset('Background1', { anchorX: 0.0, anchorY: 0.0, scaleX: 2048 / 1000, scaleY: 2732 / 1000, x: 0, y: 0 }); //Manually attach asset to element, rather than using self.attachAsset game.addChild(backgroundNode); ; // Retrieve a non-attached LK asset named 'player'. // Set its anchor and pivot point to top left (x: 0.0, y: 0.0). // Position it at the bottom right of the screen (x: 2048, y: 2732). var playerNode = LK.getAsset('player', { anchorX: 2.2, anchorY: 2.2, scaleX: 1.4, scaleY: 1.4, x: 2048, y: 2732 }); // Manually attach asset to element, rather than using self.attachAsset game.addChild(playerNode); // Add event listeners to handle player movement game.down = function (x, y, obj) { // Check if the player was clicked if (playerNode.getBounds().contains(x, y)) { // If so, start dragging the player isDragging = true; dragNode = playerNode; // Calculate the distance between the player and the cursor distance = Math.sqrt(Math.pow(x - playerNode.x, 2) + Math.pow(y - playerNode.y, 2)); // Also call move handler right away to make effect instant. handleMove(x, y, obj); } }; ; ; game.update = function () { // Check for collision with maze walls var mazeWalls = []; for (var i = 0; i < game.children.length; i++) { if (game.children[i] instanceof MazeWall) { mazeWalls.push(game.children[i]); } } for (var i = 0; i < mazeWalls.length; i++) { if (playerNode.intersects(mazeWalls[i])) { // Stop player movement playerNode.vx = 0; playerNode.vy = 0; break; } } // Update player position playerNode.x += playerNode.vx; playerNode.y += playerNode.vy; // Get the distance between the player and the cursor if (game.mouse) { var dx = game.mouse.x - playerNode.x; var dy = game.mouse.y - playerNode.y; var distance = Math.sqrt(dx * dx + dy * dy); // If the cursor is close to the player, move the player towards the cursor if (distance < 100) { var directionX = dx / distance; var directionY = dy / distance; playerNode.x += directionX * 5; playerNode.y += directionY * 5; } } }; //Mouse or touch up on game object game.up = function (x, y, obj) { // Stop dragging the player isDragging = false; dragNode = null; };
===================================================================
--- original.js
+++ change.js
@@ -100,17 +100,19 @@
// Update player position
playerNode.x += playerNode.vx;
playerNode.y += playerNode.vy;
// Get the distance between the player and the cursor
- var dx = game.mouse.x - playerNode.x;
- var dy = game.mouse.y - playerNode.y;
- var distance = Math.sqrt(dx * dx + dy * dy);
- // If the cursor is close to the player, move the player towards the cursor
- if (distance < 100) {
- var directionX = dx / distance;
- var directionY = dy / distance;
- playerNode.x += directionX * 5;
- playerNode.y += directionY * 5;
+ if (game.mouse) {
+ var dx = game.mouse.x - playerNode.x;
+ var dy = game.mouse.y - playerNode.y;
+ var distance = Math.sqrt(dx * dx + dy * dy);
+ // If the cursor is close to the player, move the player towards the cursor
+ if (distance < 100) {
+ var directionX = dx / distance;
+ var directionY = dy / distance;
+ playerNode.x += directionX * 5;
+ playerNode.y += directionY * 5;
+ }
}
};
//Mouse or touch up on game object
game.up = function (x, y, obj) {