AS3 Sprite Sheets

后端 未结 2 1521
离开以前
离开以前 2020-12-15 02:02

I have an image mySprite.png. The image is a 5x5 grid of 32x32 px sprites. This image has been loaded into the project\'s library.

Assuming I have a render() functio

2条回答
  •  离开以前
    2020-12-15 02:30

    Another possible method would be to put a 32x32 mask over the sheet and just move the sheet around.

    It would work something like (pseudo-code):

    var spriteMask:Sprite = new Sprite();
    spriteMask.graphics.drawRect(0,0,32,32);
    spriteSheetContainer.mask = spriteMask;
    
    function render():void {    // this function is on the container of the sprite sheet (spriteSheetContainer in this example)
        // run offsetX & Y iteration logic.  I would assume something that uses a frame counter, modulus, and the sprite layout grid dimensions
        _spriteSheet.x = offsetX;    // move the sprite around under the mask
        _spriteSheet.y = offsetY;
    }
    

    It's crucial to have the mask on a container of the sprite sheet and not the sprite sheet itself, so that you can move the sprite sheet independent of the mask.

提交回复
热议问题