How to build a PagerView in WatchOS - ios

How can I build or get (library) a PagerView in WatchOS. I can't find a way to do it without SwiftUI. I have a library for UIKit (https://github.com/WenchaoD/FSPagerView) but i cant use it for watchOS

Use SpriteKit for custom ui on watchOS
If you can't use SwiftUI, WatchOS only has SpriteKit and SceneKit.
Your app isn't a game, but there's no difference to the computer, only to the user. A game is just a fun app.
You need to have a WKInterfaceController that hosts a WKInterfaceSKScene view and the WKInterfaceSKScene presents an SKScene
For a pager type view of images that you can swipe between, then you might have a scene with some SKSpriteNodes, for example 3, with one on screen, one to the left, one to the right, and move them around and change their images as user drags about. Or whatever you want, maybe a SKTileMapNode or so.
For dragging, maybe a WKPanGestureRecognizer on the WKInterfaceController - you need to ensure you're not in a paged based interface, only fullscreen or navigation based would work for that. You also want to allow the crown to be used, so implement WKCrownDelegate

Related

Architecture of a SceneKit game, multiple view controllers for menu screens?

I'm working on a SceneKit game using Swift, and I'm thinking about the best way to organize the various screens/ states surrounding the actual main game scene. I have a simple prototype which consists of three states:
Splash Screen (choose game type) ->
Game ->
Game over screen (choose to play again or return to splash)
In the prototype I opted to go for UIKit to do the UI elements, rather than a SpriteKit overlay. Although it's just buttons at the moment, which would be easy enough to do in SpriteKit, I might in future want to add sliders (eg an options screen to set control sensitivity etc), text entry etc, and then you end up recreating great chunks of uikit.
So at present, each of the 3 scenes described above has its own UIViewController. The Splash and Game ViewControllers have their own SCNViews and SCNScenes, and the GameOver is a modal that displays over the main Game scene.
This structure isn't really ideal, as it means that the main game SCNScene gets reloaded whenever the viewDidLoad of the GameViewController fires. The main SCNScene is quite detailed so takes a few seconds to load, and with repeated cycles this seems to create memory issues. After 2 cycles of Splash -> Game -> GameOver I get a memory warning, and after the third cycle Xcode loses the connection to the iPhone (which seems, in my experience, to be caused by memory issues).
I would like to have a main GameViewController that loads the most frequently reused assets once, but still be able to segue between the various menu screens.
So what are the options here?
I thought perhaps I could have a main GameViewController which controls the loading and unloading of SceneKit assets and has the sole SCNView. Its viewDidLoad method would only be fired once, when the app first starts. Then, each of the other views would have a very minimal UIViewController, which would be presented as modals over the main GameViewController, with "OverCurrentContext" selected.
I wanted to ask whether this pattern sounds feasible, and how others organise their SceneKit games. I'm still quite new to native iOS development, so it could be that I'm missing some basic game design pattern.
My Experience with the use of only one GameViewController (my current work for MAC OS X: i started a a 'small' 3D game with a MainMenu/start screen, a Hud and 2 or 3 complete different 3D Scenes - this shall be ported then to IOS, too):
In the last week i tried what you asked for, to use only one GameViewController for "all" that stuff - for me it seemed to be the easy and "good" way to do it - but even after lot of hours with all my tricks I've learned the last years i was not able to reload load another (or change) 3D scene (or even not another sprite kit scene hud) after a scenekit scene is loaded in a single ViewController.
Maybe there is difference between MAC OS X and IOS but i even tried this in an iOS version and it has the same behavior.
What i was able to do: You can modify a loaded 3D scene or change data in the sprite kit hud etc., so you are able to use one 3d scene to add or show the things up when they are needed but as far as my tests here showed, you will need one ViewController to show up a complete new different 3d scene or 2d/3d Menus etc. I will post my further experiences as soon as I'm a step further. i hope this helps a little.

Custom assistive touch

