User prompt
Switch to Another way to chain `drawSegment` calls without using a callback system is to use a game loop or a tick function that is called at a regular interval by the game engine. Since the LK game engine operates at 60 frames per second, you can leverage the `LK.on('tick', function() {...})` event to schedule and control the drawing of segments.
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Timeout.tick error: Cannot read properties of null (reading 'x')' in this line: 'var lastSegmentEndX = lastSegment.x + Math.cos(lastSegment.rotation) * lastSegment.width;' Line Number: 195
Code edit (1 edits merged)
Please save this source code
User prompt
(!lastSegment || typeof lastSegment.rotation !== 'number') blocks first segment creation
User prompt
Fix rotation is Nan starting from segment index 4. 1. Verify that the `lastSegment` object has been properly initialized with all necessary properties before attempting to calculate its rotation. 2. Check the values of `deltaY` and `deltaX` used in the rotation calculation to ensure they are both valid numbers and that `deltaX` is not zero, as `Math.atan2(0, 0)` would result in an undefined rotation. 3. Trace back to where `deltaY` and `deltaX` are derived from, ensuring that the points or coordinates used in their calculation are correctly set and represent the actual positions of the segments.
Code edit (2 edits merged)
Please save this source code
User prompt
fix pointA.X is still Nan after passing the center
User prompt
fix pointA.X is sometimes Nan
Code edit (7 edits merged)
Please save this source code
User prompt
lastSegmentEndX should take rotation into account
Code edit (1 edits merged)
Please save this source code
User prompt
Fix position of pointA & pointB in drawNextSegment when moveSegments = true : new segments pointA x exeeds previous segment end
User prompt
position of pointA & pointB in drawNextSegment are wrong when moveSegments = true, maybe the slideAmount should be cummulative
User prompt
remove useless code like initSlide
User prompt
remove everything related to ValueIndicator. clean the code
User prompt
remove ValueIndicator without altering segments algorithm
Code edit (1 edits merged)
Please save this source code
User prompt
when moveSegments is true, take into account the slide in drawsegment
User prompt
Ensure the linkage between segments. adjuste to account for the distance that the existing segments have already moved to the left. This would ensure that the new segment is connected to the end of the last segment after it has slid, rather than where it was before sliding.
User prompt
Fix new segments not visible when moveSegments is true
User prompt
maintain the linkage between segments, the starting position of the new segment (`x1`, `y1`) need to be adjusted to account for the distance that the existing segments have already moved to the left. This would ensure that the new segment is connected to the end of the last segment after it has slid, rather than where it was before sliding.
Code edit (2 edits merged)
Please save this source code
User prompt
when moveSegments = true continuously add new stockValuesHistory & graphPoints values
User prompt
continuously add new stockValuesHistory & graphPoints values
===================================================================
--- original.js
+++ change.js
@@ -166,9 +166,9 @@
if (currentTime < endTime) {
LK.setTimeout(updateWidth, 16);
} else {
console.log("Past center ? " + (segment.x + segment.width / 2 >= game.width / 2));
- if (segment.x + segment.width / 2 >= game.width * 0.5) {
+ if (!moveSegments && segment.x + segment.width / 2 >= game.width * 0.5) {
moveSegments = true;
}
if (typeof callback === 'function') {
callback();
@@ -187,9 +187,9 @@
if (index < points.length - 1) {
var pointA = points[index];
var lastSegment = graphSegments.length > 0 ? graphSegments[graphSegments.length - 1] : null;
var lastSegmentEndX = lastSegment ? lastSegment.x + Math.cos(lastSegment.rotation) * lastSegment.width : 0;
- pointA.x = lastSegmentEndX;
+ pointA.x = lastSegment ? lastSegment.x + Math.cos(lastSegment.rotation) * lastSegment.width : 0;
var pointB = points[index + 1];
/*if (moveSegments) {
var lastSegmentEndX = graphSegments.length > 0 ? graphSegments[graphSegments.length - 1].x + graphSegments[graphSegments.length - 1].width : 0;
pointA.x = lastSegmentEndX;
A Technical dark background. Nothing just a gradiant of colors from black to dark blue. Theme : stock market. background
A modern clean empty rectangular button without borders. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
without shadow
a basic empty ui popup with a black background. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.