-
Notifications
You must be signed in to change notification settings - Fork 0
Drawing
Rijam edited this page Aug 2, 2024
·
2 revisions
In this example, we have two glow masks that we want to draw on top of our Town NPC; one of which should only be drawn while our Town NPC is attacking.
For this guide, we will be using these sprites
TutorialTownNPC_GlowMask
TutorialTownNPC_GlowMaskAttacking 
// Load our textures
private readonly Asset<Texture2D> glowMask = ModContent.Request<Texture2D>("TownNPCGuide/Content/NPCs/TownNPCs/Advanced/TutorialTownNPC_GlowMask");
private readonly Asset<Texture2D> glowMaskAttacking = ModContent.Request<Texture2D>("TownNPCGuide/Content/NPCs/TownNPCs/Advanced/TutorialTownNPC_GlowMaskAttacking");
public override void PostDraw(SpriteBatch spriteBatch, Vector2 screenPos, Color drawColor) {
// Flip the glow mask to match which direction the Town NPC is facing.
SpriteEffects spriteEffects = NPC.spriteDirection > 0 ? SpriteEffects.FlipHorizontally : SpriteEffects.None;
// Draw our glow mask in full bright.
Color color = Color.White;
// Move the position up by 4 pixels plus the gfxOffY value (that is for climbing half blocks).
// Main.NPCAddHeight() makes it so if the Town NPC is sitting, it also moves the glow mask up by 4 more pixels.
Vector2 verticalOffset = new(0, -4 + NPC.gfxOffY + Main.NPCAddHeight(NPC));
// Draw our glow mask
spriteBatch.Draw(glowMask.Value, NPC.Center - screenPos + verticalOffset, NPC.frame, color, NPC.rotation, NPC.frame.Size() / 2f, NPC.scale, spriteEffects, 1f);
// Only draw our extra attacking glow mask while attacking, which are frames 21+
if (NPC.frame.Y > 20 * NPC.frame.Height) {
spriteBatch.Draw(glowMaskAttacking.Value, NPC.Center - screenPos + verticalOffset, NPC.frame, color, NPC.rotation, NPC.frame.Size() / 2f, NPC.scale, spriteEffects, 1f);
}
}- Previous page: ITownNPCProfile
- Next page: AI
Basic Guides
Intermediate Guides
Advanced Guides
- Preliminaries and What are Town NPCs?
- Spriting
- Create Your Town NPC's Class
- Spawn Condition
- Names
- Chat
- Buttons
- Shop
- Attacking
- Bestiary
- Happiness
- Profile
- Gore
- Misc
- Editing Vanilla NPCs with Global NPC