Je suis en train de coder un jeu de tir simple dans lequel je veux faire pivoter mon personnage dans la direction de la souris et "tirer". J'ai fait tout le code pour cela, sauf la rotation de l'image réelle. Voici mon code à ce jour: (CECI EST TOUT SOUS LA MÉTHODE DE COMPOSANTS DE PEINTURE)Déplacer et faire pivoter une image simultanément avec AffineTransform
xCent = x + 50;
yCent = y + 50; // x and y center of image (x and y change depending on Keyboard Input)
a.setToRotation(theta, xCent,yCent); // a = new AffineTransform() Here is my calculation of theta (under the MouseMotionListener): theta = Math.atan2(e.getY() - yCent,e.getX() - xCent);
a.setToTranslation(x,y);
a.setToRotation(theta, xCent,yCent);
g2.drawImage(charac,a, null);
Comment dois-je procéder maintenant « réglage » les coordonnées x et y de l'image pour l'objet Graphics2D de le dessiner ??
Désolé, ignorez la dernière a.setToRotation (theta, xCent, yCent); – walthamMichael