Andreas K.
- Forum-Beiträge: 36
08.07.2013, 19:44:35 via Website
08.07.2013 19:44:35 via Website
Hallo,
ich habe ein Projekt, bei der eine Box über Hindernisse hüpfen soll. Das Problem ist, dass die Box bei verschiedenen Display Größen unterschiedlich weit hüpft. Habe natürlich alles in Abhängigkeit der Display Größe programmiert.
Das Beispiel ist in Processing programmiert. DisplayWidth=width und DisplayHeight=height sind die ermittelten Display Größen:
int rgb1, rgb2, rgb3;
float x, y, w, h, position, oben, unten, velocity, a, yy2;
int ltime, ctime;
float etime;
float jumc, inc;
boolean jumping;
float boxwidth, boxheight;
int MAX_INCR = 15;
void setup() {
size(displayWidth, displayHeight);
//size(800, 600);
// These don't change over time and are already global, so can be moved safely here
boxwidth=width*0.02;
boxheight=width*0.02;
oben=height*0.35-boxheight;
unten=height*0.7-boxheight;
rgb1=247;
rgb2=234;
rgb3=112;
x=0.7*width;
y=0.5*height;
w=0.05*width;
h=height;
inc = (PI / width) * 10.0 * w / MAX_INCR;
println(w + " " + inc);
}
void draw() {
// background(0);
rect(x, y, w, h);
//speed=0.019*width;
//i=i+speed;
velocity=width*0.007;
ctime = millis();
etime = (ctime - ltime)/10;
ltime = ctime;
position += velocity*etime;
//a = a + inc;
if (mousePressed && !jumping) jumping = true;
if (jumping)
{
jumc += 1;
if (a > PI) {
jumping = false;
a = 0;
jumc = 0;
}
yy2 = unten - abs(sin(a)) * height * 0.25;
println(yy2);
//yy2=unten+sin(a)*210.0;1
a += inc;
} else {
yy2 = unten;
a = 0;
}
rect(position, yy2, boxwidth, boxheight);
if (position > width) position = 0;
}
ich habe ein Projekt, bei der eine Box über Hindernisse hüpfen soll. Das Problem ist, dass die Box bei verschiedenen Display Größen unterschiedlich weit hüpft. Habe natürlich alles in Abhängigkeit der Display Größe programmiert.
Das Beispiel ist in Processing programmiert. DisplayWidth=width und DisplayHeight=height sind die ermittelten Display Größen:
int rgb1, rgb2, rgb3;
float x, y, w, h, position, oben, unten, velocity, a, yy2;
int ltime, ctime;
float etime;
float jumc, inc;
boolean jumping;
float boxwidth, boxheight;
int MAX_INCR = 15;
void setup() {
size(displayWidth, displayHeight);
//size(800, 600);
// These don't change over time and are already global, so can be moved safely here
boxwidth=width*0.02;
boxheight=width*0.02;
oben=height*0.35-boxheight;
unten=height*0.7-boxheight;
rgb1=247;
rgb2=234;
rgb3=112;
x=0.7*width;
y=0.5*height;
w=0.05*width;
h=height;
inc = (PI / width) * 10.0 * w / MAX_INCR;
println(w + " " + inc);
}
void draw() {
// background(0);
rect(x, y, w, h);
//speed=0.019*width;
//i=i+speed;
velocity=width*0.007;
ctime = millis();
etime = (ctime - ltime)/10;
ltime = ctime;
position += velocity*etime;
//a = a + inc;
if (mousePressed && !jumping) jumping = true;
if (jumping)
{
jumc += 1;
if (a > PI) {
jumping = false;
a = 0;
jumc = 0;
}
yy2 = unten - abs(sin(a)) * height * 0.25;
println(yy2);
//yy2=unten+sin(a)*210.0;1
a += inc;
} else {
yy2 = unten;
a = 0;
}
rect(position, yy2, boxwidth, boxheight);
if (position > width) position = 0;
}
Empfohlener redaktioneller Inhalt
Mit Deiner Zustimmung wird hier ein externer Inhalt geladen.
Mit Klick auf den oben stehenden Button erklärst Du Dich damit einverstanden, dass Dir externe Inhalte angezeigt werden dürfen. Dabei können personenbezogene Daten an Drittanbieter übermittelt werden. Mehr Infos dazu findest Du in unserer Datenschutzerklärung.