Pending-Name-21 / frontend-library

This library allows the game developer to write games.
0 stars 0 forks source link

Sprites blinking and visual glitch when multiple are rendered #38

Open victor-villca opened 2 months ago

victor-villca commented 2 months ago

Expected Behavior

Multiple sprites should render and animate smoothly on the screen without any visual glitches or unexpected movements.

Current Behavior

When more than one sprite is rendered on the screen, the sprites start to blink and move erratically, as if they were teleporting. This issue does not occur when only one sprite is rendered.

Possible Solution

The issue might be related to how sprite rendering is handled for multiple objects. Possible solutions could include:

Steps to Reproduce

  1. Run the game/application
  2. Add more than one sprite to the screen
  3. Observe the sprites' behavior

Context (Environment)

This issue is preventing the proper display and animation of multiple sprites when working on user: #244

Detailed Description

When a single sprite is rendered on the screen, it behaves as expected with smooth movement and animation. However, as soon as additional sprites are added to the scene, all s prites begin to exhibit erratic behavior. They appear to blink in and out of existence and move in a disjointed manner, giving the impression of teleportation rather than fluid motion.

A video demonstrating this issue will be attached to provide a visual representation of the problem. Screencast from 04-07-24 06:36:38.webm

Another video demonstrating this issue when collision: Screencast from 04-07-24 07:22:00.webm

zrock-dev commented 2 months ago

I have updated the code of one of the tests and now the glitch seems to be gone.

    @Test
    void VerifyGameOverMessageWhenGhostAndPacmaTheyCollideTest() {
        String projectPath = Paths.get("").toAbsolutePath().toString();
        Game game = new Game(new AGameSettings() {
            @Override
            public boolean isGameOver() {
                return false;
            }
        });

        SpriteBuilder builder = new SpriteBuilder(game.getSpriteIRepository());
        Sprite ghost = makeSprite(builder, projectPath + "/src/test/resources/ghost.png", 0, 80);
        Sprite pacman = makeSprite(builder, projectPath + "/src/test/resources/pacman.png", 80, 80);

        IUpdateSubscriber updateSubscriber = new IUpdateSubscriber() {
            private int i = 0;

            @Override
            public void notifySubscriber() {
                ghost.setPosition(new Coord(i++, 80));
                i++;

                if (Math.abs(pacman.getPosition().getX() - ghost.getPosition().getX()) < 20 && Math.abs(pacman.getPosition().getY() - ghost.getPosition().getY()) < 20) {
                    Sprite gameover = makeSprite(builder, projectPath + "/src/test/resources/gameover.png", 0, 0);
                    gameover.setZ_index(1);
                    assertTrue(true);
                }
                System.out.printf("Ghost is at %d,%d", ghost.getPosition().getX(), ghost.getPosition().getY());
            }
        };

        game.getUpdatePublisher().subscribe(updateSubscriber);
        try {
            game.run();
        } catch (GameException e) {
            fail(e);
        }

    }

Kooha-2024-07-05-03-22-48.webm