Code edit (14 edits merged)
Please save this source code
User prompt
remove usesText asset and its references
Code edit (6 edits merged)
Please save this source code
User prompt
Please fix the bug: 'tileSize is not defined' in or related to this line: 'var valueText = new Text2(self.type.toString(), {' Line Number: 103
User prompt
Please fix the bug: 'tileGraphics is not defined' in or related to this line: 'valueText.x = tileGraphics.x;' Line Number: 109
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'valueText.x = self.tileGraphics.x;' Line Number: 80
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading 'x')' in or related to this line: 'valueText.x = self.tileGraphics.x;' Line Number: 80
User prompt
Please fix the bug: 'tileGraphics is not defined' in or related to this line: 'valueText.x = tileGraphics.x;' Line Number: 109
User prompt
Please fix the bug: 'tileSize is not defined' in or related to this line: 'var valueText = new Text2(self.type.toString(), {' Line Number: 103
User prompt
Please fix the bug: 'tileGraphics is not defined' in or related to this line: 'valueText.x = tileGraphics.x;' Line Number: 109
Code edit (8 edits merged)
Please save this source code
User prompt
make operation buttons draggable
User prompt
in playing state handlers, make operation buttons draggable
Code edit (6 edits merged)
Please save this source code
User prompt
code if (obj && obj.parent instanceof OperationButton) { dragNode = obj.parent; } doesn't work. drageNode stay null when tapping operationButtons
User prompt
drageNode stay null when tapping operationButtons Fix drag code code if (obj && obj.parent instanceof OperationButton) { dragNode = obj.parent; } doesn't work: unsing parent or parent.parent is not the way to detect objects classes.
User prompt
``` if (obj && obj.parent && obj.parent.constructor.name === 'OperationButton') { dragNode = obj.parent; } ``` Analyze more deeply, you'll find that obj is an event from game.down handler, it contains a target property.
User prompt
Still drag doesn't work. Still dragNode is null. Please refer to game.down documentation to determine how to use the object properly
User prompt
ok, obj.target parameter isn't useful: it's only the main game object. Only use x and y parameters to dertermine if an operation button was tapped
Code edit (1 edits merged)
Please save this source code
User prompt
Ok, try to make operation buttons move smoother โช๐ก Consider importing and using the following plugins: @upit/tween.v1
Code edit (5 edits merged)
Please save this source code
User prompt
make drag anim duration depend on target x,y distance
Code edit (4 edits merged)
Please save this source code
User prompt
store initial operation buttons position in properties baseX and baseY
===================================================================
--- original.js
+++ change.js
@@ -111,23 +111,8 @@
valueText.x = buttonGraphics.x;
valueText.y = buttonGraphics.y;
self.valueText = self.addChild(valueText);
// Functions
- // Dragging functionality
- self.down = function (x, y, obj) {
- self.dragging = true;
- self.dragOffsetX = x - self.x;
- self.dragOffsetY = y - self.y;
- };
- self.move = function (x, y, obj) {
- if (self.dragging) {
- self.x = x - self.dragOffsetX;
- self.y = y - self.dragOffsetY;
- }
- };
- self.up = function (x, y, obj) {
- self.dragging = false;
- };
return self;
});
// StartButton class to represent the start button
var StartButton = Container.expand(function () {
@@ -152,8 +137,9 @@
/****
* Game Code
****/
var interTileOffsetX = -2;
+var dragNode = null;
var interTileOffsetY = -0; // relative to interTileOffsetX
var tileSize = LK.getAsset('hexTile', {}).width + interTileOffsetX;
/************************************* GAME OBJECTS CLASSES ************************************/
/***********************************************************************************************/
@@ -501,8 +487,9 @@
}
function handlePlayingStateUp(x, y, obj) {
// Implement logic for handling up event in PLAYING state
log("Handling up event in PLAYING state");
+ dragNode = null;
}
function handleMenuStateUp(x, y, obj) {
// Implement logic for handling up event in MENU state
log("Handling up event in MENU state");
@@ -511,10 +498,14 @@
// Implement logic for handling move event in SCORE state
//log("Handling move event in SCORE state");
}
function handlePlayingStateMove(x, y, obj) {
- // Implement logic for handling move event in PLAYING state
//log("Handling move event in PLAYING state");
+ if (dragNode) {
+ dragNode.x = x;
+ dragNode.y = y;
+ }
+ //log("Handling move event in PLAYING state");
}
function handleMenuStateMove(x, y, obj) {
// Implement logic for handling move event in MENU state
//log("Handling move event in MENU state");
@@ -525,8 +516,11 @@
}
function handlePlayingStateDown(x, y, obj) {
// Implement logic for handling down event in PLAYING state
log("Handling down event in PLAYING state");
+ if (obj && obj.parent instanceof OperationButton) {
+ dragNode = obj.parent;
+ }
}
function handleMenuStateDown(x, y, obj) {
// Implement logic for handling down event in MENU state
log("Handling down event in MENU state");
tick
Sound effect
tileEntrance
Sound effect
tileRemove
Sound effect
operationSelect
Sound effect
operationCancel
Sound effect
tileChangeValue
Sound effect
resetSound
Sound effect
levelFailed
Sound effect
menuLevelSelect
Sound effect
menuCellEnter
Sound effect
applause
Sound effect
bgMusic
Music
tada
Sound effect