🔧 Programmierung 🕛 vor 2 Monaten 9 Min Lesezeit
0

Build Games In Java: Sprites, Box2D Physics And Low-Latency Sound

↗ Quelle (dev.to)
🗣️ Stimme:
📑 Inhaltsübersicht

, among others), so this was never about disinterest or not understanding the domain. The opposite: I knew exactly how much a real gaming stack demands, and I felt that tackling it would dilute our focus on being the best cross-platform app framework. But at the rate we have been building up Codename One lately, it has become a manageable and realistic target.



What is Codename One? Codename One is an open-source framework for building native iOS, Android, desktop, and web apps from a single Java or Kotlin codebase. Learn more at , we can solve most of those core problems while giving indie developers a royalty-free platform for their games. No engine fees, no revenue share, no install-time runtime: Java in, native game out.



So here it is. and the existing media and animation systems, rather than replacing any of them.



Judging by



The view drops into a normal form like any component:




CODE
Form f = new Form("Gaming Demo", new BorderLayout());
PhysicsDemoView game = new PhysicsDemoView();
f.add(BorderLayout.CENTER, game);
f.show();
game.start();









The game loop



GameView drives its loop through the existing animation system, so it cooperates with the rest of the UI instead of fighting it. It manages the frame rate while running and restores the global value when it stops, and it releases everything automatically when the view is detached from the form.



For deterministic simulation there is a fixed-timestep mode: set setFixedTimestep(1.0 / 60) and update is called with exactly that delta as often as needed, with getInterpolationAlpha() available for smooth rendering between simulation steps. This is the standard pattern for physics-driven games, and it is one method call here.



Input is pollable, the way game code wants it. getInput() exposes level state (isKeyDown, isPointerDown, getPointerX/Y) and per-frame edges (wasKeyPressed, wasPointerPressed), aware of game actions (fire, directional pad) across platforms. No listeners, no event-versus-frame mismatch: you ask, every frame, and act.






Sprites and scenes



Sprite carries position, anchor, rotation, scale, and alpha, plus an axis-aligned bounding box for simple overlap tests. SpriteSheet slices a packed texture into cached frames, AnimatedSprite plays them back, and Scene holds everything in z-order with a camera, so scrolling a level means moving the camera and not repositioning the world.



It matters where those sprites run. GameView extends the RenderView from 's rigid-body engine, the one behind an entire generation of 2D hits, and is an arena collector: pilot a ship around a starfield with the on-screen joystick, scoop up spinning gems, dodge drifting asteroids. It exercises the breadth of the 2D layer: many sprites in one Scene, per-sprite animation, particle bursts, collision, and a TouchControls joystick that drives the same GameInput a keyboard would.



is the side-scroller hello world: run, jump, collect coins. The Scene camera follows the player so the level slides past, an AnimatedSprite walk cycle flips to face the run direction, and a cheap parallax backdrop (fixed sun, drifting clouds, half-speed hills) sells the depth. Its gravity is a few hand-rolled lines, proof you don't need the physics engine for a platformer feel.



is Memory (Concentration): a sprite per card, a horizontal flip animation that swaps the face at the midpoint, tap hit-testing through GameInput, and a small game state machine. The structure transfers directly to any card or tile game.



is checkers against a small built-in AI, on an isometric board. Every tile and piece is a flat Sprite, but the 2:1 diamond projection and raised pieces give a convincing 3D look with no camera or models, the classic "faux 3D" trick, and the cell-to-pixel mapping it demonstrates underlies every isometric game.



crosses into real 3D: a lit, spinning model on a ground plane, a ring of billboarded coin sprites that always face the orbiting perspective camera, and touch controls, in about two hundred lines.



is the physics demo this post opened with: Box2D bodies, linked sprites, and a SoundPool blip whose pitch varies per drop.






Where to go from here



The new that walk through the card game and the isometric checkers above section by section.



If you build something with this, we genuinely want to see it, and if you hit a wall, this is built on, and the release post has the full index. Your Java becomes a native Windows executable with no JVM in .

Vollständiger Original-Artikel
Den kompletten Beitrag mit allen Details direkt auf dev.to lesen.
↗ Original-Artikel auf dev.to lesen
Wie bewertest du diesen Beitrag?
1 Klick Feedback
Teilen mit Netzwerk & Team:

Community-Analysen & Experten-Meinungen 0

Verfasse deine eigene Analyse, teile Workarounds oder diskutiere diesen Vorfall im Blog.
Noch keine Community-Analyse verfasst. Markiere einen Textabschnitt oder klicke oben auf Eigene Analyse verfassen“!
Community Pulse: Relevanz-Einschätzung
1 Klick Experten-Votum
🔴 Akute Relevanz 0%
🟡 In Evaluierung 0%
🟢 Keine Auswirkung 0%
Spannende Innovation 0%
Verwandte Story-Cluster & Quellen (Vektor-KI)
Port 8095 Engine
6 Quellen
CVE-2022-44255 | TOTOLINK LR350 9.3.5u.6369_B20220309 buffer overflow (EUVD-2022-47204)
2 Quellen
CVE-2026-68426 | Linux Kernel up to 6.18.41/7.1.5/7.2-rc3 xfrm validate_xmit_skb_list use after free (Nessus ID 346426)
1 Quelle
Windows 11 Probleme mit gültiger Domänenanmeldung nach September-Update [Workaround]
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Build Games In Java: Sprites, Box2D Physics And Low-Latency Sound

Thematisch verwandte Begriffe: Build, Games, Java, Sprites · 6 Treffer

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...