📜 ⬆️ ⬇️

The first experience of developing games on the Sprite Kit

After creating and displaying games on the Sprite Kit in the App Store, I would like to share my experience. I will talk a little about the creation of gameplay, as well as about attempts to connect with publishers and about the impressions of the framework.




Idea


So, we had a goal - to invent and create a game in one-tap endless genre. We are a team of three people: a programmer (he is the author of the article), a designer (he is the project manager) and an illustrator-animator. As in all games of this genre, the process of the game should be fairly simple, controlled by one touch and at the same time must be delayed. After some thoughts, an idea was born, and after a while, a prototype of the game.
')
So, a character jumps from one swinging platform to another. As you progress through the game, it becomes more complicated by changing the parameters of the platforms. After landing on the next platform, the hero runs to its edge. After the jump, the visible area of ​​the game shifts.



Implementation


I started with the creation of "swing". Each of them consists of a holder (at the top), a beam and a platform. It all connects with two swivels ( SKPhysicsJointPin ). Then it was necessary to ensure that the hero stood on the platform and did not chat from side to side. I tried several approaches. I tried to manually set the velocity of the object in the update method depending on the speed of the platform on which it stands (advised on stackoverflow ), but this led to the unpleasant effect of “lagging”. As if the hero did not have time for his platform and moved with a slight delay. Experiments with changing the friction of the object also led to some unpleasant effects. As a result, the only way to fix the hero on the platform, which I found, is to add SKPhysicsJointFixed . Before jumping, remove it and then re-add when you need to stop.

In order for the hero to jump, you need to assign him some kind of impulse. The strength of the jump is controlled by the player. It depends on the duration of pressing. Here we had to slightly increase the momentum if the platform at the moment of the jump moves backwards, otherwise the hero would take off almost vertically up and land on the same platform.

The next task is to fix the landing moment correctly and after landing touch up the joint again, which will keep the hero on the platform. It turned out that it is not enough just to add a joint in the didBeginContact method, because, firstly, it is called at a time when there is still some space between objects and when adding a joint, the hero seemed to hang a few centimeters above the platform, and secondly, he can hitting the platform from the side and in this case nothing needs to be done. I solved the first problem by adding a Boolean variable that indicates that the contact was committed and checked in the next call to didSimulatePhysics . In this case, the joint is added to didSimulatePhysics and the objects at this moment are close to each other. And in order to exclude cases when the hero hits the side, check the relative position of the hero and the platform to make sure that the hero is on the platform.

After landing, the hero must run to the edge of the platform. Here the method of manually setting the velocity to the hero just worked. In the update method, we take the velocity of the platform on which it should run, add some positive value for x , and assign the resulting velocity to the hero. As a result, the hero moves on the platform. In this case, if there is a lag effect, then it is not visible and everything looks good. After reaching the edge of the platform, add the fixing joint again.

The whole scene consists of separate nodes that have different zPosition values, forming as a result layers: a layer for the hero and platforms, a layer for the background, a layer for the interface elements. After the hero's landing, the layers are shifted, while the background layer moves more slowly than the hero layer, to ensure the effect of the background distance. It turns out that the x coordinate of each next swing increases within its own node, and the node itself shifts to the left within the scene. Here I am faced with different behavior in different versions of iOS. In versions starting with iOS 7.1, the coordinates of the joints should always be converted to the coordinates of the scene, otherwise the objects connected by these joints start to behave very strangely. And in versions up to 7.1, this is not necessary, otherwise, again, objects begin to randomly dangle in the air.

In general, what happened at this stage was already possible to play and was quite interesting.

Graphics


Meanwhile, the illustrator came up with and painted the main character.



Everybody really liked it and soon the main animations were created. So, I got all the necessary sequences to add animations. Each type of animation is thrust into a separate texture atlas and added to the project. After starting the game, before the appearance of the game scene, load all the textures and save in separate arrays. We create methods for all animations, each of which “forces” the hero to delete all previous animations and adds a corresponding new one.

Separately, we worked on situations where the hero lands on the very edge of the platform. Made animations for such cases. And I have never paid attention to how such situations are allowed in other games. After all, once a hero landed on a platform in some way, he no longer has to fall, but a simple landing here will look strange.

