tvOS - a Virtual Mouse

for those familiar, navigation in tvOS is “focus based”… this means under normal circumstances you move left/right, up/down from object to object and they either grow a bit in size, or get a focus ring around them to indicate they are the “current object”. This is all well and good for static screen arrangments, but if objects move and/or are removed from the screen (as in games)… they can be situations where an object can no longer be reached because there is not a direct path anymore.

So I needed another method. I tried having the app dynamically create focusguides, but that was super complex and time consuming, not to mention I could never quite get it to do it quite right.

This led me to ask, “Why isn’t there just a MOUSE like a desktop has?” and I developed a Virtual Mouse object that works with the Siri Remote and normal Gamepads. It draws a “mouse cursor” and moves around the screen (not relying on the focus engine). Press the controller button causes a “MouseDown” , pressing it again causes a “MouseUp”. The app then takes the XY coordinate of the mouse cursor and determines what object (if any) it is hovering over. The current version is integrated into the game logic, but I intend to make it stand-alone using delegates to communicate the events

cursor0cursor1cursor2cursor3

Other cursor images can easily be added, but for now these were the only ones I needed

5 Likes