FlxSprite scale



  • Hi I used flip card animation from Demo but extra I need to zoom up card after flip.
    I have FlxSprite objects with image textures that I load from atlas and set it like this

    var frames: FlxAtlasFrames // 
    this.frames = frames;
    animation.frameName = label;
    updateHitbox();
    

    Also it listener target for FlxMouseEventManager.
    As I need to zoom in to this object I have texture 4x bigger as it is shown on screen initially, so it is not blured when I scale it, at the begining I set scale 0.25 and updated updateHitbox() sprite looked fine on screen but box for listeners is original size so 4x.
    I am doing something wrong?

    Thanx.


  • administrators

    I'm not sure I fully understand your question... You have some issues with incorrect hitbox size after scaling?

    Do you have a more complete code example?



  • Sorry :), I will try to explain better. I made minimal code for first problem:

    package package-to-file;
    
    import flixel.graphics.frames.FlxAtlasFrames;
    import flixel.FlxSprite;
    import flixel.input.mouse.FlxMouseEventManager;
    
    class Card extends FlxSprite {
    	public function new() {
    		super();
            FlxMouseEventManager.add(this , onDown, onUp, onOver, onOut);
            scale.set(0.25, 0.25);
            addTexture();
    	}
    	function addTexture() {
            this.frames = FlxAtlasFrames.fromTexturePackerJson("path-to-atlas.png", "path-to-atla.json");
    		animation.frameName = "filename-from-atlas";
    		updateHitbox();
    	}
            function onDown(target: FlxSprite) {
    		trace("on down");
    	}
    	function onUp(target: FlxSprite) {
    		trace("on up");
    	}
    	function onOver(target: FlxSprite) {
    		trace("on over");
    	}
    	function onOut(target: FlxSprite) {
    		trace("on out");
    	}
    }
    

    This code shows image as it should be 4x smaller but mouse manager functions are called for original size.



  • Just guessing: Maybe you should put

    scale.set(0.25, 0.25);
    

    Right before updateHitbox()


  • administrators

    @Hersir I see.. there's two variants of overlap checks in FlxMouseEventManager. By default, it uses the sprite's graphic, not the hitbox, and is pixel-perfect. Additionally, I don't think it supports scale, so that's probably the issue you're seeing. You could try setting the pixelPerfect argument of FlxMouseEventManager.add() to false to force it to use the hitbox instead.



  • @Gama11 Thx for fast answer. Looks like setting pixelPerfect to false did the trick, it will even work form me as I have almost square objects. So first problem is solved. Second problem is that after setting scale and calling updateHitbox flip animation stoped to work properly.

    public function new() {
    	super();
            FlxMouseEventManager.add(this , onDown, onUp, onOver, onOut,  false,  true,  false);
            scale.set(0.25, 0.25);
            addTexture("back-of-card.png");
    }
    function addTexture(label: String) {
                     this.frames = FlxAtlasFrames.fromTexturePackerJson(
                                 "path-to-atlas.png", "path-to-atla.json"
                     );
    		animation.frameName = label;
    		updateHitbox();
    }
    public function flip() {
    		FlxTween.tween(scale, { x: 0 },  0.1,  { onComplete: onFlipReady });
    }
    function onFlipReady() {
    		addTexture("other-side-of-card.png");
    		FlxTween.tween(scale, { x: 0.25 },  0.1);
    }
    

    Before it was working properly and card was flipped from centre of card, now it flips using left side as centre, so card moves left by half of width after flip tween.



  • Ok flip issue was my error, I called updateHitbox(); after each texture change and after scale tween scale.x was 0 so width was 0.



  • On more thing what I noticed after scale, is that margins between objects became uneven (some rows have bigger margin some smaller, before distance between objects was the same) , do I need to swicth on/off some pixel snapping or there is something more?


Log in to reply
 

Looks like your connection to HaxeFlixel was lost, please wait while we try to reconnect.