From d0019ee45a89aebfc1da2ba8e9fa1cd27621e29f Mon Sep 17 00:00:00 2001 From: Federico Magnani Date: Sun, 24 Nov 2024 15:35:30 +0100 Subject: [PATCH 1/2] [Fix] Fixed minor issue Window position (posx, posy) is now global, rather than being initialized inside ofApp::update (which led to a bug) --- .../windowing/windowExample/src/ofApp.cpp | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/examples/windowing/windowExample/src/ofApp.cpp b/examples/windowing/windowExample/src/ofApp.cpp index 5e4326589fc..fafb15f6070 100644 --- a/examples/windowing/windowExample/src/ofApp.cpp +++ b/examples/windowing/windowExample/src/ofApp.cpp @@ -5,7 +5,9 @@ void ofApp::setup(){ int screenW = ofGetScreenWidth(); int screenH = ofGetScreenHeight(); - ofSetWindowPosition(screenW/2-300/2, screenH/2-300/2); + posx=screenW/2-300/2; + posy=screenH/2-300/2; + ofSetWindowPosition(posx, posy); // load our typeface vagRounded.load("vag.ttf", 16); @@ -24,6 +26,7 @@ void ofApp::setup(){ ballPositionY = 150; ballVelocityX = ofRandom(-5,5); ballVelocityY = ofRandom(-5,5); + } //-------------------------------------------------------------- @@ -39,24 +42,20 @@ void ofApp::update(){ ofShowCursor(); } - ballPositionX += ballVelocityX; ballPositionY += ballVelocityY; - int posx = ofGetWindowPositionX(); - int posy = ofGetWindowPositionY(); - if (ballPositionX < 0){ ballPositionX = 0; ballVelocityX *= -1; if (!bFullscreen){ - ofSetWindowPosition(posx-10, posy); + posx-=10; } } else if (ballPositionX > ofGetWidth()){ ballPositionX = ofGetWidth(); ballVelocityX *= -1; if (!bFullscreen){ - ofSetWindowPosition(posx+10, posy); + posx+=10; } } @@ -64,16 +63,18 @@ void ofApp::update(){ ballPositionY = 0; ballVelocityY *= -1; if (!bFullscreen){ - ofSetWindowPosition(posx, posy-10); + posy-=10; } } else if (ballPositionY > ofGetHeight()){ ballPositionY = ofGetHeight(); ballVelocityY *= -1; if (!bFullscreen){ - ofSetWindowPosition(posx, posy+10); + posy+=10; } } - + + ofSetWindowPosition(posx, posy); + } //-------------------------------------------------------------- @@ -85,6 +86,7 @@ void ofApp::draw(){ // lets show our window pos in pixels // macs actually start the Y pos from 40 vagRounded.drawString("window pos ("+ofToString(ofGetWindowPositionX())+", "+ofToString( ofGetWindowPositionY())+")", 10, 25); + // vagRounded.drawString("window pos ("+ofToString(ballPositionX)+", "+ofToString(ballPositionY)+")", 10, 25); if(!bFullscreen){ vagRounded.drawString("press f to enter fullscreen", -140 + ofGetWidth()/2, ofGetHeight()/2); From f35cd4d9317d2a91668ac172f304cf7cfa2d0c44 Mon Sep 17 00:00:00 2001 From: Federico Magnani Date: Sun, 24 Nov 2024 15:36:43 +0100 Subject: [PATCH 2/2] [Fix] Fixed minor issue Window position (posx, posy) is now global, rather than being initialized inside ofApp::update (which led to a bug) --- examples/windowing/windowExample/src/ofApp.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/windowing/windowExample/src/ofApp.h b/examples/windowing/windowExample/src/ofApp.h index c48421d7970..9e295ff69a3 100644 --- a/examples/windowing/windowExample/src/ofApp.h +++ b/examples/windowing/windowExample/src/ofApp.h @@ -30,5 +30,8 @@ class ofApp : public ofBaseApp{ float ballPositionY; float ballVelocityX; float ballVelocityY; + + float posx; + float posy; };