Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Objekt zur Maus bewegen

Empfohlene Antworten

Veröffentlicht

Nabend,

mir war mal langweilig und ich wollte eine Kleinigkeit in Java Programmieren.

Also dachte ich mir, mach ich mal ein kleines Progrämmchen, wo man mit Maus und Tastatur Objekte steuern kann. Nun will ich sogesehen eine automatische Bewegung des Objektes aufrufen. Sprich: Ich klick irgendwo hin und das jeweilige Objekt läuft dahin.

Die Theorie ist einfach, doch lässt sich nicht so recht umsetzen.

public void changePosition(){

		while(x<m_x){

			player.setLocation(x-50,y);

			x++;

		}

		while(x>m_x){

			player.setLocation(x-50,y);

			x--;

		}

		while(y<m_y){

			player.setLocation(x-50,y-50);

			y++;

		}

		while(y>m_y){

			player.setLocation(x-50,y-50);

			y--;

		}

	}

Das ist vorerst mein Code dafür. m_x und m_y sind die x und x Koordinaten der Maus und das normale x und y, sind für die Koordinaten des Objektes (Höhe und Breite betragen jeweils 100), das bewegt wird. Wie ihr daraus erkennen könnt, wird dann das Objekt direkt am Mauszeige positioniert. Ich will aber, dass das Objekt sich langsam dahinbewegt. Wenn ich den Thread für ein paar Millisekunden stoppe, hängt sich alles auf. Wenn ich einen eigenen Thread für die komplette Abfrage mache, passiert garnichts.

Kann mir dabei vielleicht einer behilflich sein?^^

Gruß

Kaeyu

Ok, hab das Problem gelöst. Mit einem extra Thread funktioniert es, ich hatte nur eine kleine Zeile vergessen zu schreiben^^

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.