What does this certain function refer to?
I was analyzing this piece of code (new to javascript) that is part of a simple flappy bird game but cant figure out what does this function this.x = width
refer to. Exactly what does the width
mean.
Some context
function Pipe() {
this.spacing = 175;
this.top = random(height / 6, 3 / 4 * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 4 ;
this.highlight = false;
this.hits = function(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
this.highlight = true;
return true;
}
}
this.highlight = false;
return false;
}
this.show = function() {
fill(255);
if (this.highlight) {
fill(255, 0, 0);
}
rect(this.x, 0, this.w, this.top);
rect(this.x, height-this.bottom, this.w, this.bottom);
}
this.update = function() {
this.x -= this.speed;
}
this.offscreen = function() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
I would really appreciate if someone could help me with this one.
javascript function
add a comment |
I was analyzing this piece of code (new to javascript) that is part of a simple flappy bird game but cant figure out what does this function this.x = width
refer to. Exactly what does the width
mean.
Some context
function Pipe() {
this.spacing = 175;
this.top = random(height / 6, 3 / 4 * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 4 ;
this.highlight = false;
this.hits = function(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
this.highlight = true;
return true;
}
}
this.highlight = false;
return false;
}
this.show = function() {
fill(255);
if (this.highlight) {
fill(255, 0, 0);
}
rect(this.x, 0, this.w, this.top);
rect(this.x, height-this.bottom, this.w, this.bottom);
}
this.update = function() {
this.x -= this.speed;
}
this.offscreen = function() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
I would really appreciate if someone could help me with this one.
javascript function
1
The snippet is incomplete, so it's rather hard to say. If you tried to run that you'd get an error.
– Jared Smith
Nov 12 at 20:27
add a comment |
I was analyzing this piece of code (new to javascript) that is part of a simple flappy bird game but cant figure out what does this function this.x = width
refer to. Exactly what does the width
mean.
Some context
function Pipe() {
this.spacing = 175;
this.top = random(height / 6, 3 / 4 * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 4 ;
this.highlight = false;
this.hits = function(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
this.highlight = true;
return true;
}
}
this.highlight = false;
return false;
}
this.show = function() {
fill(255);
if (this.highlight) {
fill(255, 0, 0);
}
rect(this.x, 0, this.w, this.top);
rect(this.x, height-this.bottom, this.w, this.bottom);
}
this.update = function() {
this.x -= this.speed;
}
this.offscreen = function() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
I would really appreciate if someone could help me with this one.
javascript function
I was analyzing this piece of code (new to javascript) that is part of a simple flappy bird game but cant figure out what does this function this.x = width
refer to. Exactly what does the width
mean.
Some context
function Pipe() {
this.spacing = 175;
this.top = random(height / 6, 3 / 4 * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 4 ;
this.highlight = false;
this.hits = function(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
this.highlight = true;
return true;
}
}
this.highlight = false;
return false;
}
this.show = function() {
fill(255);
if (this.highlight) {
fill(255, 0, 0);
}
rect(this.x, 0, this.w, this.top);
rect(this.x, height-this.bottom, this.w, this.bottom);
}
this.update = function() {
this.x -= this.speed;
}
this.offscreen = function() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
I would really appreciate if someone could help me with this one.
function Pipe() {
this.spacing = 175;
this.top = random(height / 6, 3 / 4 * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 4 ;
this.highlight = false;
this.hits = function(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
this.highlight = true;
return true;
}
}
this.highlight = false;
return false;
}
this.show = function() {
fill(255);
if (this.highlight) {
fill(255, 0, 0);
}
rect(this.x, 0, this.w, this.top);
rect(this.x, height-this.bottom, this.w, this.bottom);
}
this.update = function() {
this.x -= this.speed;
}
this.offscreen = function() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
function Pipe() {
this.spacing = 175;
this.top = random(height / 6, 3 / 4 * height);
this.bottom = height - (this.top + this.spacing);
this.x = width;
this.w = 80;
this.speed = 4 ;
this.highlight = false;
this.hits = function(bird) {
if (bird.y < this.top || bird.y > height - this.bottom) {
if (bird.x > this.x && bird.x < this.x + this.w) {
this.highlight = true;
return true;
}
}
this.highlight = false;
return false;
}
this.show = function() {
fill(255);
if (this.highlight) {
fill(255, 0, 0);
}
rect(this.x, 0, this.w, this.top);
rect(this.x, height-this.bottom, this.w, this.bottom);
}
this.update = function() {
this.x -= this.speed;
}
this.offscreen = function() {
if (this.x < -this.w) {
return true;
} else {
return false;
}
}
}
javascript function
javascript function
edited Nov 12 at 20:25
ODYN-Kon
2,0841625
2,0841625
asked Nov 12 at 20:21
Samu Kallio
1
1
1
The snippet is incomplete, so it's rather hard to say. If you tried to run that you'd get an error.
– Jared Smith
Nov 12 at 20:27
add a comment |
1
The snippet is incomplete, so it's rather hard to say. If you tried to run that you'd get an error.
– Jared Smith
Nov 12 at 20:27
1
1
The snippet is incomplete, so it's rather hard to say. If you tried to run that you'd get an error.
– Jared Smith
Nov 12 at 20:27
The snippet is incomplete, so it's rather hard to say. If you tried to run that you'd get an error.
– Jared Smith
Nov 12 at 20:27
add a comment |
1 Answer
1
active
oldest
votes
In this case, width
is referencing a variable that must have been defined outside of Pipe()
function. Same goes for height
.
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%2f53269523%2fwhat-does-this-certain-function-refer-to%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
In this case, width
is referencing a variable that must have been defined outside of Pipe()
function. Same goes for height
.
add a comment |
In this case, width
is referencing a variable that must have been defined outside of Pipe()
function. Same goes for height
.
add a comment |
In this case, width
is referencing a variable that must have been defined outside of Pipe()
function. Same goes for height
.
In this case, width
is referencing a variable that must have been defined outside of Pipe()
function. Same goes for height
.
answered Nov 12 at 20:24
ODYN-Kon
2,0841625
2,0841625
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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%2f53269523%2fwhat-does-this-certain-function-refer-to%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
1
The snippet is incomplete, so it's rather hard to say. If you tried to run that you'd get an error.
– Jared Smith
Nov 12 at 20:27