Sprite jittering in Flash/HTML5 targets when using auto-scrolling

  • Hi there!

    I'm having some jittering issues with my Flash and HTML5 builds, with a really lean and simple code. I was having this problem with a bigger project, so I reduced it to the bare bones to try to find what was happening. Here, the player is just a FlxSprite moving at a constant speed, while the camera follows an invisible object (a Gradius-like camera). Surprisingly, this works great in Neko / Windows targets.

    Here's the full code:

    override public function create():Void
    	var loader:FlxOgmoLoader = new FlxOgmoLoader(AssetPaths.level1__oel);
    	tilemap = loader.loadTilemap(AssetPaths.tiles__png, 16, 16, "tiles");
    	tilemap.setTileProperties(0, FlxObject.NONE);
    	tilemap.setTileProperties(1, FlxObject.NONE);
    	tilemap.setTileProperties(2, FlxObject.ANY);
    	loader.loadEntities(entityCreator, "entities");
    	FlxG.camera.setScrollBounds(0, tilemap.width, 0, tilemap.height);
    	FlxG.worldBounds.set(0, 0, tilemap.width, tilemap.height);
    	cameraGuide = new FlxSprite(FlxG.width / 2, FlxG.height / 2);
    	cameraGuide.makeGraphic(1, 1, 0x00000000);
    	cameraGuide.velocity.x = 50;
    	player.velocity.x = cameraGuide.velocity.x;	
    override public function update(elapsed:Float):Void
    	FlxG.collide(tilemap, player);

    Any ideas why this could be happening?

  • flash and html5 might lag because of a slow computer or too high of a framerate in haxeflixel (HF). try to set the framerate to a lower value. that might work.

  • Maybe you're building in debug mode. Since Flash and HTML5 are normally slow in debug mode, try to build in release mode.

  • @galoyo I tried it in a lot of different computers and it's the same thing. Tried adjusting the framerate just now, and didn't work either...

    @DleanJeans I have tried release mode and it's the same thing.

    It worked alright before 4.x, but now I have this issue...

  • administrators

    The code snippet you posted isn't very useful because it's not compilable / it requires some assets you didn't provide.

  • @Gama11 Oh, sorry. Here's the repo with all the things: https://github.com/TheOneAndTrueAcid/OgmoLoco

  • administrators

    player.pixelPerfectPosition = false; appears to fix it.

  • @Gama11 damn, it works!

    Thanks <3! A lot of my students were having this problem and didn't know how to fix it.

Log in to reply