Code edit (3 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: alpha is undefined' in or related to this line: 'numberText.setText(alpha.toFixed(1));' Line Number: 67
Code edit (2 edits merged)
Please save this source code
User prompt
display a number text in the top center of the screen
Code edit (1 edits merged)
Please save this source code
Code edit (16 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: character.update is not a function' in or related to this line: 'character.update();' Line Number: 167
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'ReferenceError: body is not defined' in or related to this line: 'armLeft.x = -body.width / 2 + armOffsetX;' Line Number: 120
User prompt
rename the "body" asset to "torso" and rename any usages
Code edit (3 edits merged)
Please save this source code
User prompt
after creating the body asset in the character class, add a head asset with an anchor of 0.35, 0.95
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: self.getAsset is not a function' in or related to this line: 'var body = self.getAsset('body', {});' Line Number: 99
Code edit (10 edits merged)
Please save this source code
User prompt
Please fix the bug: 'TypeError: cyclic object value' in or related to this line: 'self.attachAsset(body, {});' Line Number: 106
Code edit (1 edits merged)
Please save this source code
Code edit (1 edits merged)
Please save this source code
User prompt
in the character update method, call the update method of the right and left arms, using the runAlpha as the alpha value
User prompt
Add a runAlpha variable to the Character class and increase its value by 0.02 in the update method, additionally, reduce the value by 1 if the value is >= 1
User prompt
Add a runAlpha variable to the Character class and increase its value in the update method
User prompt
Add an alpha = 0 variable to the character and increase its value by 0.02 in the update method reducing the value by 1 if it's value >= 1
/**** * Classes ****/ /** * config { * x : Number || 0, * y : Number || 0, * rotation : Number || 0, * } **/ var ConfigContainer = Container.expand(function (config) { var self = Container.call(this); config = config || {}; ; self.x = config.x || 0; self.y = config.y || 0; self.rotation = config.rotation || 0; ; return self; }); var CharacterLeg = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Leg settings var upperBaseAngle = Math.PI * 3 / 8; var lowerBaseOffset = 135; var lowerHoldAngle = Math.PI / 8; var footBaseOffset = 100; // Create and attach leg parts var upper = self.attachAsset('upperLeg', { rotation: upperBaseAngle, anchorY: 0.1, tint: config.tint || 0xFFFFFF }); var lower = self.addChild(new ConfigContainer({ y: lowerBaseOffset, tint: config.tint || 0xFFFFFF })); lower.attachAsset('lowerLeg', { anchorX: 0.65, tint: config.tint || 0xFFFFFF }); var foot = lower.attachAsset('foot', { y: footBaseOffset, anchorX: 0.2, anchorY: 0.05, tint: config.tint || 0xFFFFFF }); self.update = function (alpha) { var upperSwing = Math.sin(alpha * Math.PI * 2) * Math.PI / 3; self.rotation = upperSwing; lower.rotation = Math.abs(-upperSwing) + lowerHoldAngle; foot.rotation = Math.max(0, upperSwing * 2 / 3) - lowerHoldAngle; }; }); var CharacterBody = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Body settings var armOffsetX = 15; var armOffsetY = 30; var pelvisOffsetX = -15; var legOffsetX = 5; // Create and attach body parts var armRight = self.addChild(new CharacterArm({ y: armOffsetY, tint: 0x777777 })); var legRight = self.addChild(new CharacterLeg({ x: pelvisOffsetX + legOffsetX, tint: 0x777777 })); var torso = self.attachAsset('torso', { anchorX: 0.5 }); var head = self.attachAsset('head', { anchorX: 0.15, anchorY: 0.95 }); var pelvis = self.attachAsset('pelvis', { x: pelvisOffsetX, y: torso.height, anchorX: 0.5, anchorY: 0.2 }); var legLeft = self.addChild(new CharacterLeg({ x: pelvisOffsetX - legOffsetX })); var armLeft = self.addChild(new CharacterArm({ y: armOffsetY })); // Position body parts armLeft.x = -torso.width / 2 + armOffsetX; armRight.x = torso.width / 2 - armOffsetX; legLeft.y = torso.height + pelvis.height / 3; legRight.y = torso.height + pelvis.height / 3; // Add an empty update function to the Character class self.runAlpha = 0; self.update = function () { this.runAlpha += 0.001; armLeft.update(this.runAlpha); armRight.update(this.runAlpha - 0.5); //legLeft.update(this.runAlpha); legRight.update(this.runAlpha - 0.5); }; }); var CharacterArm = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); // Arm settings var upperBaseAngle = -Math.PI * 3 / 8; var upperOffsetAngle = Math.PI / 5; var lowerBaseAngle = -Math.PI / 4; var lowerHoldAngle = -Math.PI * 5 / 8; var lowerBaseOffset = 90; // Create and attach arm parts var upper = self.attachAsset('upperArm', { rotation: upperBaseAngle, anchorX: 0.85, anchorY: 0.25, tint: config.tint || 0xFFFFFF }); var lower = self.attachAsset('lowerArm', { y: lowerBaseOffset, rotation: lowerBaseAngle + lowerHoldAngle, anchorX: 0.95, anchorY: 0.05, tint: config.tint || 0xFFFFFF }); self.update = function (alpha) { var upperSwing = Math.sin(alpha * Math.PI * 2) * Math.PI / 4; // Swing between -45 and 45 degrees var lowerSwing = -upperSwing / 2; self.rotation = -upperSwing + upperOffsetAngle; lower.rotation = lowerBaseAngle + lowerHoldAngle + lowerSwing; }; }); var Character = ConfigContainer.expand(function (config) { var self = ConfigContainer.call(this, config); var body = self.addChild(new CharacterBody()); self.update = function () { body.update(); }; }); /**** * Initialize Game ****/ var game = new LK.Game({ backgroundColor: 0x000000 }); /**** * Game Code ****/ var character = game.addChild(new Character({ x: 2048 / 2, y: 2732 / 2 })); // Create a text object to display the number var numberText = new Text2('0', { size: 150, fill: "#ffffff" }); // Set the anchor to the center of the top edge of the text numberText.anchor.set(0.5, 0); // Add the text to the top-center of the screen LK.gui.top.addChild(numberText); ; // Events LK.on('tick', function () { character.update(); }); ; // Animations function animationRun(alpha) { return {}; } function animationJump(alpha) { return {}; } function animationStand(alpha) { return {}; }
===================================================================
--- original.js
+++ change.js
@@ -97,9 +97,9 @@
self.update = function () {
this.runAlpha += 0.001;
armLeft.update(this.runAlpha);
armRight.update(this.runAlpha - 0.5);
- legLeft.update(this.runAlpha);
+ //legLeft.update(this.runAlpha);
legRight.update(this.runAlpha - 0.5);
};
});
var CharacterArm = ConfigContainer.expand(function (config) {
white
white
circle sliced into many pieces, flat image. 2d, white background, shadowless.
pixel art of a tall, tree. game asset, 2d, white background, shadowless.
Pixel art street lamp. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art cloud. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.
pixel art sun. Single Game Texture. In-Game asset. 2d. Blank background. High contrast. No shadows.