/    Sign up×
Community /Pin to ProfileBookmark

New to JS, Problem With Objects

Hey so I’m really new to JavaScript and I’m having a problem wiht making an object work.

This is my code right now:

[CODE]var player = {
x: width/2,
y: height/2,
}

function setup() {
createCanvas(500, 500);
}

function draw() {
background(0);
ellipse(player.x, player.y, 25, 25);
}[/CODE]

problem is, the ellipse doesn’t show up on the screen…

Any help would be awesome! Thanks.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@rootApr 04.2017 — You haven't enough script to produce a canvas object as you will see by this example available online : http://www.html5canvastutorials.com/advanced/html5-canvas-ovals/
Copy linkTweet thisAlerts:
@SempervivumApr 04.2017 — Reading your code I assume that you intend to use some framework or library. Please specify which.
Copy linkTweet thisAlerts:
@shadedcolorsauthorApr 05.2017 — I'm using p5.js

I followed a tutorial series. Is that different from normal JavaScript?
Copy linkTweet thisAlerts:
@shadedcolorsauthorApr 05.2017 — I also have a problem adding an image to my game. It doesn't show up, and I know that the directory is correct.

This is my code:



var img;

function preLoad() {

img = loadImage('images/test.gif');

}

function setup() {

createCanvas(500, 500);

}

function draw() {

background(0);

image(img, 250, 250);

}
Copy linkTweet thisAlerts:
@SempervivumApr 05.2017 — Is that different from normal JavaScript?[/QUOTE]Yes, this is written in Javascript but it is different from the plain javascript API for canvas. Unfortunately I'm not familiar with it as I'm using jCanvas.
Copy linkTweet thisAlerts:
@rootApr 05.2017 — also, framework questions go in the JavaScript Frameworks forum.
×

Success!

Help @shadedcolors spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...