Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

better warnings for invalid width/height args #2762

Merged
merged 4 commits into from
Mar 30, 2023

Conversation

Geokureli
Copy link
Member

Previously

  • if someone passes invalid width/height args into loadGraphic, it may not create any frames, even if the height is off by one and it wont log a warning.
  • If they call animation.add with frame indices higher than the sprite's total number of frames, it won't add those frames and it wont log a warning.
  • If they call animation.add with no valid frame indices, it won't create the animation, and it won't log a warning.
  • If they try to play an animation that doesn't exists it would log: No animation called "$name"

This caused issued where people with incorrect width/height args would get warnings when trying to play anims, and they have no idea why.

Now

  • It will log a warning when the desired frameHeight/frameWidth is too big
  • It will log a warning when an animation is given an invalid frame
  • It will log a warning when they try to make an animation with no valid frames

Example:

import flixel.FlxSprite;
import openfl.display.BitmapData;

class InvalidFrameSizeTestState extends flixel.FlxState
{
	override function create()
	{
		super.create();
		
		final size = 100;
		
		// works fine
		testLoadGraphic(size * 12, size, size, size);
		
		
		/* Warnings:
		 * frameHeight:100 is larger than the graphic's height:99
		 * Could not create animation: a, this sprite has no frames
		 * Could not create animation: b, this sprite has no frames
		 * Could not create animation: c, this sprite has no frames
		 * No animation called "a"
		 * No animation called "b"
		 * No animation called "c"
		 */
		testLoadGraphic(size * 12, size - 1, size, size);
		
		/* Warnings:
		 * Could not add frames above 5 to animation: b
		 * Could not create animation: c, no valid frames were given
		 * No animation called "c"
		 */
		testLoadGraphic(size * 6, size, size, size);
		
	}
	
	function testLoadGraphic(bitmapWidth:Int, bitmapHeight:Int, frameWidth:Int, frameHeight:Int)
	{
		final bmd = new BitmapData(bitmapWidth, bitmapHeight, false);
		final sprite = new FlxSprite();
		sprite.loadGraphic(bmd, true, frameWidth, frameHeight);
		sprite.animation.add("a", [ 0,  1,  2,  3]);
		sprite.animation.add("b", [ 4,  5,  6,  7]);
		sprite.animation.add("c", [ 8,  9, 10, 11]);
		
		sprite.animation.play("a");
		sprite.animation.play("b");
		sprite.animation.play("c");
	}
}

@Geokureli Geokureli merged commit b1e58b3 into HaxeFlixel:dev Mar 30, 2023
@Geokureli Geokureli deleted the anim_warnings branch May 1, 2023 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant