Loading...
Processing Forum
Recent Topics
All Forums
Screen name:
myxomatosis
myxomatosis's Profile
1
Posts
1
Responses
0
Followers
Activity Trend
Last 30 days
Last 30 days
Date Interval
From Date :
To Date :
Go
Loading Chart...
Posts
Responses
PM
Show:
All
Discussions
Questions
Expanded view
List view
Private Message
OOP Help
[2 Replies]
08-Sep-2011 09:47 AM
Forum:
Programming Questions
Hey guys, NewB to Processing with an issue. I'm trying to play with OOP, but my objects aren't acting separately. Specifically they aren't moving at their own individual speeds. Thoughts? I'm hoping this is the appropriate way to post code in here:
Cube myCube1;
Cube myCube2;
void setup() {
size(1000, 1000, P3D);
myCube1 = new Cube(color(15, 15, 100, 100),500,500,0,2,0,0);
myCube2 = new Cube(color(15, 15, 100, 100),250,250,0,-2,0,0);
}
void draw() {
background(0);
myCube1.slide();
myCube1.display();
myCube2.slide();
myCube2.display();
}
class Cube {
color c;
float Xpos;
float Ypos;
float Zpos;
float Xspeed;
float Yspeed;
float Zspeed;
Cube(color tempC, float tempXpos, float tempYpos, float tempZpos, float tempXspeed, float tempYspeed, float tempZspeed) {
c = tempC;
Xpos = tempXpos;
Ypos = tempYpos;
Zpos = tempZpos;
Xspeed = tempXspeed;
Yspeed = tempYspeed;
Zspeed = tempZspeed;
}
void display() {
stroke(175);
fill(c);
translate(Xpos, Ypos, Zpos);
box(50);
}
void slide() {
Xpos = Xpos + Xspeed;
if (Xpos+25 > width) {
Xspeed = -Xspeed;
}
if (Xpos-25 < 0) {
Xspeed = -Xspeed;
}
}
}
«Prev
Next »
Moderate user : myxomatosis
Forum