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
@@ -18,16 +18,8 @@
var self = Container.call(this);
self.isSelected = false;
var optionGraphics = self.createAsset(optionId, optionText, 0.5, 0.5);
self.addChild(optionGraphics);
- var statusText = new Text2(self.isSelected ? 'Activated' : 'Not Activated', {
- size: 30,
- fill: "#ffffff",
- align: 'center'
- });
- statusText.anchor.set(0.5, -1.5);
- self.addChild(statusText);
- self.statusText = statusText;
optionGraphics.on('down', function () {
self.isSelected = !self.isSelected;
if (optionId === 'setting1') {
self.activateSetting1();
@@ -38,66 +30,47 @@
}
});
self.activateSetting1 = function () {
console.log('Setting 1' + (self.isSelected ? ' was activated' : ' was deactivated'));
- /*
- this can be replace by the function you want to be executed when the settings is activated.
- */
+ setGameSetting('setting1', self.isSelected);
var object1 = getChildByName(game, 'object1');
- self.statusText.setText(self.isSelected ? 'Activated' : 'Not Activated');
- if (self.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;
- }
+ 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 (self.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;
- }
+ 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 (self.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;
- }
+ 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);
@@ -108,38 +81,57 @@
var self = Container.call(this);
var cogwheelGraphics = self.createAsset('cogwheels', 'Settings Cogwheel', 0.5, 0.5);
var setting1, setting2, setting3;
cogwheelGraphics.on('down', function () {
- game.addChildAt(settingsBackground, game.children.length);
+ toggleSettingsMenu();
+ });
+ function toggleSettingsMenu() {
console.log('Settings cogwheel tapped');
- settingsBackground.visible = !settingsBackground.visible;
- settingsBackground.x = 2048 / 2;
- settingsBackground.y = 2732 / 2;
if (!settingsBackground.visible) {
- if (setting1) {
- game.removeChild(setting1);
- }
- if (setting2) {
- game.removeChild(setting2);
- }
- if (setting3) {
- game.removeChild(setting3);
- }
+ showSettingsMenu();
} 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');
+ hideSettingsMenu();
}
- });
+ }
+ function showSettingsMenu() {
+ game.addChildAt(settingsBackground, game.children.length);
+ settingsBackground.visible = true;
+ 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);
+ }
+ var setting2 = getChildByName(game, 'setting2');
+ if (setting2) {
+ game.removeChild(setting2);
+ }
+ var setting3 = getChildByName(game, 'setting3');
+ if (setting3) {
+ game.removeChild(setting3);
+ }
+ }
});
/****
* Initialize Game