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

Add support for clipRects to FlxTiledSprite. #421

Conversation

EliteMasterEric
Copy link

Adds the ability to clip FlxTiledSprites inside a rectangle by assigning the clipRect.

@Geokureli
Copy link
Member

forgot this, i'll test this out tomorrow

Comment on lines +110 to +117
override function set_clipRect(Value:FlxRect):FlxRect
{
if (Value != clipRect)
regen = true;

return super.set_clipRect(Value);
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

  1. use lower case arg names
  2. regen even if the same rect instance is set. one common way to use this is
sprite.clipRect.width = 100;
sprite.clipRect = sprite.clipRect;

Copy link
Member

@Geokureli Geokureli left a 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();
        }
    }
}

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.

2 participants