-
Notifications
You must be signed in to change notification settings - Fork 139
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
Add support for clipRects to FlxTiledSprite. #421
Add support for clipRects to FlxTiledSprite. #421
Conversation
forgot this, i'll test this out tomorrow |
override function set_clipRect(Value:FlxRect):FlxRect | ||
{ | ||
if (Value != clipRect) | ||
regen = true; | ||
|
||
return super.set_clipRect(Value); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
override function set_clipRect(Value:FlxRect):FlxRect | |
{ | |
if (Value != clipRect) | |
regen = true; | |
return super.set_clipRect(Value); | |
} | |
override function set_clipRect(value:FlxRect):FlxRect | |
{ | |
regen = true; | |
return super.set_clipRect(value); | |
} | |
couple things
- use lower case arg names
- regen even if the same rect instance is set. one common way to use this is
sprite.clipRect.width = 100;
sprite.clipRect = sprite.clipRect;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this doesn't seem to work right. In addition to the change I requested above, it behaves in unexpected ways here:
Screen.Recording.2024-06-11.at.11.28.31.PM.mov
notice that the bottom is cut off, and it tiles above when rect.y=-50 and height=200. I wasn't expecting it to tile above, but I was expecting it to look identical to the initial state in the vid
Here is my test case (it requires the above change to work):
package states;
import flixel.text.FlxText;
import flixel.math.FlxRect;
import flixel.addons.display.FlxTiledSprite;
import flixel.FlxG;
class TiledSpriteTestState extends flixel.FlxState
{
var sprite:FlxTiledSprite;
var text:FlxText;
var toggled = true;
override function create()
{
super.create();
sprite = new FlxTiledSprite("assets/images/haxe.png", 200, 100);
sprite.clipRect = FlxRect.get(25, 0, 150, 100);
sprite.screenCenter();
add(sprite);
text = new FlxText("");
updateText();
add(text);
}
function updateText()
{
text.text = sprite.clipRect.toString();
text.screenCenter();
text.y += 100;
}
override function update(elapsed)
{
super.update(elapsed);
if (FlxG.keys.justPressed.SPACE)
{
sprite.clipRect = toggled ? sprite.clipRect.set(0, 0, 200, 100) : sprite.clipRect.set(25,-50,150,200);
toggled = !toggled;
updateText();
}
}
}
Adds the ability to clip
FlxTiledSprites
inside a rectangle by assigning theclipRect
.