User prompt
Remove player movment
User prompt
Make the player go to the clicked side from player point by moving smoothly to it; If click right go right If click down go down If click left go left If click up go up
User prompt
Make player go to the cursor point not the opposit
User prompt
don't move it far from cursor
User prompt
If clicked by cursor on the top side of player move it vertical straight to it. same for each direction
User prompt
If click down the player go down and same for other directions
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(playerNode, {' Line Number: 51 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make player go to cursor
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(playerNode, {' Line Number: 51 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make the player go to the clicked directions
User prompt
Don't make it follow cursor
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(playerNode, {' Line Number: 55 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
If click any side from the player movz it to it
User prompt
Don't move it diagonal
User prompt
Increase speed for the player.
User prompt
Please fix the bug: 'Uncaught TypeError: tween.to is not a function' in or related to this line: 'tween.to(playerNode, {' Line Number: 61 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
User prompt
Make player movement smooth by large distance
User prompt
Add movement to player up down left right
User prompt
make the player movement only 4 dirctions and horizontal or vertical only.
User prompt
Make it go to the clicked direction.
User prompt
change the movement to horizontal and vertical.
User prompt
Make player moves by right or left or up or down by click the direction. Move player by small distance to the cursor clicked point.
Code edit (1 edits merged)
Please save this source code
Code edit (2 edits merged)
Please save this source code
User prompt
Make it small
/**** * Plugins ****/ var tween = LK.import("@upit/tween.v1"); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ // 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: 0.7, scaleY: 0.7, 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) { // Store the target position playerNode.targetX = x; playerNode.targetY = y; // Determine the direction of the click var direction = { x: x - playerNode.x, y: y - playerNode.y }; // Normalize the direction var length = Math.sqrt(direction.x * direction.x + direction.y * direction.y); direction.x /= length; direction.y /= length; // Set the player's velocity in the direction of the click playerNode.vx = direction.x * 5; playerNode.vy = direction.y * 5; }; ; ; game.update = function () { // Update the player's position based on its velocity playerNode.x += playerNode.vx; playerNode.y += playerNode.vy; // Update the player's last position playerNode.lastX = playerNode.x; playerNode.lastY = playerNode.y; // Stop the player when it reaches the clicked point if (playerNode.vx > 0 && playerNode.x >= playerNode.targetX || playerNode.vx < 0 && playerNode.x <= playerNode.targetX || playerNode.vy > 0 && playerNode.y >= playerNode.targetY || playerNode.vy < 0 && playerNode.y <= playerNode.targetY) { playerNode.vx = 0; playerNode.vy = 0; } };
===================================================================
--- original.js
+++ change.js
@@ -40,8 +40,11 @@
// 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) {
+ // Store the target position
+ playerNode.targetX = x;
+ playerNode.targetY = y;
// Determine the direction of the click
var direction = {
x: x - playerNode.x,
y: y - playerNode.y
@@ -50,25 +53,10 @@
var length = Math.sqrt(direction.x * direction.x + direction.y * direction.y);
direction.x /= length;
direction.y /= length;
// Set the player's velocity in the direction of the click
- if (Math.abs(direction.x) > Math.abs(direction.y)) {
- if (direction.x > 0) {
- playerNode.vx = 5;
- playerNode.vy = 0;
- } else {
- playerNode.vx = -5;
- playerNode.vy = 0;
- }
- } else {
- if (direction.y > 0) {
- playerNode.vx = 0;
- playerNode.vy = 5;
- } else {
- playerNode.vx = 0;
- playerNode.vy = -5;
- }
- }
+ playerNode.vx = direction.x * 5;
+ playerNode.vy = direction.y * 5;
};
;
;
game.update = function () {
@@ -78,9 +66,9 @@
// Update the player's last position
playerNode.lastX = playerNode.x;
playerNode.lastY = playerNode.y;
// Stop the player when it reaches the clicked point
- if (playerNode.vx > 0 && playerNode.x >= playerNode.lastX || playerNode.vx < 0 && playerNode.x <= playerNode.lastX || playerNode.vy > 0 && playerNode.y >= playerNode.lastY || playerNode.vy < 0 && playerNode.y <= playerNode.lastY) {
+ if (playerNode.vx > 0 && playerNode.x >= playerNode.targetX || playerNode.vx < 0 && playerNode.x <= playerNode.targetX || playerNode.vy > 0 && playerNode.y >= playerNode.targetY || playerNode.vy < 0 && playerNode.y <= playerNode.targetY) {
playerNode.vx = 0;
playerNode.vy = 0;
}
};
\ No newline at end of file