프로그램을 특정 FPS로 제한하고 싶습니다. 그렇지 않으면 한 컴퓨터에서 더 빠르게 실행되고 다른 컴퓨터에서는 느리게 실행됩니다. FPSClock = pygame.time.Clock() FPSClock.tick (30)Java 3D에서 사용자 정의 FPS를 설정하는 방법
자바 차원에서이 같은 일이 있나요 -
나는 파이 게임에서 내가 뭔가를 원하는? 저는 Java 3D의 초보자입니다. 기술 향상을 위해 Pong 게임을 쓰려고했습니다. 그러나, 나는 갇혀있어 자바에서 적절한 지연의 방법이 없다는 것을 깨달았습니다. 마지막 프레임의 시간이 어땠는지 알 수 없기 때문입니다.
KeyEvent가 내 코드에서 작동하지 않는다는 것도 발견했습니다. 지금까지 내 코드 -
import com.sun.j3d.utils.universe.*;
import com.sun.j3d.utils.geometry.*;
import javax.media.j3d.*;
import javax.vecmath.*;
import java.awt.event.*;
import java.awt.event.KeyListener.*;
import java.awt.event.WindowAdapter;
import java.awt.*;
import java.applet.Applet;
public class Pong implements KeyListener {
static float ballx = 0.0f;
static float bally = 0.0f;
static float ballz = 0.0f;
static Transform3D transform2 = new Transform3D();
static TransformGroup transformGroup2 = new TransformGroup();
public static void main(String[] args) {
SimpleUniverse universe = new SimpleUniverse();
BranchGroup group = new BranchGroup();
Appearance appearance = new Appearance();
Color3f color = new Color3f(0.1f, 1.8f, 0.1f);
ColoringAttributes coloringAttributes = new ColoringAttributes(color, ColoringAttributes.NICEST);
appearance.setColoringAttributes(coloringAttributes);
Box box = new Box(0.05f, 0.2f, 0.03f, appearance);
Transform3D transform = new Transform3D();
TransformGroup transformGroup = new TransformGroup();
transformGroup.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Vector3f vector = new Vector3f(-0.9f, 0.0f, 0.0f);
transform.setTranslation(vector);
transformGroup.setTransform(transform);
transformGroup.addChild(box);
Box box1 = new Box(0.05f, 0.2f, 0.03f, appearance);
Transform3D transform1 = new Transform3D();
TransformGroup transformGroup1 = new TransformGroup();
transformGroup1.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
Vector3f vector1 = new Vector3f(0.9f, 0.0f, 0.0f);
transform1.setTranslation(vector1);
transformGroup1.setTransform(transform1);
transformGroup1.addChild(box1);
group.addChild(transformGroup);
Sphere sphere = new Sphere(0.1f);
group.addChild(transformGroup1);
Vector3f vector2 = new Vector3f(0.0f,0.0f,0.0f);
transform2.setTranslation(vector2);
transformGroup2.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
transformGroup2.setTransform(transform2);
transformGroup2.addChild(sphere);
Color3f lightColor = new Color3f(1.8f, 1.9f, 0.1f);
BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
Vector3f lightDirection = new Vector3f(4.0f, -7.0f, -12.0f);
DirectionalLight light = new DirectionalLight(lightColor, lightDirection);
light.setInfluencingBounds(bounds);
transformGroup2.addChild(light);
group.addChild(transformGroup2);
Color3f ambientColor = new Color3f(1.0f, 1.0f, 1.0f);
AmbientLight ambientLightNode = new AmbientLight(ambientColor);
ambientLightNode.setInfluencingBounds(bounds);
transformGroup2.addChild(ambientLightNode);
universe.getViewingPlatform().setNominalViewingTransform();
universe.addBranchGraph(group);
}
public void keyPressed(KeyEvent event) {
if (event.getKeyChar() == 'a') {
ballx = ballx 0.1f;
transform2.setTranslation(new Vector3f(ballx, bally, ballz));
transformGroup2.setTransform(transform2);
}
}
public void keyReleased(KeyEvent event) {
}
public void keyTyped(KeyEvent event) {
}
}
감사합니다. 파이썬이 저에게 많은 도움이되었습니다. 모든 컴퓨터에서 60FPS를 기록하는 타이머로 프로그램을 업데이트 할 것입니다. 나는 여전히 문제가 하나 더 있는데, KeyListener와 keyPressed(), keyTyped() 및 keyReleased()를 Pong 클래스에 구현했다. 어떤 오류도 보이지 않고 작동하지도 않습니다. 이 문제에 대한 도움을 주시면 감사하겠습니다. – Thomas