Then the background and textures were created for the surfaces. The background was divided into three layers, each of which moves at a different speed. This adds even more volume effect. Platform and beam textures are composed of repeating patterns. Also added a few animations (flashing stars, falling comets), which randomly appear on the background in order to slightly diversify the appearance.

I discovered strange behavior when adding semi- blurred UIView views to a SKView class view . A translucent view is not displayed if it does not contain any opaque child views. More precisely, when it is added, it appears for a very short time, and then disappears. That is, if you add a view with alpha = 0.5 to SKView without any child views, it will not be displayed. You need to add at least one child view with alpha = 1 to display it normally.

We also added a bit of competitive element, using the possibilities of the game center. During the game, the results of friends are pumped up and displayed. The result is shown directly on the platform, which reached one of the friends, in the form of a translucent shadow of the protagonist.

Impressions of the Sprite Kit


Before I started working on the game, I read all sorts of articles comparing various game frameworks. As a benefit to the Sprite Kit, it has been indicated everywhere that it is part of Cocoa and it is easiest to start using it for the first project. For me, this was a decisive factor when choosing a framework. The disadvantages of the Sprite Kit, noted in the articles, seemed to me insignificant for our project. As a result, the main disadvantage for me was that the frequency of physics updates in the Sprite Kit depends on fps. That is, at the moments when the FPS falls (for example, during the display of banners for the game center), the stability of physics leaves much to be desired. It took quite a lot of time to catch and fix the bugs caused by it. Also, it was not possible to get rid of small delays when changing the hero's animations on older devices (up to iPhone 5). There is no experience with other frameworks, except for a few Cocos2D lessons, so there is nothing to compare with. But there are plans to rewrite the game on Cocos2D with Box2D and compare the results. Otherwise, everything is very convenient and simple. I think, for games with very simple physics or without it at all, the Sprite Kit is ideal if developed only for iOS.

Marketing and monetization


During the development process, requests were sent to various publishers. Most did not even respond to the letter, but some did respond. Among them are Ketchapp, Chillingo and Ayopa games. They all installed the game via TestFlight. To admit, we most of all counted on Ketchapp, as our game most of all approaches under their format. However, after installing the game, they no longer wrote. Chillingo replied that they like the graphics and the character, but now it’s hard to make money on games of this genre and asked to keep them informed of our developments. Most of all, we were close to an agreement with Ayopa games. They responded for the first time only 3 weeks after they downloaded the game. They wrote that we need to make some corrections, but in general they are interested. We were inspired, did everything they asked, posted a new version. Unfortunately, the next answer came again only after 2 weeks, when we were already tired of waiting, and the application was half way to the App Store. We asked them for some guarantees that they will take up our application if we postpone the display in the App Store and change the game at will. In response, they expressed a desire to learn about our future projects, but in this situation, they refused. In general, it did not work out, somehow we were tired of waiting for a response for 2-3 weeks, I wanted to upload the application faster.

As a result, we decided to advertise on our own: social networks, requests for review in various Internet resources, google AdMob. In AdMob threw 20 thousand rubles. They were consumed in one day and brought in a total of 55,000 impressions, 1,140 clicks and about 450 installations. Also advertised in the group in contact with the number of users about 700 thousand. This brought a total of about 200 installations. The conclusion is that without large sums of advertising it is hardly worth counting on success, unless, of course, you are lucky and you are not given a free review on any major website. The list of sites that sent a request for a free review, looked at the publication of the user RedRoseSinging , as well as in this publication of the user EugeneDM , thanks to them.

As a monetization, we chose the standard approach for such games - the display of ads + the built-in purchase, which offers to disable this advertisement. As an advertising network chose Chartboost . There, you can very flexibly customize the displayed ads and the banner itself looks quite nice. I worked a little on showing the banner so that it would not be pressed accidentally. In many games this is exactly what happens and it is very annoying.

Here is a video with gameplay:



Thanks to everyone who read the article to the end, waiting for comments!

Source: https://habr.com/ru/post/250243/


All Articles