Join My Free Newsletter: https://www.johndav.com
In part three of my Swift Playgrounds game development project I am building our first attack into the game. The idea is to use a SwiftUI button in ContentView to trigger the attacking flag in our SpriteKit scene.
0:00 - Laying out Buttons in SwiftUI
3:10 - Add new varibles needed and create func fireAttack()
8:19 - Triggering fireAttack() in SpriteKit scene via Button in SwiftUI view
To do this we need to add a couple of Published variables to our GameData class, then write to those variables inside our GameScene. Then when we can use the button in ContentView to change the state of our attacking flag from false to true. Which will fire exactly 1 projectile and then toggle the flag back to false.
It's a simple, maybe even a bit crude, implementation, but it gets the job done and allows us to quickly prototype the concept behind this game which is exactly why I love Swift Playgrounds.
Previous Videos In This Series
Part 1 - Basic UI setup and rocket movement with SKPhysics: • Building a Game on an iPad with Swift...
Part 2 - Adding Fuel Gauges with SwiftUI Charts: • Using SwiftUI's Built In Charts Featu...
Next time I'll be implementing the second "mystery" button. What do you think it should do? Maybe it'll be a speed boost? Or maybe it could be a protective shield? I think whatever it is should be a button with a cooldown so I can work on implementing a cooldown effect.
Perhaps we'll try a few different options as we build the game further. I also foresee having items within the game world that could modify these buttons in the future. The possibilities are exciting!
#gamedev #swiftplaygrounds #swiftui
//Published Games
ZER0ED: https://apps.apple.com/us/app/zer0ed/...
Shapes&Numbers: https://apps.apple.com/us/app/shapes-...
Смотрите видео iPad GameDEV with Swift Playgrounds: Making a Simple Game онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь JohnDav 02 Февраль 2023, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,094 раз и оно понравилось 24 людям.