User prompt
Make player teleport to cursor
User prompt
If player clicked by cursor make it follow it to any of the 4 directions movments
User prompt
Add movement to the player right left up down
User prompt
Remove all movments of player
User prompt
If the button of the mouse clicked on the player constrain player with it
User prompt
Hold cursor on the player to drag it
User prompt
Make player move by drage
User prompt
Make player go to the direction where the clicked point
User prompt
if player moved draw by line
User prompt
player must go to cursor clicked point
User prompt
Move player to the left if i click left and same for up and right and down
Code edit (1 edits merged)
Please save this source code
User prompt
make it up a bit
User prompt
Set player position at bottom
User prompt
Add speed to player
User prompt
Makae it move large area and stop
User prompt
Make the player follow the cursor
User prompt
make player move large area
User prompt
if the button clicked in the screen move the player to cursor smoothly by short distance then stop.
User prompt
make player move to the clicked direction toward the cursor smoothly by short distance then stop
User prompt
make player follow cursor smoothly when click in the current direction on the screen.
User prompt
Move player by click horizontal or vertical
User prompt
Make player move toward the cursor smoothly
User prompt
Add movement by click in any direction right or down or left or up to follow cursor smoothly
User prompt
Please fix the bug: 'TypeError: lineGraphics.lineTo is not a function' in or related to this line: 'lineGraphics.lineTo(player.lastX, player.lastY);' Line Number: 35
/**** * Classes ****/ var Draw = Container.expand(function () { var self = Container.call(this); var drawGraphics = self.attachAsset('draw', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { drawGraphics.clear(); // There is no lineStyle method in LK engine. We can set the color of the shape directly when initializing it. self.x = player.x; self.y = player.y; }; }); var Line = Container.expand(function () { var self = Container.call(this); var lineGraphics = self.attachAsset('line', { anchorX: 0.5, anchorY: 0.5 }); self.update = function () { lineGraphics.clear(); self.x = player.x; self.y = player.y; // There is no lineTo method in LK engine. We can set the width and height of the shape directly when initializing it. lineGraphics.width = player.lastX - player.x; lineGraphics.height = player.lastY - player.y; }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var background = game.addChild(LK.getAsset('maze1', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 / 2 })); background.scale.x = game.width / background.width; background.scale.y = game.height / background.height; var player = game.addChild(LK.getAsset('player', { anchorX: 0.5, anchorY: 0.5, x: 2048 / 2, y: 2732 - 115, // Move player position up a bit scaleX: 1.5, scaleY: 1.5 })); game.interactive = true; game.on('mousedown', onDragStart).on('touchstart', onDragStart); function onDragStart(event) { var newPosition = event.data.getLocalPosition(this.parent); if (newPosition.x < player.x) { player.x -= 50; } else if (newPosition.x > player.x) { player.x += 50; } if (newPosition.y < player.y) { player.y -= 50; } else if (newPosition.y > player.y) { player.y += 50; } } var line = game.addChild(new Line()); ;
===================================================================
--- original.js
+++ change.js
@@ -51,35 +51,26 @@
var player = game.addChild(LK.getAsset('player', {
anchorX: 0.5,
anchorY: 0.5,
x: 2048 / 2,
- y: 2732 - 110,
+ y: 2732 - 115,
// Move player position up a bit
scaleX: 1.5,
scaleY: 1.5
}));
-player.interactive = true;
-player.on('mousedown', onDragStart).on('touchstart', onDragStart).on('mouseup', onDragEnd).on('mouseupoutside', onDragEnd).on('touchend', onDragEnd).on('touchendoutside', onDragEnd).on('mousemove', onDragMove).on('touchmove', onDragMove);
+game.interactive = true;
+game.on('mousedown', onDragStart).on('touchstart', onDragStart);
function onDragStart(event) {
- this.data = event.data;
- this.alpha = 0.5;
- this.dragging = true;
-}
-function onDragEnd() {
- this.alpha = 1;
- this.dragging = false;
- this.data = null;
-}
-var line = game.addChild(new Line());
-function onDragMove() {
- if (this.dragging) {
- var newPosition = this.data.getLocalPosition(this.parent);
- this.lastX = this.x;
- this.lastY = this.y;
- this.x += (newPosition.x - this.x) * 0.1;
- this.y += (newPosition.y - this.y) * 0.1;
- if (Math.abs(newPosition.x - this.x) < 5 && Math.abs(newPosition.y - this.y) < 5) {
- this.dragging = false;
- }
+ var newPosition = event.data.getLocalPosition(this.parent);
+ if (newPosition.x < player.x) {
+ player.x -= 50;
+ } else if (newPosition.x > player.x) {
+ player.x += 50;
}
+ if (newPosition.y < player.y) {
+ player.y -= 50;
+ } else if (newPosition.y > player.y) {
+ player.y += 50;
+ }
}
+var line = game.addChild(new Line());
;
\ No newline at end of file