How to insert a function inside a .tick() handler on the fly in aframe?
I want to remove a piece of code inside a .tick handler in AFRAME using js.
This is what I have:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {},
update: function () {},
tick: function() {
myObject.position.y += 0.009;//this is what I want to remove on the fly
},
remove: function () {},
pause: function () {},
play: function () {}
});
I expect to trigger the add or removal of that piece of code on the fly using js.
aframe
add a comment |
I want to remove a piece of code inside a .tick handler in AFRAME using js.
This is what I have:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {},
update: function () {},
tick: function() {
myObject.position.y += 0.009;//this is what I want to remove on the fly
},
remove: function () {},
pause: function () {},
play: function () {}
});
I expect to trigger the add or removal of that piece of code on the fly using js.
aframe
add a comment |
I want to remove a piece of code inside a .tick handler in AFRAME using js.
This is what I have:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {},
update: function () {},
tick: function() {
myObject.position.y += 0.009;//this is what I want to remove on the fly
},
remove: function () {},
pause: function () {},
play: function () {}
});
I expect to trigger the add or removal of that piece of code on the fly using js.
aframe
I want to remove a piece of code inside a .tick handler in AFRAME using js.
This is what I have:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {},
update: function () {},
tick: function() {
myObject.position.y += 0.009;//this is what I want to remove on the fly
},
remove: function () {},
pause: function () {},
play: function () {}
});
I expect to trigger the add or removal of that piece of code on the fly using js.
aframe
aframe
asked Dec 29 '18 at 5:41
XunorusXunorus
12
12
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Sorround your logic with an if statement that checks for the appropriate conditions:
tick: function() {
if (conditions) {
myObject.position.y += 0.009;
}
}
You can set those conditions anywhere in your code: component local or global variable, component property...
add a comment |
Thanks! I used the conditional like this:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {
condition = false;
},
update: function () {},
tick: function() {
if (condition == true) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Now I can trigger the state with:
condition = false;
2
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:schema: {enabled: { default: false }}and you can doel.setAttribute(‘foo’, {enabled: false})
– Diego Marcos
Dec 29 '18 at 19:04
add a comment |
I think you misunderstood the point of schema and updates, but you are really really close with your logic.
I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.
AFRAME.registerComponent('foo', {
schema: {
condition: {type: boolean, default:false}
},
init: function () {
//possible once off initialization logic
},
update: function () {},
tick: function() {
if (this.data.codition) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Then on the fly you simply do
yourElementWithFooComponent.setAttribute("condition":"true"/"false");
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53967012%2fhow-to-insert-a-function-inside-a-tick-handler-on-the-fly-in-aframe%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sorround your logic with an if statement that checks for the appropriate conditions:
tick: function() {
if (conditions) {
myObject.position.y += 0.009;
}
}
You can set those conditions anywhere in your code: component local or global variable, component property...
add a comment |
Sorround your logic with an if statement that checks for the appropriate conditions:
tick: function() {
if (conditions) {
myObject.position.y += 0.009;
}
}
You can set those conditions anywhere in your code: component local or global variable, component property...
add a comment |
Sorround your logic with an if statement that checks for the appropriate conditions:
tick: function() {
if (conditions) {
myObject.position.y += 0.009;
}
}
You can set those conditions anywhere in your code: component local or global variable, component property...
Sorround your logic with an if statement that checks for the appropriate conditions:
tick: function() {
if (conditions) {
myObject.position.y += 0.009;
}
}
You can set those conditions anywhere in your code: component local or global variable, component property...
edited Dec 29 '18 at 18:01
answered Dec 29 '18 at 11:49
Diego MarcosDiego Marcos
1,97531013
1,97531013
add a comment |
add a comment |
Thanks! I used the conditional like this:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {
condition = false;
},
update: function () {},
tick: function() {
if (condition == true) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Now I can trigger the state with:
condition = false;
2
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:schema: {enabled: { default: false }}and you can doel.setAttribute(‘foo’, {enabled: false})
– Diego Marcos
Dec 29 '18 at 19:04
add a comment |
Thanks! I used the conditional like this:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {
condition = false;
},
update: function () {},
tick: function() {
if (condition == true) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Now I can trigger the state with:
condition = false;
2
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:schema: {enabled: { default: false }}and you can doel.setAttribute(‘foo’, {enabled: false})
– Diego Marcos
Dec 29 '18 at 19:04
add a comment |
Thanks! I used the conditional like this:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {
condition = false;
},
update: function () {},
tick: function() {
if (condition == true) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Now I can trigger the state with:
condition = false;
Thanks! I used the conditional like this:
AFRAME.registerComponent('foo', {
schema: {},
init: function () {
condition = false;
},
update: function () {},
tick: function() {
if (condition == true) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Now I can trigger the state with:
condition = false;
answered Dec 29 '18 at 18:28
XunorusXunorus
12
12
2
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:schema: {enabled: { default: false }}and you can doel.setAttribute(‘foo’, {enabled: false})
– Diego Marcos
Dec 29 '18 at 19:04
add a comment |
2
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:schema: {enabled: { default: false }}and you can doel.setAttribute(‘foo’, {enabled: false})
– Diego Marcos
Dec 29 '18 at 19:04
2
2
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:
schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})– Diego Marcos
Dec 29 '18 at 19:04
Good job! Another idea is adding the condition as part of the schema to avoid the global variable:
schema: {enabled: { default: false }} and you can do el.setAttribute(‘foo’, {enabled: false})– Diego Marcos
Dec 29 '18 at 19:04
add a comment |
I think you misunderstood the point of schema and updates, but you are really really close with your logic.
I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.
AFRAME.registerComponent('foo', {
schema: {
condition: {type: boolean, default:false}
},
init: function () {
//possible once off initialization logic
},
update: function () {},
tick: function() {
if (this.data.codition) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Then on the fly you simply do
yourElementWithFooComponent.setAttribute("condition":"true"/"false");
add a comment |
I think you misunderstood the point of schema and updates, but you are really really close with your logic.
I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.
AFRAME.registerComponent('foo', {
schema: {
condition: {type: boolean, default:false}
},
init: function () {
//possible once off initialization logic
},
update: function () {},
tick: function() {
if (this.data.codition) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Then on the fly you simply do
yourElementWithFooComponent.setAttribute("condition":"true"/"false");
add a comment |
I think you misunderstood the point of schema and updates, but you are really really close with your logic.
I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.
AFRAME.registerComponent('foo', {
schema: {
condition: {type: boolean, default:false}
},
init: function () {
//possible once off initialization logic
},
update: function () {},
tick: function() {
if (this.data.codition) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Then on the fly you simply do
yourElementWithFooComponent.setAttribute("condition":"true"/"false");
I think you misunderstood the point of schema and updates, but you are really really close with your logic.
I would add the condition into the schema so that you can use it anywhere within your component as well as use AFrame sugar to update it using setAttribute.
AFRAME.registerComponent('foo', {
schema: {
condition: {type: boolean, default:false}
},
init: function () {
//possible once off initialization logic
},
update: function () {},
tick: function() {
if (this.data.codition) {
myObject.position.y += 0.009;//this is what I want to remove on the fly
}
},
remove: function () {},
pause: function () {},
play: function () {}
});
Then on the fly you simply do
yourElementWithFooComponent.setAttribute("condition":"true"/"false");
answered Dec 30 '18 at 16:33
BeyerzBeyerz
4881718
4881718
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53967012%2fhow-to-insert-a-function-inside-a-tick-handler-on-the-fly-in-aframe%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown