User prompt
clean up the code
User prompt
make setting1 2 and 3 dissappear when the settings cog is clicked again
User prompt
make the settings dissappear when the settings cog is clicked again
User prompt
make the settings disappear when the cog wheel is clicked again
User prompt
tidy the code up
User prompt
put a text element on the setting1 button, saying if it is currently activated or not
Code edit (1 edits merged)
Please save this source code
User prompt
add a text box that appears when the settings cog is pressed, and disappears when it is pressed again. name it settings1status
Code edit (2 edits merged)
Please save this source code
User prompt
make the textbox be invisable at first, and only appear when the settings menu is active
Code edit (1 edits merged)
Please save this source code
User prompt
make a text box that keeps track if settings1 is activated or not
Code edit (1 edits merged)
Please save this source code
User prompt
make a text box that keeps track if settings1 is activated or not
User prompt
make a textbox that keeps track off the status of setting1 by checking if setting1 is true or false, make it a part of the settings menu.
User prompt
Fix Bug: 'TypeError: self.setText is not a function' in this line: 'self.setText('Setting 1 is ' + (status ? 'On' : 'Off'));' Line Number: 8
User prompt
make a textbox that keeps track off the status of setting1, make it a part of the settings menu
User prompt
make SettingsStatusText1 a part of the settings menu so it disappears and reappears when the settings menu is opened
User prompt
make SettingsStatusText1 a part of the settings menu so it disappears and reappears when the settings menu is opened
User prompt
rename SettingsStatusText to SettingsStatusText1
User prompt
name the settings status text settingstatustext1
Code edit (1 edits merged)
Please save this source code
User prompt
Fix Bug: 'Error: The supplied DisplayObject must be a child of the caller' in this line: 'self.visible = false;' Line Number: 15
User prompt
Fix Bug: 'Error: The supplied DisplayObject must be a child of the caller' in this line: 'self.visible = false;' Line Number: 16
User prompt
Fix Bug: 'Error: The supplied DisplayObject must be a child of the caller' in this line: 'self.visible = false;' Line Number: 17
===================================================================
--- original.js
+++ change.js
@@ -21,57 +21,15 @@
self.addChild(optionGraphics);
optionGraphics.on('down', function () {
self.isSelected = !self.isSelected;
if (optionId === 'setting1') {
- self.activateSetting1();
+ activateSetting1(self.isSelected);
} else if (optionId === 'setting2') {
- self.activateSetting2();
+ activateSetting2(self.isSelected);
} else if (optionId === 'setting3') {
- self.activateSetting3();
+ activateSetting3(self.isSelected);
}
});
- self.activateSetting1 = function () {
- console.log('Setting 1' + (self.isSelected ? ' was activated' : ' was deactivated'));
- setGameSetting('setting1', self.isSelected);
- var object1 = getChildByName(game, 'object1');
- if (!object1 && self.isSelected) {
- object1 = game.addChildAt(new Object1(), game.getChildIndex(settingsBackground));
- object1.name = 'object1';
- object1.x = 2048 / 2;
- object1.y = 2732 / 2 - 450;
- }
- if (object1) {
- object1.visible = self.isSelected;
- }
- };
- self.activateSetting2 = function () {
- console.log('Setting 2' + (self.isSelected ? ' was activated' : ' was deactivated'));
- setGameSetting('setting2', self.isSelected);
- var object2 = getChildByName(game, 'object2');
- if (!object2 && self.isSelected) {
- object2 = game.addChildAt(new Object2(), game.getChildIndex(settingsBackground));
- object2.name = 'object2';
- object2.x = 2048 / 2;
- object2.y = 2732 / 2 - 300;
- }
- if (object2) {
- object2.visible = self.isSelected;
- }
- };
- self.activateSetting3 = function () {
- console.log('Setting 3' + (self.isSelected ? ' was activated' : ' was deactivated'));
- setGameSetting('setting3', self.isSelected);
- var object3 = getChildByName(game, 'object3');
- if (!object3 && self.isSelected) {
- object3 = game.addChildAt(new Object3(), game.getChildIndex(settingsBackground));
- object3.name = 'object3';
- object3.x = 2048 / 2;
- object3.y = 2732 / 2 - 150;
- }
- if (object3) {
- object3.visible = self.isSelected;
- }
- };
});
var SettingsBackground = Container.expand(function () {
var self = Container.call(this);
var settingsBgGraphics = self.createAsset('settingsBg', 'Settings Background', 0.5, 0.5);
@@ -81,58 +39,38 @@
var self = Container.call(this);
var cogwheelGraphics = self.createAsset('cogwheels', 'Settings Cogwheel', 0.5, 0.5);
var setting1, setting2, setting3;
cogwheelGraphics.on('down', function () {
- toggleSettingsMenu();
- });
- function toggleSettingsMenu() {
- console.log('Settings cogwheel tapped');
- if (settingsBackground.visible) {
- hideSettingsMenu();
- destroySettingOptions();
- } else {
- showSettingsMenu();
- }
- }
- function showSettingsMenu() {
game.addChildAt(settingsBackground, game.children.length);
- settingsBackground.visible = true;
+ console.log('Settings cogwheel tapped');
+ settingsBackground.visible = !settingsBackground.visible;
settingsBackground.x = 2048 / 2;
settingsBackground.y = 2732 / 2;
- createSettingOptions();
- }
- function hideSettingsMenu() {
- settingsBackground.visible = false;
- destroySettingOptions();
- }
- function createSettingOptions() {
- var setting1 = game.addChild(new SettingOption('setting1', 'Setting 1'));
- setting1.x = settingsBackground.x;
- setting1.y = settingsBackground.y - 450;
- setting1.isSelected = getGameSetting('setting1');
- var setting2 = game.addChild(new SettingOption('setting2', 'Setting 2'));
- setting2.x = settingsBackground.x;
- setting2.y = settingsBackground.y - 200;
- setting2.isSelected = getGameSetting('setting2');
- var setting3 = game.addChild(new SettingOption('setting3', 'Setting 3'));
- setting3.x = settingsBackground.x;
- setting3.y = settingsBackground.y + 50;
- setting3.isSelected = getGameSetting('setting3');
- }
- function destroySettingOptions() {
- var setting1 = getChildByName(game, 'setting1');
- if (setting1) {
- game.removeChild(setting1);
+ if (!settingsBackground.visible) {
+ if (setting1) {
+ game.removeChild(setting1);
+ }
+ if (setting2) {
+ game.removeChild(setting2);
+ }
+ if (setting3) {
+ game.removeChild(setting3);
+ }
+ } else {
+ setting1 = game.addChild(new SettingOption('setting1', 'Setting 1'));
+ setting1.x = settingsBackground.x;
+ setting1.y = settingsBackground.y - 450;
+ setting1.isSelected = getGameSetting('setting1');
+ setting2 = game.addChild(new SettingOption('setting2', 'Setting 2'));
+ setting2.x = settingsBackground.x;
+ setting2.y = settingsBackground.y - 200;
+ setting2.isSelected = getGameSetting('setting2');
+ setting3 = game.addChild(new SettingOption('setting3', 'Setting 3'));
+ setting3.x = settingsBackground.x;
+ setting3.y = settingsBackground.y + 50;
+ setting3.isSelected = getGameSetting('setting3');
}
- var setting2 = getChildByName(game, 'setting2');
- if (setting2) {
- game.removeChild(setting2);
- }
- var setting3 = getChildByName(game, 'setting3');
- if (setting3) {
- game.removeChild(setting3);
- }
- }
+ });
});
/****
* Initialize Game
@@ -158,8 +96,65 @@
}
function setGameSetting(setting, value) {
gameSettings[setting] = value;
}
+function activateSetting1(isSelected) {
+ console.log('Setting 1' + (isSelected ? ' was activated' : ' was deactivated'));
+ var object1 = getChildByName(game, 'object1');
+ if (isSelected) {
+ setGameSetting('setting1', true);
+ if (!object1) {
+ object1 = game.addChildAt(new Object1(), game.getChildIndex(settingsBackground));
+ object1.name = 'object1';
+ object1.x = 2048 / 2;
+ object1.y = 2732 / 2 - 450;
+ }
+ object1.visible = true;
+ } else {
+ setGameSetting('setting1', false);
+ if (object1) {
+ object1.visible = false;
+ }
+ }
+}
+function activateSetting2(isSelected) {
+ console.log('Setting 2' + (isSelected ? ' was activated' : ' was deactivated'));
+ var object2 = getChildByName(game, 'object2');
+ if (isSelected) {
+ setGameSetting('setting2', true);
+ if (!object2) {
+ object2 = game.addChildAt(new Object2(), game.getChildIndex(settingsBackground));
+ object2.name = 'object2';
+ object2.x = 2048 / 2;
+ object2.y = 2732 / 2 - 300;
+ }
+ object2.visible = true;
+ } else {
+ setGameSetting('setting2', false);
+ if (object2) {
+ object2.visible = false;
+ }
+ }
+}
+function activateSetting3(isSelected) {
+ console.log('Setting 3' + (isSelected ? ' was activated' : ' was deactivated'));
+ var object3 = getChildByName(game, 'object3');
+ if (isSelected) {
+ setGameSetting('setting3', true);
+ if (!object3) {
+ object3 = game.addChildAt(new Object3(), game.getChildIndex(settingsBackground));
+ object3.name = 'object3';
+ object3.x = 2048 / 2;
+ object3.y = 2732 / 2 - 150;
+ }
+ object3.visible = true;
+ } else {
+ setGameSetting('setting3', false);
+ if (object3) {
+ object3.visible = false;
+ }
+ }
+}
game.setBackgroundColor(0xFFFFFF);
var settingsBackground = new SettingsBackground();
var cogwheels = game.addChild(new Cogwheels());
cogwheels.x = 2048 - cogwheels.width / 2 - 50;