jeudi 5 janvier 2017

AS3 Flixel How to limit the display to a rectangle/viewport

I have a 4 different FlxTileMaps in my GameState class. exteriorMap, exteriorWalk, interiorMap, & interior walk. So while hero is outside interiorMap is invisible and enteriorMap is visible and vise versa. My interiorMap holds all of the rooms. I need to limit the display to a single room. Also, my room variables are stored in an XML file, such as: startX, startY, endX, endY.

This is the opposite of the result that I want: 1

I have the current room highlighted with a sprite. I want to use that as a mask for a camera curtain.

This is the code:

 public override function update():void
 {
 ...
if(activeLayer == 2)
        {
            FlxG.camera.follow(hero);

            //roomCurtain.makeGraphic(mapSet.intMap.width, mapSet.intMap.height, 0xFFbb0000);
            //roomCurtain.scrollFactor.x = 0;
            //roomCurtain.scrollFactor.y = 0;

            roomOutline.x = mapSet.rooms[currentRoom].startX*16;
            roomOutline.y = mapSet.rooms[currentRoom].startY * 16;

            roomOutline.makeGraphic(
            (mapSet.rooms[currentRoom].endX - mapSet.rooms[currentRoom].startX)*16, 
            (mapSet.rooms[currentRoom].endY - mapSet.rooms[currentRoom].startY)*16, 
            0x22bbFFFF);

            //roomResult.makeGraphic(FlxG.stage.stageWidth, FlxG.stage.stageHeight, 0xFFbb0000);

            //FlxDisplay.alphaMaskFlxSprite(roomCurtain, roomOutline, roomResult);

            roomCurtain.visible = true;             
            roomOutline.visible = true;}

public override function update():void
{

...

if(activeLayer == 2)
        {
            FlxG.camera.follow(hero);

            roomCurtain.makeGraphic(mapSet.intMap.width, mapSet.intMap.height, 0xFFbb0000);
            //roomCurtain.scrollFactor.x = 0;
            //roomCurtain.scrollFactor.y = 0;

            roomOutline.x = mapSet.rooms[currentRoom].startX*16;
            roomOutline.y = mapSet.rooms[currentRoom].startY * 16;

            roomOutline.makeGraphic(
            (mapSet.rooms[currentRoom].endX - mapSet.rooms[currentRoom].startX)*16, 
            (mapSet.rooms[currentRoom].endY - mapSet.rooms[currentRoom].startY)*16, 
            0x22bbFFFF);

            roomResult.makeGraphic(FlxG.stage.stageWidth, FlxG.stage.stageHeight, 0xFFbb0000);

            FlxDisplay.alphaMaskFlxSprite(roomCurtain, roomOutline, roomResult);

            roomCurtain.visible = true;             
            roomOutline.visible = true;}

Removing commenting produces this:

2

I'm a bit unsure of how this alphaMaskFlxSprite works. I was also thinking that FlxTileMap might be able to only generate tiles within the room's coordinates.

Aucun commentaire:

Enregistrer un commentaire