Journal

Virtual Pet (Tamagotchi-Style) UI in SwiftUI

A virtual pet lives in real time, so its hunger must grow while the app is closed. The trick is the same one timers use: derive state from elapsed time.

Virtual Pet (Tamagotchi-Style) UI in SwiftUI: a glass iPhone app-grid icon on a mint and teal gradient

TL;DR

A Tamagotchi-style virtual pet has needs like hunger, happiness, and energy that decay over real time, care actions that restore them, and a mood that reflects the result. The key engineering insight is the same as a timer: do not tick needs while the app runs, compute them from the time elapsed since the last interaction, so the pet ages correctly even when the app was closed. Add gentle, non-nagging notifications, build the UI from a free VP0 design, and use your own original creature, not a trademarked one.

Want a virtual pet that genuinely needs you, like a Tamagotchi, in SwiftUI? The short answer: model needs that decay over real time, care actions that restore them, and a mood that shows the result. The one insight that makes it work is borrowed from timers: do not tick hunger while the app is open, compute it from how much time has passed since the last interaction, so the pet ages even when the app was closed. Build the UI from a free VP0 design, the free iOS design library for AI builders, and use your own original creature.

Who this is for

This is for SwiftUI builders who want a charming, sticky little game, and who want the pet’s state to behave correctly over real time rather than resetting every launch or only changing while the app is open.

Needs that live in real time

A virtual pet has a few needs, hunger, happiness, energy, maybe cleanliness, each a value that drops over time. Care actions, feed, play, sleep, restore them, and the combination drives the pet’s mood and animation. The mistake beginners make is decrementing needs on a foreground timer, which freezes the moment the app is backgrounded, so a pet left overnight is somehow fine. The fix is to store the timestamp of the last update and, whenever the app becomes active, compute the decay from the elapsed time, exactly the technique a reliable countdown uses. SwiftUI drives the meters and animation, and gentle local notifications can remind the user their pet needs attention.

PieceApproachGet it right
NeedsDecay over timeCompute from elapsed time
Last updateStored timestampSurvives the app closing
Care actionsFeed, play, sleepRestore needs, with feedback
MoodDerived from needsAnimation reflects state
RemindersLocal notificationsGentle, never nagging

Build it free with a VP0 design

Pick a game or character design from VP0, copy its link, and prompt your AI builder:

Rebuild this VP0 virtual-pet design in SwiftUI: [paste VP0 link]. Model hunger, happiness, and energy that decay over real time, computed from a stored last-update timestamp so the pet changes while the app is closed. Add feed, play, and sleep actions, a mood the animation reflects, and gentle local-notification reminders. Use my own original creature and name.

The format has staying power, the original Tamagotchi sold over 82,000,000 units, proving how compelling a needy little creature can be. For neighboring SwiftUI and game patterns, see a Wordle-style daily word game in SwiftUI, a Sudoku grid generator UI in SwiftUI, a habit tracker source code for the same daily-return care loop, and a Pomodoro timer app in SwiftUI for the elapsed-time technique. For a different sticky genre, see a multiple-choice quiz app UI in React Native.

Gentle, and original

Two things keep this lovable rather than annoying or risky. Gentleness: reminders should nudge, not guilt, so a pet that gets sad is fine but one that dies and shames the user is not the modern, kind version, and the notifications should be infrequent and skippable. Originality: Tamagotchi is a Bandai trademark, and the specific creature and name are protected, so design your own animal, your own art, and your own name. The virtual-pet mechanic is yours to build; the brand is not.

Common mistakes

The first mistake is ticking needs on a foreground timer, so the pet freezes when the app closes. The second is copying Tamagotchi’s name or character. The third is guilt-driven, frequent notifications that get the app muted. The fourth is needs that decay so fast the pet is constant work. The fifth is paying for a game kit when a free VP0 design plus SwiftUI does it.

Key takeaways

  • A virtual pet has needs that decay over real time and care actions that restore them.
  • Compute needs from a stored last-update timestamp, not a foreground tick.
  • Reflect needs in the pet’s mood and animation.
  • Keep reminders gentle, and use your own original creature and name.
  • Build the UI free from a VP0 design.

Frequently asked questions

How do I build a virtual pet app in SwiftUI? Model needs that decay over time and care actions that restore them, computing each need from the time elapsed since the last update so the pet changes even when the app was closed, with gentle reminders.

What is the safest way to build a virtual pet with Claude Code or Cursor? Start from a free VP0 design, derive needs from a stored timestamp not a tick, add care actions and gentle notifications, and use your own original creature, not a trademarked one.

Can VP0 provide a free SwiftUI or React Native template for a pet game? Yes. VP0 is a free iOS design library; pick a game design and your AI tool rebuilds the pet, needs meters, and care buttons at no cost.

How does a virtual pet’s hunger change while the app is closed? Store the last-update timestamp and compute decay from the elapsed time when the app reopens, the same technique a countdown timer uses to stay accurate after being suspended.

Frequently asked questions

How do I build a virtual pet app in SwiftUI?

Model needs like hunger, happiness, and energy that decay over time, and care actions that restore them. Compute each need from the time elapsed since the last update rather than ticking a counter, so the pet changes correctly even when the app was closed. Reflect the result in the pet's mood, and add gentle reminders. Build the UI from a free VP0 design.

What is the safest way to build a virtual pet with Claude Code or Cursor?

Start from a free VP0 design and prompt the tool to derive needs from elapsed time using a stored last-update timestamp, not a foreground tick. Add care actions, a mood state, and gentle local notifications, and use your own original creature and name rather than a trademarked character.

Can VP0 provide a free SwiftUI or React Native template for a pet game?

Yes. VP0 is a free iOS design library for AI builders. Pick a game or character design, copy its link, and your AI tool rebuilds the pet, needs meters, and care buttons at no cost.

How does a virtual pet's hunger change while the app is closed?

Store the timestamp of the last update, and when the app reopens, compute how much each need decayed from the elapsed time. This makes the pet age realistically without running in the background, the same technique a reliable countdown timer uses to stay accurate after the app is suspended.

Part of the Native Apple & SwiftUI: The iOS Ecosystem hub. Browse all VP0 topics →

Keep reading