Is it possible to create an app (App A) with a programmatically created view that works very much like Assistive Touch: stays on top of the UI, and is visible pretty much anytime (while using App B, App C etc)?
Objective is to be able to make screenshots in random parts of the interface and then launch an app that can process these screenshots (from camera roll or wherever else).

Menu Screens (e.g. Inventory Screen) on a SceneKit game

I just started to learn SceneKit/SpriteKit to develop games, and while I understood the game part (the SCNScene, in my case), I’m not so sure about the menu/hud part.
What I want to do: create an Inventory Screen to show the items the player has in his bag. This screen will appear when the user taps the bag Icon in the HUD. Furthermore, the Inventory Screen must have a UICollectionView-like list to show each item.
Game Hud:
Inventory Screen:
My question is: should I mix SpriteKit with UIKit to try to accomplish this? Or use just one of them? Should everything be done just with SKScenes that are shown on top of each other (by adding to the OverlaySKScene)?
Currently, I’m presenting the HUD as a SKScene (OverlaySKScene). When the user taps the bag icon, I’m loading a new SKScene (with a bunch of SKSpriteNodes, SKShapeNodes etc) and putting it as the current OverlaySKScene. Now, I’m trying to do the CollectionView part, but don’t know if I should try to implement everything from scratch with SpriteKit or if it’s possible to reuse UICollectionView, with my SKScene as a delegate.
I'm not sure if the way I'm doing is the right way, either.
Any help would be appreciated.
Thanks in advance.

How do you implement SpriteKit within a WatchKit extension app?

I am trying to extend a SpriteKit-based iPhone app to the Apple Watch, however given that Watch extensions do not use UIKit and UIViews (instead using WKInterfaceObject and its subclasses), I am not sure how I can setup my SKView and SKScene within the Watch extension.
This is old, but just wanted to mention that in watchOS 3 you can use SpriteKit and SceneKit.
You can't use SpriteKit in a WatchApp. You can ONLY use the UI elements provided for a Watch App. You can't create custom UI elements. The closest you can get is to create custom images in your watch extension running on the iPhone and set those in your Watch UI. See Watchkit animation implementations: clock face, animated charts, circular progress bar for more info.

Can I support VoiceOver in my Cocos2D-iPhone Game?

I'm making a game where a player reacts to sounds via motion - seeing as the visual element isn't needed to play it, and many play with their eyes closed, it seems a shame to not be fully VoiceOver compatible. I'm currently using Cocos2D-iPhone and CocosDenshion for audio, and am now starting to think about how I'll be building my menu system to choose levels and configure controls.
Is it reasonably easy to support VoiceOver in Cocos2D's menu system, or should I look in to trying to create my menus in UIKit which I have no experience using?
I don't know if Cocos' menu system supports VoiceOver, but if it doesn't, you could probably add the functionality you're looking for yourself without having to delve into a lot of UIKit work. All you need to do is create a UIView subclass which gets added to your main window when your app starts up. Then use the UIAccessibilityContainer protocol and UIAccessibilityPostNotification calls to allow users to interact with your game via VoiceOver.
The UIAccessibilityContainer protocol lets you inform VoiceOver what interface elements are currently on the screen, their labels, their traits, etc. VoiceOver then uses this information to let users swipe between elements and get feedback on them.
When your game changes state, you can change what that protocol sends back and then issue a
UIAccessibilityPostNotification(UIAccessibilityLayoutChangedNotification, nil)
...to inform VoiceOver that the screen layout has changed. And to just speak something via VoiceOver, say when your game state has changed, you can send a different notification to speak some text:
UIAccessibilityPostNotification(UIAccessibilityAnnouncementNotification, #"Achievement unlocked!");
No need to go with UIKit framework you can go with the cocos2d native methods and class to implement this.
For sound option we have SimpleAudioEngine Which can be used. you can distinguish between sound using its ID which is of type ALuint.
ALuint soundEffectID;
//to start
soundEffectID=[[SimpleAudioEngine sharedEngine] playEffect:#"my sound"];
//to stop
[[SimpleAudioEngine sharedEngine] stopEffect:soundEffectID];
You have to mange these effect and I think your problem will be solved.

Resources