<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Łukasz Konior on Medium]]></title>
        <description><![CDATA[Stories by Łukasz Konior on Medium]]></description>
        <link>https://medium.com/@lukkonior?source=rss-e26c0d00f714------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ezb1MsKu9QTHfIK5MAH3Ag.jpeg</url>
            <title>Stories by Łukasz Konior on Medium</title>
            <link>https://medium.com/@lukkonior?source=rss-e26c0d00f714------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 02:23:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lukkonior/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[SpriteKit Advanced — How to build a 2,5D game (Part III)]]></title>
            <link>https://medium.com/free-code-camp/spritekit-advanced-how-to-build-a-2-5d-game-part-iii-e058b99cfbc3?source=rss-e26c0d00f714------2</link>
            <guid isPermaLink="false">https://medium.com/p/e058b99cfbc3</guid>
            <category><![CDATA[indie-game]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[tech]]></category>
            <dc:creator><![CDATA[Łukasz Konior]]></dc:creator>
            <pubDate>Sun, 01 Oct 2017 20:09:42 GMT</pubDate>
            <atom:updated>2017-10-01T20:12:30.976Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AcTkWr0OAaQmXWb0uJ_wbA.png" /></figure><h3>Intro</h3><p>This article is about improving visuals of <a href="https://itunes.apple.com/app/apple-store/id1073887270?pt=117756562&amp;ct=Develop%20Articles&amp;mt=8">Raft Challenge</a> by applying GPU’s shaders to the still scenery. It explains the algorithms and potential pitfalls when using GLSL in SpriteKit.</p><p>The reader should have basic experience in writing fragment shaders. We discussed these in <a href="https://medium.freecodecamp.org/spritekit-advanced-how-to-build-a-2-5d-game-part-i-2dc76c7c65e2">part 1</a> and <a href="https://medium.freecodecamp.org/spritekit-advanced-how-to-build-a-2-5d-game-part-ii-30ddb613b568">part 2</a> of this series.</p><h3>The problem</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*9SBXaFkPnYERxMB-0TCBuw.gif" /></figure><p>After the game entered beta stage, we received feedback from various people. We frequently heard that the graphics were good, but also static, which in the long run led to boredom.</p><p>My instant reaction was like: “They said it’s static? So we’ll add some wind to move the whole thing!” After that, we thought more about the problem.</p><p>Such huge objects as the trees cannot animate frame-by-frame, because it would lead to memory problems. We were considering adding small animated objects like animals. But it would complicate the scene graph even more. And it would have unknown performance impact.</p><p>The solution I came up with was to animate the whole forest using the fragment shaders. I wanted to create the wind effect.</p><p>The idea was to apply a horizontal distortion to the sprite’s texture with strength proportional to the distance from the trunks’ base. That strength has also been changing in time and influenced by the scene’s “depth”.</p><p>Other pros of this solution:</p><ul><li>easy integration<br>It’s as simple as filling an existing object’s properties</li><li>performance</li><li>huge flexibility</li></ul><p>Here’s the source (GLSL):</p><pre>void main( void )<br>{<br>    float horizonAbsoluteOffset = 0.64; // 1<br>    float distanceFromTrunksBase = abs(v_tex_coord[1] - horizonAbsoluteOffset); // 2<br>    float maxDivergence = mix(0.0,1.0,distanceFromTrunksBase)*0.038; // 3<br>    float factor = sin(u_time*2+(attrDepth * 1.3)); // 4<br>    vec2 deltaUV = vec2(maxDivergence * factor, 0); // 5<br>    <br>    gl_FragColor = texture2D(u_texture, v_tex_coord + deltaUV); //6<br>}</pre><ol><li>This float holds the vertical position of all trunks’ bases<br> — This value is specific to our texture</li><li>We calculate the distance between the current sampling point and the above value<br> — This value is less than 1.0 and can be negative</li><li>We calculate max divergence<br> — The magic number at the end was tweaked through trial and error</li><li>We calculate the changing strength and the wind’s direction<br> — The sin function is a good foundation since it returns predictable values (-1 to 1)<br> — It’s also a continuous function<br> — The latter means that we can put any garbage as the argument and it will still work<br> — In this case “the garbage” is the current time plus the “depth” of the current sprite<br> — Magic numbers are added to shape the animation</li><li>The delta vector is created<br> — Max divergence multiplied by the factor goes into the X position while Y is left with 0.</li><li>This line takes the color from a specific point in the texture and outputs it to the screen<br> — By adding delta to our current position with vtexcoord, we alter the point from which the sampler is extracting color value</li></ol><p>Result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*hWEuJs2ib6EWDzbm3sCrrw.gif" /></figure><p>Note that reflections on the water are also moving. That is because the trees and reflections are a part of the same sprite and texture. No sorcery here.</p><h3>Improving fog</h3><p>Is there anything else that we can do? Well, if we can’t invent anything new, we can always improve something that exists. Our designer said once ago that trees further away should have solid color to merge better with the fog.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/513/1*N6nfA_ZtMLUP1FFeavg1Uw.png" /></figure><p>The above image is almost self-explanatory. Earlier, I’ve mentioned about the “depth”. Every layer of the forest has an attribute attrDepth. It represents the distance between the mountains (0.0) and the viewer (6.0).</p><p>Let’s tweak this fog!</p><pre>__constant vec3 colorLightMountains = vec3(0.847, 0.91, 0.8);<br>__constant vec3 colorDarkMountains = vec3(0.729, 0.808, 0.643);</pre><pre>void main( void )<br>{   <br>    //get color<br>    vec4 color = texture2D(u_texture, v_tex_coord);<br>    float alpha = color.a; // 1</pre><pre>    //fog<br>    vec3 outputColor = vec3(color.rgb);<br>    if (attrDepth &lt; 1.0) {					// 2<br>        outputColor = colorLightMountains;<br>        alpha = min(attrDepth,alpha);<br>    } else if (attrDepth &lt; 2.0) {			// 3<br>        outputColor = mix(colorLightMountains, colorDarkMountains, attrDepth - 1.0);<br>    } else if (attrDepth &lt;= 3.0) {		// 4<br>        outputColor = mix(colorDarkMountains, color.rgb, attrDepth - 2.0);<br>    }<br>    <br>    gl_FragColor = vec4(outputColor, 1.0) * alpha; // 5<br>}</pre><p>The code above is pretty straightforward so I’ll focus only on the most important things:</p><ol><li>Extract alpha from the texture.</li><li>The far stage<br>When the forest is the furthest possible, it has the Light Mountains color and 0 alpha<br> As it’s moving closer, it emerges by increasing alpha up to depth == 1.0</li><li>The medium distance<br>The color shifts towards Dark Mountains as the sprite’s get closer to the viewer.</li><li>The close distance<br>The color is a mix between the Dark Mountains and the native texture color<br>Naturally, the closer it is, the more normal it looks</li><li>Pass the final color to the output using the alpha extracted at the beginning</li></ol><p>Again, the result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*ylVO0Z4OgKfzM6bWpN9fgw.gif" /></figure><h3>Combining both effects</h3><p>The best thing that I like about shaders is their flexibility. It’s not only possible to merge both effects without sacrificing anything. It’s even recommended to do so.</p><p>Merging shaders decrease the draw calls and that increases the frame rate.</p><pre>__constant vec3 colorLightMountains = vec3(0.847, 0.91, 0.8);<br>__constant vec3 colorDarkMountains = vec3(0.729, 0.808, 0.643);</pre><pre>void main( void )<br>{<br>    //wind<br>    float horizonAbsoluteOffset = 0.64;<br>    float distanceFromTrunksBase = abs(v_tex_coord[1] - horizonAbsoluteOffset);<br>    float maxDivergence = mix(0.0,1.0,distanceFromTrunksBase)*0.038;<br>    float factor = sin(u_time*2+(attrDepth * 1.3));<br>    vec2 deltaUV = vec2(maxDivergence * factor, 0);<br>    <br>    //get color<br>    vec4 color = texture2D(u_texture, v_tex_coord + deltaUV);<br>    float alpha = color.a;</pre><pre>    //fog<br>    vec3 outputColor = vec3(color.rgb);<br>    if (attrDepth &lt; 1.0) {<br>        outputColor = colorLightMountains;<br>        alpha = min(attrDepth,alpha);<br>    } else if (attrDepth &lt; 2.0) {<br>        outputColor = mix(colorLightMountains, colorDarkMountains, attrDepth - 1.0);<br>    } else if (attrDepth &lt;= 3.0) {<br>        outputColor = mix(colorDarkMountains, color.rgb, attrDepth - 2.0);<br>    }<br>    <br>    //output<br>    gl_FragColor = vec4(outputColor, 1.0) * alpha;<br>}</pre><p>The final result:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*z5Nl9WpJztl97Hj29l5m-A.gif" /></figure><h3>Pitfalls</h3><p>There’s no rose without a thorn.</p><ul><li>Using shaders on multiple big sprites with alpha channel may cause visible frame rate drop.</li><li>Same GPU may give 60fps on the iPhone but only 20fps on iPad with more pixels<br>Test your code frequently on different devices, especially the iPads with retina displays</li><li>There is no reliable way to estimate the performance of the device from the code<br>Run your game on multiple physical devices and white list those that are capable of running shaders with decent performance<br>To distinguish devices, you can use <a href="https://github.com/erica/uidevice-extension/blob/master/UIDevice-Hardware.m">UIDevice-Hardware.m</a></li><li>Your partially transparent texture loses color and becomes gray? Google <strong>premultiplied alpha</strong>!</li><li>Beware of using SKTextureAtlases if you’re altering the coordinates like in the wind example<br>During the atlas generation, XCode may rotate and move some textures.<br>It’s impossible to detect such anomaly from the code, or at least I don’t know how</li><li>For some sprites, you may receive a texture with swapped X and Y coordinates!</li><li>You may accidentally warp to a completely different sub-texture!</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*6WvEeaIP5d6-2OVangLvEw.png" /></figure><h3>Summary</h3><p>We’ve learned how to use fragment shaders to create wind and fog. When writing Your own GLSL code, you’ll surely produce many display artifacts. Some of them are annoying, and some are hilarious. Keep in mind that some of them may have potential to become a feature!</p><p>About the author: Kamil Ziętek is an iOS Developer at <a href="http://www.allinmobile.co/">www.allinmobile.co</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e058b99cfbc3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/spritekit-advanced-how-to-build-a-2-5d-game-part-iii-e058b99cfbc3">SpriteKit Advanced — How to build a 2,5D game (Part III)</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SpriteKit Advanced — How to build a 2,5D game (Part II)]]></title>
            <link>https://medium.com/free-code-camp/spritekit-advanced-how-to-build-a-2-5d-game-part-ii-30ddb613b568?source=rss-e26c0d00f714------2</link>
            <guid isPermaLink="false">https://medium.com/p/30ddb613b568</guid>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[spritekit]]></category>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[indie-game]]></category>
            <dc:creator><![CDATA[Łukasz Konior]]></dc:creator>
            <pubDate>Sun, 01 Oct 2017 20:06:08 GMT</pubDate>
            <atom:updated>2017-10-01T20:13:46.722Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MYgdND4CCLf9eONh2LfRSg.png" /></figure><h3>Intro</h3><p>This article shows how to write basic shaders in the SpriteKit. It’s split into two parts: first we play, then we learn.</p><p>It also contains information how to use SKAttribute and SKAttributeValue classes that were added in iOS SDK 10.0.</p><p>If you haven’t already read it, <a href="https://medium.freecodecamp.org/spritekit-advanced-how-to-build-a-2-5d-game-part-i-2dc76c7c65e2">here’s part 1 of this article series</a>.</p><h3>Prepare the project</h3><p>Let’s get quick and dirty.</p><ul><li>Open XCode 8 and create a new project from template: iOS &gt; Game.</li><li>Open the GameScene.sks and remove the label in the center of the screen.</li><li>Download <a href="http://cosmicteapotgames.com/wp-content/uploads/2017/06/trees.png">this</a> and put it inside Assets.xcassets</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TaljtSkLlHER3NnRbghAdw.png" /></figure><ul><li>Name it “Trees”</li><li>Open the GameScene.m</li><li>remove all instance variables</li><li>remove all methods</li></ul><h3>The Fragment Shader</h3><p>Now we create an empty <strong>fragment </strong><strong>shader</strong> In XCode:</p><ul><li>In the Project Navigator select Supporting Files</li><li>Choose: File &gt; New &gt; File…</li><li>Select: Other &gt; Empty</li><li>Name it “myShader.fsh” and press Create.</li><li>Put this inside:</li></ul><pre>// currently a boring pass-thru shader void main( void ) { vec4 color = texture2D(utexture, vtexcoord); // here will emerge something worthy glFragColor = color;}</pre><p>Above fragment shader does nothing perceptible. Quick explanation:</p><ul><li>void main()<br> this function gets called for each pixel of the sprite and outputs color for that pixel<br>Gets input data from surrounding globals and must set the gl_FragColor variable</li><li>vec2, vec3and vec4 are the types similar to C&#39;s: float array[2], float array[3] and float array[4]</li><li><em>u_texture</em> is a texture ID<br>Leave it alone :-)</li><li>v_tex_coord is a vec2 which contains our current position in texture</li><li>texture2D(tex , p) is a function that returns color from texture tex in point p as vec4 <br>which contains rgba</li><li>gl_FragColor is an output color<br> We must assign it a vec4</li></ul><h3>Loading code</h3><p>What’s left is the loading code.</p><ul><li>Open the GameScene.m</li><li>add method -didMoveToView:</li></ul><pre>- (void)didMoveToView:(SKView *)view {<br>	// 1. load the shader&#39;s source from myShaderFile.fsh<br>	NSString *file = [[NSBundle mainBundle] pathForResource:@&quot;myShader&quot; ofType:@&quot;fsh&quot;];<br>	NSString *sourceString = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];<br>	    <br>	// 2. create the shader<br>	SKShader *shader = [SKShader shaderWithSource:sourceString];<br>	<br>	// 3. assign the shader to a newly created sprite node<br>	SKSpriteNode *spriteNode = [SKSpriteNode spriteNodeWithImageNamed:@&quot;Trees&quot;];<br>	spriteNode.shader = shader;<br>	<br>	// 4. finally add the sprite to the scene<br>	[self addChild:spriteNode];<br>}</pre><p>Ensure that myShader.fsh figures in ProjectFile &gt; Target &gt; Build Phases &gt; Copy Bundle Resources!</p><p>You may now run the project on the iOS device. There shall be no errors in the XCode’s console and you should see a screen similar to this below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*umN3DsikYVWkwbg1sgiVHQ.png" /></figure><h3>Let’s play a bit!</h3><p>Now is the fun part. We’ll replace the shader’s main function.</p><h3>Color with red with alpha preservation</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*JnxJI4awktb8Jaq61-Ny4A.png" /></figure><pre>void main( void )<br>{<br>    vec4 color = texture2D(u_texture, v_tex_coord);<br>    float alpha = color.a;<br>    gl_FragColor = vec4(1,0,0, 1.0) * alpha; //google &quot;premultiplied alpha&quot;<br>}</pre><h3>Scale down by 2x</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*O_5A_sgzAOpUR6BSrXEf9w.png" /></figure><pre>void main( void )<br>{<br>    vec4 color = texture2D(u_texture, v_tex_coord * 2.0);<br>    gl_FragColor = color;<br>}</pre><h3>Swap colors after 1 second</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*LZ5Gdhvb4rj1MbDr-7PJkA.gif" /></figure><pre>void main( void )<br>{<br>    vec4 color = texture2D(u_texture, v_tex_coord);<br>    float alpha = color.a;<br>    float phase = mod(u_time, 3);<br>    vec3 outputColor = color.rgb;<br>    if (phase &lt; 1.0) {<br>        outputColor = color.bgr;<br>    } else if (phase &lt; 2.0) {<br>        outputColor = color.brg;<br>    }<br>    gl_FragColor = vec4(outputColor, 1.0) * alpha;<br>}</pre><h3>Colorize over time</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*MEP_vUFhazzMSREbYkRejw.gif" /></figure><pre>void main( void )<br>{<br>    vec4 color = texture2D(u_texture, v_tex_coord);<br>    float alpha = color.a;<br>    float r = (sin(u_time+ 3.14 * 0.00)+1.0)*0.5;<br>    float g = (sin(u_time+ 3.14 * 0.33)+1.0)*0.5;<br>    float b = (sin(u_time+ 3.14 * 0.66)+1.0)*0.5;<br>    gl_FragColor = vec4(r,g,b, 1.0) * alpha;<br>}</pre><h3>Waves</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*fFWsqBtdNs7sDRokrElCIw.gif" /></figure><pre>void main( void )<br>{<br>    float deltaX = sin(v_tex_coord.y*3.14*10 + u_time * 4)*0.01;<br>    vec2 coord = v_tex_coord;<br>    coord.x = coord.x + deltaX;<br>    vec4 color = texture2D(u_texture, coord);<br>    gl_FragColor = color;<br>}</pre><h3>New Attributes</h3><p>At WWDC 2016 Apple introduced an important update to SpriteKit — the SKAttribute and SKAttributeValue classes.</p><p>Before this SDK update, if we wanted to pass custom parameters into the shader program, we had to pass the data through a uniform value.</p><p>This had two serious drawbacks:</p><ul><li>every uniform change caused shader recompilation</li><li>shader program handled every sprite in the exact same way</li></ul><p>For example: if we wanted to dye a group of sprites red, and one of them blue, we had two ways. First we create two separate SKShader instances and change our custom myColor uniform.</p><p>Second we make one shader instance and change its uniform which causes a recompilation.</p><p>Both ways cannot be drawn on same pass. And the second one requires complex management code.</p><p>SDK 10.0 introduced the SKAttribute and SKAttributeValue classes. These two allow (finally!) passing data to the shader programs without recompilation. The usage algorithm is simple:</p><ul><li>The shader part:</li></ul><ol><li>Create a shader program<br>SKShader</li><li>Create an array of SKAttributes</li><li>Assign array of attributes to the shader program</li></ol><ul><li>The sprite part:</li></ul><ol><li>Assign the shader program to a sprite</li><li>Assign a dictionary of SKAttributeValues</li></ol><h3>Example with attributes</h3><p>In the last example, we’ll add two more sprites. Every one of them will have the same shader program and will differ only in attributes. Let’s modify the <em>-</em>didMoveToView: inGameScene.m:</p><pre>- (void)didMoveToView:(SKView *)view {<br>    NSString *file = [[NSBundle mainBundle] pathForResource:@&quot;myShader&quot; ofType:@&quot;fsh&quot;];<br>    NSString *sourceString = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil];<br>    SKShader *shader = [SKShader shaderWithSource:sourceString];<br>    <br>    // 1. Add a custom attribute to shader<br>    SKAttribute *attrProgress = [SKAttribute attributeWithName:@&quot;THE_MIGHTY_DARK_FACTOR&quot; type:SKAttributeTypeFloat];<br>    shader.attributes = @[attrProgress];<br><br>    // 2. Create tree sprites<br>    NSArray *trees = @[<br>                       [self createTreeWithShader:shader mightyFactor:0.3f zPosition:1],<br>                       [self createTreeWithShader:shader mightyFactor:0.6f zPosition:2],<br>                       [self createTreeWithShader:shader mightyFactor:0.9f zPosition:3],<br>                       ];<br>    for (SKSpriteNode *tree in trees) {<br>        [self addChild:tree];<br>    }<br>}<br><br>- (SKSpriteNode*)createTreeWithShader:(SKShader*)shader mightyFactor:(CGFloat)mightyFactor zPosition:(CGFloat)zPosition {<br>    SKSpriteNode *treeNode = [SKSpriteNode spriteNodeWithImageNamed:@&quot;Trees&quot;];<br>    treeNode.shader = shader;<br>    // 3. Fill the custom attribute on the sprite<br>    treeNode.attributeValues = @{@&quot;THE_MIGHTY_DARK_FACTOR&quot;: [SKAttributeValue valueWithFloat:mightyFactor]};<br>    treeNode.zPosition = zPosition;<br>return treeNode;<br>}</pre><p>… and the shader program:</p><pre>void main( void )<br>{<br>    vec4 color = texture2D(u_texture, v_tex_coord * (2.5 * THE_MIGHTY_DARK_FACTOR));<br>    float alpha = color.a;<br>    vec3 baseColor = color.rgb * THE_MIGHTY_DARK_FACTOR;<br>    gl_FragColor = vec4(baseColor, 1.0) * alpha;<br>}</pre><p>... and see the parameterized result!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*UgStdGSUt-D5n3teQ9HYSA.png" /></figure><h3>Caveats</h3><ul><li>The shader’s source code is typically loaded from a .fsh file to a plain NSString<br>This code must compile on the target device during the runtime<br>no buildtime checks!</li><li>Older devices may use different version of OpenGL ES so beware GLSL syntax differences!<br>In Raft Challenge’s case there was the need to replace __constant (valid in OpenGL ES 3.0) to const for OpenGL ES 2.0.</li><li>It’s a good idea to keep a reference to SKShader object somewhere and reuse it as frequently as needed to avoid visible frame rate drop<br>While allocation and shader compilation takes less than 1/60 sec, it may become a huge burden in render loop</li><li>When using SpriteKit’s Texture Atlases be cautious of vtexcoord<br>XCode may rotate some textures which swap X and Y axis<br><strong>Color modification is safe, geometry is not</strong></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*6WvEeaIP5d6-2OVangLvEw.png" /></figure><h3>Summary</h3><p>We learned by examples how to use fragment shaders in the Sprite Kit. We added parameters to sprites so our shader program can render every instance in a different way without any performance loss.</p><p>The <a href="http://cosmicteapotgames.com/wp-content/uploads/2017/06/ShaderDemo.zip">complete project</a> is available for a download.</p><p>You can <a href="https://medium.freecodecamp.org/spritekit-advanced-how-to-build-a-2-5d-game-part-iii-e058b99cfbc3">read part 3 of this series here</a>.</p><p>About the author: Kamil Ziętek is an iOS Developer at <a href="http://www.allinmobile.co/">www.allinmobile.co</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=30ddb613b568" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/spritekit-advanced-how-to-build-a-2-5d-game-part-ii-30ddb613b568">SpriteKit Advanced — How to build a 2,5D game (Part II)</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SpriteKit Advanced — How to build a 2,5D game (Part I)]]></title>
            <link>https://medium.com/free-code-camp/spritekit-advanced-how-to-build-a-2-5d-game-part-i-2dc76c7c65e2?source=rss-e26c0d00f714------2</link>
            <guid isPermaLink="false">https://medium.com/p/2dc76c7c65e2</guid>
            <category><![CDATA[ios]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[spritekit]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[game-development]]></category>
            <dc:creator><![CDATA[Łukasz Konior]]></dc:creator>
            <pubDate>Sun, 01 Oct 2017 20:04:38 GMT</pubDate>
            <atom:updated>2017-10-03T15:01:49.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*UfZWvFeWyuKgOIlkuU1log.png" /></figure><h3>Intro</h3><p>This article is about graphical evolution of <a href="https://itunes.apple.com/app/apple-store/id1073887270?pt=117756562&amp;ct=Develop%20Articles&amp;mt=8">Raft Challenge</a> from the prototype to the final product. It’s <a href="https://www.allinmobile.co/">AIM</a>-ed for the people who are thinking about making their own game with graphics like Raft, but don’t know exactly how to start.</p><h3>The very beginning of Raft Challenge</h3><p>Raft Challenge was born during the first hackathon organized by <a href="https://www.allinmobile.co/">All In Mobile</a>. The idea was to make a game where a player avoids obstacles. We wanted to keep things as simple as possible.</p><p>After the weekend, we had a prototype that looked like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/0*29ZcVeUwWak334-s." /></figure><p>Raft Challenge won the hackathon. The company announced that it’ll make the resources to improve the game.</p><h3>Let’s make it 2,5D!</h3><p>At the start of the project, Raft had the simplest possible graphics. A view was directly over a flat ground texture, with colored circles that indicated the player and the enemies. It was beautiful and as simple as the code underneath. Then our <a href="https://dribbble.com/allinmobile">graphic designer</a> came and messed up everything. He said, “Let’s make it 2,5D!”. The challenge was accepted and the animation above was the result.</p><p>After the hackathon he showed up once again. This time it was something more than one sentence.</p><p>It was an evil smile and this video:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/0*3TKCZXfkWaib8OYk." /></figure><h3>Perspective explained</h3><p>Ok, let’s drop the act :-). I’ve wanted to give him the feeling that he’s in charge. But I’m the boss here! The perspective is easy to implement in code, regardless of what 2D engine we use.</p><p>First, we have to determine where we want to put the <a href="https://en.wikipedia.org/wiki/Perspective_%28graphical%29#One-point_perspective">vanishing point</a>. The example below shows this point in the center of the canvas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/260/0*xnahdNb6kRoh-G7m." /></figure><p>Raft Challenge has this point in the upper half of the screen, because the sky and everything overhead isn’t as important as obstacles on the river.</p><p>How are the sprites themselves made? While it may be obvious for someone with artistic background, it isn’t necessarily clear for a technical person.</p><p>There are two rules:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/0*ipZT-l4zDgd9T6Iz." /></figure><ul><li>Moving parts must be drawn along the helper lines as shown above<br>All those lines intersect in the vanishing point</li></ul><p><strong>Note:</strong> The coast part isn’t reaching the vanishing point. It stops somewhere in the middle, leaving the transparent area behind.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/403/0*pr5ogyA1xVz0lgvv." /></figure><ul><li>That empty area between the graphic and the vanishing point has an important purpose<br>It’ll hold elements that are further away.</li></ul><p>Those parts are made by applying a twice smaller scale for each step. The resulting image should be seamless if the texture is well-made.</p><h3>Assembling the scene</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/685/0*4VyeL4eUI7iNyYqP." /></figure><p>After we’ve prepared all our assets, we need to put them all into the scene.</p><p>Let’s see how it looks in Raft Challenge.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/692/0*qAPitL_kSVE8ytz1." /></figure><p>Starting from the bottom:</p><ol><li>Background layers<br>Background <br>Grass <br>Fog bottom <br>Sun <br>Mountains <br>Horizon Line</li></ol><ul><li>These layers are all static they don’t move</li><li>Background acts for both the sky and water</li><li>The background is a plain gradient <br>It’s stretched to fill the entire device’s screen <br>The aspect ratio is ignored</li><li>We may merge layers other than Background for increased performance unless we want to change some properties</li><li>We may move the sun during the gameplay<br> or replace mountains for something different</li></ul><p>2. Perspective layers <br>Trees with reflections <br>Coast <br>Obstacles</p><ul><li>For the clarity of the image above, layers with similar content were grouped<br>There were: <br>2 layers of Obstacles<br>8 layers of Coast<br>8 layers of Trees with reflections</li><li>These layers are scaled up by 2 when a player is moving forward</li><li>Order of these layers depends on<br>distance <br>closer ones are on top<br>priority <br>Obstacle &gt; Coast &gt; Trees</li></ul><p>3. Character</p><ul><li>If an Obstacle is in the closest possible position, it may have z-position higher than the Character itself<br>In this case, the Obstacle covers the Character, which is desirable</li></ul><p>4. GUI</p><ul><li>Good graphics should depend on illusions and tricks instead of hardware</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/337/0*zgXz-u5twZohGh22." /></figure><h3>Summary</h3><p>This article should give us an idea how to approach the problem of making assets to a 2,5D game and organizing them into a scene.</p><p>You can read <a href="https://medium.freecodecamp.org/spritekit-advanced-how-to-build-a-2-5d-game-part-ii-30ddb613b568">part 2 of this series here</a>.</p><p>About the author: Kamil Ziętek is an iOS Developer at <a href="http://www.allinmobile.co/">www.allinmobile.co</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2dc76c7c65e2" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/spritekit-advanced-how-to-build-a-2-5d-game-part-i-2dc76c7c65e2">SpriteKit Advanced — How to build a 2,5D game (Part I)</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to not utterly ruin your mobile app’s user interface]]></title>
            <link>https://medium.com/free-code-camp/how-to-not-utterly-ruin-your-mobile-apps-user-interface-8433cee6477d?source=rss-e26c0d00f714------2</link>
            <guid isPermaLink="false">https://medium.com/p/8433cee6477d</guid>
            <category><![CDATA[startup]]></category>
            <category><![CDATA[tech]]></category>
            <category><![CDATA[ux]]></category>
            <category><![CDATA[design]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Łukasz Konior]]></dc:creator>
            <pubDate>Tue, 21 Feb 2017 02:03:10 GMT</pubDate>
            <atom:updated>2017-02-21T02:03:10.858Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tK71b_qIjCooHXqv3LNCmg.png" /></figure><p>There’s no single universal formula for designing a great user interface (if you discover one, please let me know). But I <em>do</em> know some major mistakes to avoid if you want to deliver a great app.</p><p>I’ve seen every one of these mistakes made by designers of all levels of experience. There’s no shame in that — a good UI design is a multifaceted challenge, and it’s easy to overlook some aspects of it.</p><p>At <a href="https://www.allinmobile.co/">All In Mobile</a>, we often redesign apps for clients who aren’t satisfied with their product and want to improve the way their app looks and feels. So today I’m going to share some major no-nos I’ve observed.</p><p>Of course, I’m all about fixing issues, not just pointing them out. So I’ll demonstrating all 5 of these major UI mistakes — then show you redesigned app views, so you can see how your team can fix them.</p><h3>UI mistake 1: Abusing fonts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*ORAnK2YUNv254DJP." /></figure><p>Let’s start with system font families.</p><p>For example, San Francisco is a system font for iOS, and Android has Roboto. They’re both easy-to-read and fairly similar.</p><p>Are system fonts okay to use? Yes, definitely. It’s a safe and proven option. But remember — Samsung phones allow you to change the default font. Your beautifully designed app can be killed in an instant if the phone user switches into Choco Cooky font.</p><p>You can also opt for a more sophisticated solution and choose a custom font. If you go this route, though, keep in mind: Less is more.</p><p>There might be plenty of awesome fonts, but be reasonable. <a href="https://twitter.com/intent/tweet?text=%22Fonts%20should%20add%20to%20the%20user%20experience.%22%20https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">Fonts should add to the user experience</a>. Too many types, sizes, or colors can complicate things.</p><p>If you do go for custom fonts, keep it simple and coherent. Add custom fonts only when needed, and where they can actually improve your app. And using custom fonts for the sake of having custom fonts is not a good enough reason.</p><p>License. A few months ago we were asked to redesign a fashion app. While reviewing the fonts, we came across 2 commercial fonts, both being used without any bigger purpose and without license. This mistake could have cost the client $2,000! A font is software, and always licensed. If you embed a font into a mobile app, make sure you read the license and the terms of use. Don’t know the license? <a href="https://twitter.com/intent/tweet?text=%22Don%27t+know+the+license%3F+Then+don%27t+use+the+font.%22+https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">Then don’t use the font</a>.</p><h3>UI mistake 2: Too much on the screen</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*WhHhf_ja5tRYYzM1." /></figure><p>When phones were much smaller, designers faced issues bundling necessary things onto the screen. For example, the iPhone 4 had 640×960 resolution and 2:3 ratio. With the advent of super-sized phones (or phablets), we can put more stuff on the screen — bigger fonts, more buttons, and fancier design.</p><p>Be wary of falling into this freedom trap. More isn’t more, so be selective. Every additional item has to be processed by the user. Attract their attention wisely so they can easily navigate the app. If there’s too much on the screen, users can easily get lost and wonder what to do or where to click. <a href="https://twitter.com/intent/tweet?text=%22Use+design+to+focus+the+user%27s+eye+on+significant+aspects.%22+https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">Use design to focus the user’s eye on significant aspects.</a> You want people to access the important content straight away and in an intuitive way.</p><h3>UI mistake 3: Lack of consistency</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*l9WJ6LDCfJ3qnbxD." /></figure><p>Be consistent when you design. <a href="https://twitter.com/intent/tweet?text=%22Be+consistent+when+you+design.+Don%27t+send+mixed+signals+to+users.%22+https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">Don’t send mixed signals to users.</a> If you use one element for a specific action, stick with it. Users learn by doing certain actions, and if they encounter unexpected or ambiguous actions, it can really ruin their experience.</p><p>Also keep a consistent layout — for the most part. For instance, use the same colors and elements to create a repeating pattern. Use style guides to set standards so that you can stay on the right track when designing.</p><p>Consistent layouts help users learn their way through your app, but you can have some exceptions, like the login page or other screens with dedicated uses. Whenever you break out of the pattern, keep in mind that every element still needs to make up a whole.</p><h3>UI mistake 4: Transferring from iOS to Android 1:1</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*caYTyIQwSJSw7XbG." /></figure><p>It made sense to do 1:1 transfers from iOS to Android until Android 4.0, when Holo Design appeared. This was the first sensible theme for Android, with structures, guidelines, and navigation that was incompatible with iOS.</p><p>Why not transfer directly from iOS to Android, or vice versa? Doesn’t it save you time and money?</p><p>Well, it <em>might</em>, but <a href="https://twitter.com/intent/tweet?text=%22the+ultimate+goal+is+to+create+the+best+user+experience%22+https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">the ultimate goal is to create the best user experience</a>, right? And users have habits and preferences. They use their phones all the time, and they grow accustomed to how their particular one functions. So if your applications behave differently than what people are used to, they’re way less likely to enjoy using it.</p><p>Android and iOS have their own interaction patterns, and users might not be pleased if you serve them something else they’ll have to learn from scratch. If you transfer from iOS to Android (or the other way around), you could also make consistency mistakes from device to device.</p><p>There’s good news, though — your app doesn’t have to look completely different for iOS and Android. Try to keep most of your visual style for both platforms. Take for example the case of car rental app Silvercar. They came up with their own navigation style, but at the same time they retained consistency between the mobile operating systems.</p><h3>UI mistake 5: Poor information hierarchy</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*-Q5z5_lILEF-3xIx." /></figure><p>When you design something, whatever it is — a business card, a website, an app — a person will interact with it in some way. You need to plan and design according to the degree of significance of the information you’re presenting, based on the way someone will interact with it.</p><p>Sit down and think about the most important thing you want to show. Once you know your priorities, you can distinguish significant things with the help of fonts, colors, size, location, etc. You need to think about what people do with your product — in ideal and non-ideal settings — and design it accordingly.</p><h3>Mistakes — and solutions — in practice</h3><p>Now we’re going to show you what all of these mistakes look like in practice, and how to fix them. As an example, we’ll redesign a view list for a food ordering app.</p><p>A client with a food ordering app decided to add the option of rating restaurants, but the previous design didn’t provide for such a solution. We took this opportunity to improve a few things.</p><p>The previous screen was designed at a time when iPhone 5 still held a greater share of the market. It had smaller cells, a smaller restaurant logo, and more compressed text. When viewed on new devices, too many elements appeared on the screen, making it more difficult to read.</p><p>That’s where we stepped in and made some changes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*FvYszCKRaT3Z9i_I." /></figure><p>As you can see, the cells are more distant from each other. They don’t fuse together anymore, and their information looks much clearer. The user isn’t overwhelmed by the number of items on the screen.</p><p>Also, the hierarchy of information has been improved. Now, the most important element is the logo. A returning user is more likely to quickly recognize the logo than to read the brand name. Previously, the name was fighting with the logo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*LAdWoP2GwzdoUCm_." /></figure><p>Another element that needed work was the typography. We used the Oswald font for names and tags. We initially anticipated only one line for tags, but some restaurants have a really rich offer, and so we enabled ourselves to fit as many tags as possible.</p><p>We also include visualization of the Android version with the system font and Choco Cooky on Samsung phones. We solved this issue by adding Roboto as the custom font.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*sZYUNpKOKn1AvEJx." /></figure><p>To add the rating portion the client wanted, we decided to use the stars. Hotels and Michelin Guides use it, so it made sense to us.</p><p>But there was a problem. We’d used stars in the previous design to mark favorite restaurants. We couldn’t place these 2 elements together because it’d be confusing. Liking a restaurant has nothing to do with its rating, and we would be left using the same symbol for those 2 actions. We didn’t want to be inconsistent, nor did we want to change the meaning of a symbol from one version to another. In the end, we solved the issue with a screen informing users a new feature had been added.</p><p><a href="https://twitter.com/intent/tweet?text=%22Design+isn%27t+science%E2%80%94there%27s+no+magic+formula+for+success.%22+https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">“Design isn’t science — there’s no magic formula for success.”</a></p><p>Even if you avoid these 5 major mistakes, what you designed might fall apart when the user comes into contact with it.</p><p>You simply can’t anticipate everything people might do. That’s why you have to observe the behavior and needs of the users, with the help of analytics and other tools. Then, react accordingly and improve your app. <a href="https://twitter.com/intent/tweet?text=%22Design+should+be+about+changing+to+improve+UX%E2%80%94continuously.%22+https://www.allinmobile.co/know-how/app-ui-design-mistakes/%20via%20@AllinMobileapps">Design should be about changing to improve UX — continuously.</a></p><p>Never rest on your laurels, because there’s always something you can design better.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8433cee6477d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/free-code-camp/how-to-not-utterly-ruin-your-mobile-apps-user-interface-8433cee6477d">How to not utterly ruin your mobile app’s user interface</a> was originally published in <a href="https://medium.com/free-code-camp">We’ve moved to freeCodeCamp.org/news</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>