Hello!
I’m trying to implement some new features for PaperTileset class, which is used to create tiles to create PaperTilemaps later on. I’m not sure, but in my mind PaperTileset has shortage of some neccessary functions.
I am trying to create procedural map and thus I need to use code to create my 2D procedural map. However, I can’t even access the tile texture straight from the PaperTileset class.
Instead I need to create UPaperTilemap in UE4 editor, use all the tiles from my tileset there so I could access them in code through the just created tilemap. Then create UPaperTileMapComponent, set this tilemap as its’ tilemap. Finally, I can access my tile textures.
Accessing textures can be seen in this picture below:
My question:
How does FPaperTileInfo hold the texture information of the tile. If I understand this, I could create a getter for getting tile texture directly in the tileset, but it’s too confusing…
I don’ t especially understand the EPaperTileFlags enum, what does it do?
enum class EPaperTileFlags : uint32
{
FlipHorizontal = (1U << 31),
FlipVertical = (1U << 30),
FlipDiagonal = (1U << 29),
TileIndexMask = ~(7U << 29),
};
// This is the contents of a tile map cell
USTRUCT(BlueprintType, meta=(HasNativeBreak="Paper2D.TileMapBlueprintLibrary.BreakTile", HasNativeMake="Paper2D.TileMapBlueprintLibrary.MakeTile"))
struct FPaperTileInfo
{
GENERATED_USTRUCT_BODY()
// The tile set that this tile comes from
UPROPERTY(EditAnywhere, Category=Sprite)
UPaperTileSet* TileSet;
// This is the index of the current tile within the tile set
UPROPERTY(EditAnywhere, Category=Sprite)
int32 PackedTileIndex;
FPaperTileInfo()
: TileSet(nullptr)
, PackedTileIndex(INDEX_NONE)
{
}
inline bool operator==(const FPaperTileInfo& Other) const
{
return (Other.TileSet == TileSet) && (Other.PackedTileIndex == PackedTileIndex);
}
inline bool operator!=(const FPaperTileInfo& Other) const
{
return !(*this == Other);
}
bool IsValid() const
{
return (TileSet != nullptr) && (PackedTileIndex != INDEX_NONE);
}
inline int32 GetFlagsAsIndex() const
{
return (int32)(((uint32)PackedTileIndex) >> 29);
}
inline void SetFlagsAsIndex(uint8 NewFlags)
{
const uint32 Base = PackedTileIndex & (int32)EPaperTileFlags::TileIndexMask;
const uint32 WithNewFlags = Base | ((NewFlags & 0x7) << 29);
PackedTileIndex = (int32)WithNewFlags;
}
inline int32 GetTileIndex() const
{
return PackedTileIndex & (int32)EPaperTileFlags::TileIndexMask;
}
inline bool HasFlag(EPaperTileFlags Flag) const
{
return (PackedTileIndex & (int32)Flag) != 0;
}
inline void ToggleFlag(EPaperTileFlags Flag)
{
if (IsValid())
{
PackedTileIndex ^= (int32)Flag;
}
}
inline void SetFlagValue(EPaperTileFlags Flag, bool bValue)
{
if (IsValid())
{
if (bValue)
{
PackedTileIndex |= (int32)Flag;
}
else
{
PackedTileIndex &= ~(int32)Flag;
}
}
}
};
If you need any more information, feel free to mention it.
Thanks in advance!