All Questions
43 questions
0
votes
1
answer
62
views
display(){} Method p5.js not displaying image
I working on a school project. I created a class for an image. It seemed to be working when the class was embedded in the draw function. My professor said that I should move the class outside of the ...
0
votes
1
answer
49
views
Bouncing ball is glitched
I have problem with the bouncing ball, while creating it using class. The ball move but it stuck at the bottom of the page. Please help!!
Thank you!!!
The ball move but it stuck at the bottom of the ...
1
vote
1
answer
68
views
P5JS- Drawing circles that not overlapped
I have this code to draw an array of circle and make sure they will not be overalapped. I don't know what my problem is, cause it's not giving error but at the same time, I don't see anything ...
0
votes
1
answer
197
views
How to switch from a menu screen to actual game?
So I am trying to switch between a menu screen (currently just a blank canvas with a line of text) and the actual game screen in p5.js. What I have tried at the moment is using a variable called '...
0
votes
0
answers
71
views
Why does p5js lag a lot when I use classes?
I'm trying to use classes in p5js but when I use new Object(), it just lags the website to something like 0.1 FPS.
let objects = [];
function setup() {
createCanvas(400, 400);
const object = ...
0
votes
1
answer
36
views
How do I make this array of objects 'spring' into random positions on the canvas?
I'm trying to make an array of images 'spring' onto the canvas from the bottom of the screen and then land in random positions, like this image here:enter image description here (this is a screenshot ...
0
votes
0
answers
52
views
Accessing other classes inside a class Javascript
I am trying to make a simple breakout game with p5js. I got the balls to work fine, but when I try to make them interact with the brick class, I run into some problems. I can't seem to figure ourI don'...
2
votes
1
answer
271
views
Use p5js functions with node, npm minification
I am trying to convert a sketch to use node and bundle a distribution js file. My guess is that some of the function names in p5js must be reserved (to combat this I was going to use a development ...
-3
votes
1
answer
245
views
The move function is not functioning as expected
I am having trouble with this project. I’m pretty new on this and I doesn’t know why this piece of code is not working properly.
There is a spot in the grid (you, the player) that is transferred to ...
1
vote
1
answer
313
views
How to create a flower shape with ellipses within a class function?
I'm trying to make a mini game in which a flower (made up of ellipses) is moved by the mouse horizontally in order to catch rain droplets.
I'm struggling with several different issues and would love ...
2
votes
1
answer
115
views
How would I add text in a circle and also shuffle my questions?
Link to code for reference: https://editor.p5js.org/tpant963/sketches/Ft9fBLlRU
Hi! So I've been trying to make a review game on Java OOP concepts on p5.js, but I'm beginning to get a bit overwhelmed ...
1
vote
1
answer
252
views
How to modify the behavior of one method on a javascript class when another method is called?
I created a class on javascript using the p5.js package and I would like to know how I could modify the inner properties of a method with another method belonging to the same class.
So I basically ...
0
votes
1
answer
724
views
How to declare class when using p5.js with react
I am trying to implement the code below in my react app. And I am not sure how to deal(?) with class Walker.
// The Nature of Code
// Daniel Shiffman
// http://natureofcode.com
let walker;
function ...
0
votes
0
answers
35
views
Using var to refer to a constructor in javascript [duplicate]
I have a code with constructor for each letter of the alphabet.
so if i say new A (x,y,w,h) I can create a new A which will draw itself on the canvas.
Is there a way to automate this process in ...
1
vote
1
answer
123
views
Accessing class property always returns false in P5JS
I have a game in P5.JS that i want to pause. Most of my code is in a class. This class has a isPaused field that is set to false in the constructor. Now, i have a button that flips this value, like ...
4
votes
2
answers
166
views
Referencing different objects in a class depending on user input
I'm trying to create a very basic physics simulation in p5.js and I am using a class to create multiple instances of the shapes (which are currently all circles), I have a function that checks if the ...
1
vote
1
answer
723
views
Collision detection of array objects
I'm making a small game in p5.js and when the avatar hits a specific object that object needs to trigger a specific scene. The object in questions are 4 hourglasses contained in an array, how do I &...
0
votes
2
answers
350
views
I can't rotate my square towards the mouse p5.js, keeping it in the center
Well, I am making a tank game. In this very basic question(hoping it'll be a basic answer) all I wanna know how to do is, pointing my tank towards my mouse. The code in my Tank class is:
class Tank { ...
0
votes
1
answer
317
views
p5 Uncaught (in promise) Error when instantiating an object inside another class
I keep getting an error pointing to a line where I create an instance of a class within another class.
character = new Character(x, y, this.speed);
The error says "sketch.js:33 Uncaught (in ...
0
votes
2
answers
1k
views
p5.js repetition of the same function
I am learning p5.js and I don't quite understand how to repeat my function on the y-axis so that the lines appeared on top of the other. I understand that I would need to make a class object but all ...
0
votes
1
answer
318
views
Create a class that draws lines between points created by another class
I'm making a program that animates bezier curves with p5.js. I've created this program already once but this time I'm refining it. (I'm basically copying Jason Davies work here) I want to be able to ...
0
votes
1
answer
693
views
p5.js script failing with empty variable?
I am so close to completing a script that I have been battling now for 2 months. (p5.js graphic)
Here is my problem:
I have a variable that is supposed to be updated based on a dropdown selection.
...
1
vote
1
answer
55
views
Using object trails and pixel data together , not getting what I hoped for?
I'm a very new coder, honestly confused most of the time, Any advice would be great. I was doing an exercise from Dan Shiffman vids. I’m trying to paint a line or a stroke with pixel data from a live ...
3
votes
3
answers
312
views
JS maximum call stack exceeded P5
I am trying to make program to count the biggest color connected blocks in p5.js. The problem is that when I call recursively the box neighbours it gives - "The maximum call stack exceed" and I know ...
0
votes
1
answer
192
views
Objects not shown on screen & keyPressed not working (Flappy Bird Code Challenge)
I created flappy bird game following The Coding Train's tutorial on Youtube.
(https://www.youtube.com/watch?v=cXgA1d_E-jY)
The original instruction created pipes and ball as objects, but I modified ...
-1
votes
1
answer
46
views
How to fix Ball class not appearing everytime i click the mouse [closed]
I want to create a new ball everytime i click the mouse, but nothing is appearing. I have a class named Ball in another file. I got it to work by hard coding how many balls i want to appear, but i ...
2
votes
2
answers
791
views
variable is not changing properties inside a class
I'm making a ball class / object that bounces around like the DVD screen thing. But when the balls hit the edge the variable that controles their X and Y speeds dont change.
I've already tried ...
0
votes
1
answer
124
views
Maximum call size exceeded when running setter
I'm coding a version of a board game for a personal project with p5.js being my way of outputting graphics. I have a class that's making objects that correspond to spaces on my board. These squares ...
0
votes
1
answer
239
views
Why is my animation not working now that I've added counter variable and Intervals?
I have an animation function within a class.
The animation is of a tree 'shuddering' back and forth quickly along the x axis as if struck by an axe.
What I'd like to happen:
When I click on the ...
1
vote
1
answer
201
views
Calling a class in p5 that won't loop?
I’m currently working on a game with p5 which will include some pretty complicated stuff… at least for me anyway.
How do I call a class without it looping in p5?
Consider my following code:
...
-1
votes
1
answer
164
views
This code keeps returning Ball is not defined
let ball;
// declared
function setup(){
createCanvas(500, 500);
ball = new Ball ();
// this is the problem keeps saying ball is not defined
// i have defined it
// can anyone point ...
2
votes
1
answer
1k
views
How do you redraw an object created from a class in p5.js javascript
I have a class which draws a tree, however I would like to be able to draw another tree when the mouse is pressed, however I can't currently as redraw(); simply adds a tree on top of the current ...
1
vote
1
answer
381
views
Issue using getters and setters in p5.js javascript class, "Script error. (: line 0)"
I have created a class which takes in an array of vector coordinates, and then sketches leafs where those coordinates are. I am writing a getter and a setter where you can change the colour of these ...
0
votes
1
answer
389
views
Is this syntax for this class correct, not working correct, Script error. (: line 0) (javascript p5.js)
I am creating a class which takes an array of vectors, and then draws a leaf on the coordinates of each of the items in the array. I have wrote a class to achieve this, which takes the array of ...
0
votes
1
answer
117
views
Cant correctly turn this set of functions into a working class (p5.js)
I am turning a set of functions which create a tree into a class, however where the functions create a large branched out tree, the class version is not correctly sketching the tree as it does in the ...
0
votes
1
answer
253
views
Javascript p5.js class not drawing correctly
I have created a javascript class for a tree object, which when the .draw method is called, the program should generate a leafless tree, however currently the program constantly draws a single branch ...
0
votes
1
answer
1k
views
Trying to understand and get classes to work for p5.js
I am trying to learn how to use classes to make my code reusable. I have began by trying to create a background class which should, when the draw method is called, generate a background, however at ...
1
vote
0
answers
27
views
All objects' properties modified instead of one in 2d array [duplicate]
I'm trying to recreate Tetris in P5.js. I want my shape that falls to pass on its coordinates once it has reached the bottom. I want to pass on the object x/y coordinates (translated into indexes) to ...
0
votes
1
answer
340
views
Swap image using setInterval() with class – p5.js
I'm working on a project on p5.js
My goal is to swap image every X seconds as I did in this example here.
The problem is that when I try to do the same with a class object, setInterval() doesn't ...
1
vote
1
answer
569
views
p5.js classes (class "example" is not changing my this.x value)
I want to move an ellipse but I am stuck because my this.x value isn't changing... print("hit this.y = 30"); is working just fine but this--; is not working. Is anything blocking it? Thank you in ...
1
vote
2
answers
193
views
Trying to retrieve an object's color from an array
So I've been at this for hours and my brain is fried so I could use a bit of assistance.
I need to take the color value from the most recently added object in an array and use it for a separate ...
1
vote
2
answers
3k
views
Accessing a class function with array of objects
I was coding in p5.js, and I noticed a problem that I couldn't pass.
I have a class named "Boxes". I am already using the functions that "Boxes" have. But while I tried to use that functions apply to ...
0
votes
1
answer
76
views
Passing values into p5's canvas, instancing
Let's say I have several p5 canvases on one page, and I've chosen to use instancing to split them up. Because many of the methods will perform the same operations, I've made a superclass. It looks ...