<?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 Luka Leopoldović on Medium]]></title>
        <description><![CDATA[Stories by Luka Leopoldović on Medium]]></description>
        <link>https://medium.com/@luka.leopoldovic?source=rss-474c2c801171------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*uiMfY5dGTM1NSdnZUM7fAg.jpeg</url>
            <title>Stories by Luka Leopoldović on Medium</title>
            <link>https://medium.com/@luka.leopoldovic?source=rss-474c2c801171------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 11:23:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luka.leopoldovic/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[Android DBMS Performance Comparison Using the Jetpack Benchmark Library]]></title>
            <link>https://medium.com/swlh/android-dbms-performance-comparison-using-the-jetpack-benchmark-library-19581bf67443?source=rss-474c2c801171------2</link>
            <guid isPermaLink="false">https://medium.com/p/19581bf67443</guid>
            <category><![CDATA[database]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[benchmark]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[jetpack]]></category>
            <dc:creator><![CDATA[Luka Leopoldović]]></dc:creator>
            <pubDate>Tue, 02 Jun 2020 15:42:34 GMT</pubDate>
            <atom:updated>2020-06-03T10:13:24.788Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TAiLdqBicvzEdwKEkCrAUQ.jpeg" /></figure><p>There are plenty of Android database management systems you can choose from and you will probably pick one based on multiple factors: intuitiveness/ease of use, flexibility, documentation, <strong>performance</strong>.. However, if exactly the performance is the major factor, this article might have some answers for you.</p><h4>TESTING SETUP</h4><p>In this research, I have benchmarked the speed of executing the CRUD operations on various datasets for six highly popular Android DBM systems:</p><ul><li>SQLite,</li><li>Room Persistence Library, v 2.2.5,</li><li>DBFlow, v 4.2.8,</li><li>GreenDao, v 3.2.2,</li><li>Realm, v 6.0.2,</li><li>ObjectBox, v 2.5.1.</li></ul><p>The benchmarks were done under the standardized conditions. Each DBMS was tested:</p><ul><li>using the same datasets,</li><li>using the same code-base,</li><li>multiple and the same number of times (49 measures per benchmarked operation per dataset size, with the total of three runs for each test class),</li><li>on the same device (Google Pixel 2, Android Q) via the same host,</li><li>while the device was in the air-plane mode,</li><li>while there were no other applications running in the background,</li><li>in the sustained performance mode,</li><li>using the Android Test Orchestrator to ensure the minimum shared state between the tests.</li></ul><p>The datasets used for testing contain 10k, 20k, 30k, 40k and 50k cities. At the moment of conducting the research, I have experienced some issues while running the performance tests with the current version of Android Studio (3.6.3); therefore, I used the Android Debug Bridge (adb) for both running the tests and generating the detailed benchmark reports. However, I gave the tests a run with the newly released version of Android Studio (4.0) and everything seemed to be working fine, at least for the base test runs.</p><p>As mentioned before, the measurements were made using the Jetpack Benchmark library. Even though I am leaving the library as a topic for another blog, I will quickly brief you about some advantages you can benefit from by using it:</p><ul><li>it runs each measurement several times,</li><li>in addition to the multiple measurement runs, you can generate the detailed report for your benchmark results containing different statistical parameters related to the measurements, like the minimum, maximum and median time,</li><li>if using with adb, you will get some extra statistical data in the terminal output, like the mean value and the standard deviation,</li><li>while using with devices which support the sustained performance mode, the library will use a combination of this API and launching its own activity to both prevent thermal throttling and stabilize results.</li></ul><p>In conclusion, there was 147 measurements made per operation (per dataset size), resulting in total of 2940 measurements made per DBMS and 17 640 measurements for the entire research, which should make the results reliable.</p><p>At the end, I ended up with plenty of tables following the later pattern.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*ap2tt2zz4Az4H6mQvww9Gg.png" /></figure><p>The mean value of all the runs in milliseconds is used for the further comparison. If you want to fully preview the detailed results, check this <a href="https://docs.google.com/spreadsheets/d/1dBUTe_wXP_-lZSE6Eq7I3fjty9p__TpZxfqRbmE_-Uk/edit?usp=sharing">sheet</a>.</p><h4>INDIVIDUAL RESULTS</h4><p>Each DBMS will be presented with its own, individual results first, and the mutual comparison will be done afterwards.</p><p><strong>SQLite:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bOOMGfTQ1EKLrcyW6ahS4Q.png" /></figure><p>Comparing to the other relational DBM systems, the times for executing the create and update operations are almost identical.</p><p><strong>Room:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oSU5t4udHAxTkAwmerLk8A.png" /></figure><p>There is a clear separation between the times necessary to execute each of the CRUD operations. The speed of deleting the rows is blazing fast.</p><p><strong>DBFlow:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yd1yjGYu-3MPTfMwoNFePg.png" /></figure><p>Has the slowest reading speed of all relational DBM systems. For 50 000 rows, the times necessary for reading and creating the rows are almost the same.</p><p><strong>GreenDao:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5hS3bDnvpdzBbvUFaAsWw.png" /></figure><p>The slowest relational DBMS in terms of updating the data, but the fastest in terms of reading the data from the database.</p><p><strong>Realm:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-5SCZ8YW6iQODEStqLaDyg.png" /></figure><p>No, the Read line is not missing here. Moreover, the speed for reading the data is so fast that its representation on the chart is being covered with the Delete line. Contrary, requires the most time to perform the Create operation, compared to all of the benchmarked DBM systems.</p><p><strong>ObjectBox:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C3WOOuv1GhA5qSqu5BHlxA.png" /></figure><p>A quite nice surprise in terms of performance. This was by far the fastest DBMS taking the overall performance into account.</p><h4><strong>MUTUAL COMPARISON</strong></h4><p>In this section, the individual results will be mutually compared. For each operation a rank will be formed where database management systems will be positioned from the fastest to the slowest. To form the rank, a coefficient is formed by ranking the DBM systems from the fastest to the slowest for the executed operation per dataset size. For instance, the systems were ranked for reading the 10k rows from the database. They were ranked again for reading 20k rows. The procedure was repeated for all dataset sizes. The final ranking for the operation was created by calculating the average of the previously formed ranks. If the average rank values for two or more DBM systems were the same, a tie was called.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OZ5cWlDN6UPia99RDIhZzQ.png" /></figure><p><strong>Rank:</strong> ObjectBox, SQLite, DBFlow, GreenDao, Room, Realm.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zqgpTbOr37qb0sUS8oK1Dg.png" /></figure><p><strong>Rank:</strong> Realm, ObjectBox, GreenDao, Room, SQLite, DBFlow.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mlEbAuAwyl0dtzIzPoOP6A.png" /></figure><p><strong>Rank:</strong> ObjectBox, Realm, SQLite, DBFlow, Room, GreenDao.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NWU54BRVO_yAggrVPKM3mw.png" /></figure><p><strong>Rank:</strong> Realm, Room, ObjectBox, DBFlow/GreenDao (tie), SQLite.</p><p>At the end, the average rank was calculated, giving the final, general ordering of the tested database management systems (from the fastest to the slowest):</p><p><strong>ObjectBox, Realm, Room/SQLite </strong>(tie)<strong>, DBFlow/GreenDao </strong>(tie).</p><h4>CONCLUSION</h4><p>The scope of the research includes benchmarking of the CRUD operations. The benchmark was made using the Jetpack Benchmark library with the total of 17 640 measurements made. Currently, the object-oriented DBM systems show better results for performing the most of the tested operations. However, that does not have to be the case if more complex operations were introduced.</p><p>Once again, the presented rankings are related to performance only and do not cover various other factors which may determine which DBMS would suit your project the best.</p><p>You can check the entire <strong>benchmark code</strong> on my <a href="https://github.com/Luja93/AndroidDBMSPerformanceBenchmark">GitHub</a>.</p><p>Hope this was helpful! Let me know what is your DBMS of choice in the comments. :-)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19581bf67443" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/android-dbms-performance-comparison-using-the-jetpack-benchmark-library-19581bf67443">Android DBMS Performance Comparison Using the Jetpack Benchmark Library</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MVP vs MVVM — choosing the right Android architecture]]></title>
            <link>https://medium.com/swlh/blog-mvp-vs-mvvm-choosing-the-right-android-architecture-28c5105ca4a1?source=rss-474c2c801171------2</link>
            <guid isPermaLink="false">https://medium.com/p/28c5105ca4a1</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[mvvm]]></category>
            <category><![CDATA[mvp]]></category>
            <category><![CDATA[software-architecture]]></category>
            <dc:creator><![CDATA[Luka Leopoldović]]></dc:creator>
            <pubDate>Thu, 13 Feb 2020 17:34:37 GMT</pubDate>
            <atom:updated>2020-02-20T17:59:01.808Z</atom:updated>
            <content:encoded><![CDATA[<h3>MVP vs MVVM — choosing the right Android architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aI177jLe8u8frZK9Dw7bCg.jpeg" /></figure><h3>Software architecture is probably one of the most popular topics among developers, regardless of the platform you build for. With all the available frameworks and tools for asynchronous programming, dependency injection, networking, data caching and view-bindings, many patterns have evolved and some have stood out from the bunch.</h3><p>However, it is impossible to find the golden-gem of architecture that will fit everyone, especially if you’re trying to build a sustainable infrastructure as the core. The solution? Constant upgrades and enhancements to fit your needs the best. This story is all about that. It will delineate our transition from one pattern to another, elaborate why we replaced a well worked-out <strong>MVP</strong> base for <strong>MVVM</strong>, and how we did it.</p><p>When starting a new project, we use our base (template) project as the ground floor. It contains all the elements we’ll certainly use to code an app:</p><ul><li>it imports all the dependencies we’ll use in the project</li><li>it sets up networking/caching/etc. libraries in advance</li><li>it sets up the dependency injection graph</li><li>it contains dozens of utils and helper classes for easier, cleaner and faster coding</li><li>it enforces you to build upon the ground floor and work with the architectural pattern it’s set-up for</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jDNC5iRm4EIKmxVx" /></figure><h4>A BRIEF MVP IMPLEMENTATION OVERVIEW</h4><p>Our <a href="https://gitlab.com/bornfight-mobile/android-public/androtemplate">MVP template project</a> was created 5 years ago and has been constantly upgraded ever since. In our case, every screen we create (assuming there is a business logic) consists of three layers (the <strong>Model</strong>, the <strong>View</strong> and the <strong>Presenter</strong>) and a contract which binds them.</p><ul><li>the <strong>View</strong> should not contain any business logic and it should only manage the UI (for instance — bind views, programmatically set data which should be shown visually, handle click listeners, text watchers, animations etc.)</li><li>the <strong>Presenter</strong> represents the layer which triggers the business logic classes, transforms and prepares the data for the View — basically, it is the middle man between the Model and the View</li><li>the <strong>Model</strong> is responsible for database updates and/or web-server communication — it is a data provider.</li><li>the <strong>Contract</strong> provides a list of methods which the View or the Presenter should implement — essentially, it enables communication between the two layers</li></ul><p>MVP served us well through the years. It is an easy to follow design which deals well with the separation of logic. Unfortunately, it has some drawbacks which start to unfold as more code and more logic gets involved in the MVP triad.</p><h4>MVP — THE DRAWBACKS</h4><p>The first problem is the <strong>tight-coupling</strong> between the View and the Presenter. Each View holds a reference to the Presenter and each Presenter holds a reference to the View. In order for the two layers to communicate, a <strong>communication channel</strong> has to be opened via the Contract. This approach results in <strong>less-generic code</strong> (since the Presenter can’t be used as a layer in the MVP triad for another View). In a heap of communication methods, both the View and the Presenter will <strong>rapidly expand</strong> in the code-line size. There is also an <strong>extra layer of difficulty while writing unit tests</strong>, since there is a View dependency in each Presenter.</p><p>However, the biggest downside for us were the <strong>UI updates</strong>. In order to update a View component with data which has to be processed, the View must specifically be instructed by the Presenter. In other words, the View can’t “automatically” listen for the Model updates which the Presenter should expose. Therefore, <strong>“auto”-UI updates</strong> are hardly feasible. In order to succeed, we’d have to moderate the middle layer — the Presenter.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vH_-Doz2OdtQyxv9" /></figure><h4>MVVM TO THE RESCUE!</h4><p>Luckily for us, there are many different sets of tools that can be used to bridge a View and a business logic layer in a more efficient way. It is only a matter of the concept which suits the architecture you want to tailor the most. In particular, to untangle all the hanks MVP tends to create, but simultaneously keep some of its benefits (easy to understand and build upon, easily maintainable etc.) we decided to go with MVVM and, among other things, with the <a href="https://developer.android.com/topic/libraries/architecture">Android Architecture Components</a>.</p><p>Moreover, by switching to MVVM, we were able to resolve all the issues mentioned above:</p><ul><li>the View and the ViewModel (ex Presenter) are no longer tight-coupled</li><li>the ViewModel code is more generic</li><li>with proper abstractions, we reduced the previously rapid growth of the files for complex screens</li><li>the code is more testable</li><li>the “auto”-UI updates are live</li></ul><h4>HOW THAT WORKS?</h4><p>Now, every screen consists of three layers:</p><ul><li><strong>The View</strong> — still only handles the UI actions, without any business logic involved in any of its responsibilities</li><li><strong>The ViewModel</strong> — handles the communication of the view with the rest of the application (calling the business logic classes) and exposes the states/data to whomever needs to consume it using LiveData</li><li><strong>The Model</strong> — a data provider that updates the database or communicates with a web-server</li></ul><p>The complete flow is as follows: there is a View on top, which only has a dependency to (a) ViewModel(s). Since there is no longer a <strong>one-to-one relationship</strong> between the View and (formerly) the Presenter, it is now possible to couple multiple ViewModels to any View, since a ViewModel contains no View references. A ViewModel depends on repositories for fetching/caching data, and a repository will depend on a local and/or remote data source. In testing jargon, there is only one layer beneath the one you’re about to test, that you should mock (with the exception of a repository). Finally, since the states/data is exposed to its listeners via LiveData, we get <strong>“auto”-UI updates</strong> by simply observing it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*cig180RL1tfDXqF8" /></figure><h4>THE TRANSITION</h4><p>The idea for the transition did not come overnight. Moreover, we want our architecture to be perfectly balanced, so it’s powerful enough to satisfy the requests of highly-complex projects, and yet lightweight enough to be easily upgradeable and maintainable.</p><p>While creating the new skeleton, we kept up to the latter as the compass:</p><ul><li>the architecture must leave us enough room to easily add up extra modules (e.g. UseCases etc.) for more complex projects, and it should be sufficient to build smaller and medium projects as is</li><li>the structure we create must be easily testable</li><li>the base set-up should not force us to create or update a large number of files before we even started to work on a screen itself</li><li>we want to reduce boilerplate to minimum (e.g. RxJava calls etc.)</li><li>we want a set of default actions to be present under the hood (e.g. default loader or displaying error messages, default schedulers etc.), but again, those actions must be easily overridable if necessary</li><li>the code must be generic enough to fit all the cases we might encounter and easily adaptable if there is a case which is not directly supported by the foundations</li></ul><p>That is a long list to cross, especially if you take into account all the MVP eyesores. We agreed on building a demo project where we’ll try to create the core which will obey our list the most. That project must be simple enough to let us easily experiment with the schemes we try to accomplish, yet robust enough to test all the standard application components (networking, local caching, etc). So, we made a forecast app. The process of putting the things together took about a month, considering all the projects we did aside. It included a lot of brainstorming and mutual consulting, since it’s sometimes hard to see the whole picture if you’re standing too close to the board. We are very pleased with the final result, and it worked very well for the tasks and the scenarios we’ve put it through so far.</p><p>Is it perfect? Definitely not. Is it better than it used to be? We believe so. To discover the true advantages and, even more importantly, the disadvantages, we’ll have to build dozens of applications upon it, the same as we did with the MVP skeleton. One thing is certain — there is a plenty of brushing up and improvements our new base projects will have to go through, but we will do our best to maximize the benefits we gain from it — to fasten-up and boost our development speed, performance and quality. Having a base project as a starting point for every new application you make is extremely useful — if you have managed to set it up to be equally powerful as flexible. Besides performance boost, it appoints a well-designed standard you have to obey right from the start, which makes sure your code is consistent, clean and well-written.</p><h4>CONCLUSION</h4><p>Is MVP bad? No. Is MVVM better? It depends. For our needs and the complexity of applications we create, MVVM should help us get rid off some drawbacks MVP entails. On the other hand, new drawbacks regarding MVVM will appear, and we have to be ready to ameliorate them since the benefits of a well-designed architecture will always surpass the disadvantages.</p><p>If you are interested in how we assembled our new base project, stay tuned for the next blog which will explain it in detail.</p><p>Until then, feel free to use our <a href="https://gitlab.com/bornfight-mobile/android-public/androtemplate">MVP</a> or <a href="https://gitlab.com/bornfight-mobile/android-public/mvvmtemplate">MVVM</a> template project as a free starting pack, depending on what you think suits you better.</p><p>_____<br><strong>We’re available for partnerships and open for new projects. <br></strong><a href="https://www.bornfight.com/contact/"><strong>If you have an idea you’d like to discuss, share it with our team!</strong></a></p><p><em>Originally published at </em><a href="https://www.bornfight.com/blog/mvp-vs-mvvm-choosing-the-right-android-architecture/?utm_source=facebook&amp;utm_medium=social&amp;utm_campaign=blog_b_2020&amp;utm_term=leopoldovic_MVPMVVM&amp;fbclid=IwAR0CRsJMKzgAIVw_StVHVRXxim2LKGtKHICVD2ASDmoyw2FQVe4DJgxOhg8"><em>https://www.bornfight.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28c5105ca4a1" width="1" height="1" alt=""><hr><p><a href="https://medium.com/swlh/blog-mvp-vs-mvvm-choosing-the-right-android-architecture-28c5105ca4a1">MVP vs MVVM — choosing the right Android architecture</a> was originally published in <a href="https://medium.com/swlh">The Startup</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bring your games to life with particles]]></title>
            <link>https://medium.com/@luka.leopoldovic/bring-your-games-to-life-with-particles-f27c8ce57ee1?source=rss-474c2c801171------2</link>
            <guid isPermaLink="false">https://medium.com/p/f27c8ce57ee1</guid>
            <category><![CDATA[special-effects]]></category>
            <category><![CDATA[particlesystem]]></category>
            <category><![CDATA[digital-design]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[corona]]></category>
            <dc:creator><![CDATA[Luka Leopoldović]]></dc:creator>
            <pubDate>Tue, 28 Jan 2020 19:28:09 GMT</pubDate>
            <atom:updated>2020-01-28T19:28:09.937Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*lHawzlbpTfUFBveiSpe7LQ.jpeg" /></figure><h3>If you are a mobile game developer, or plan to develop a mobile game, then you are probably aware that using classic animation and sprites in your games may no longer do the trick.</h3><p>Since the <a href="https://www.bornfight.com/blog/choosing-the-right-features-for-your-custom-mobile-app/">mobile hardware</a> has gotten stronger, it can easily be utilized to produce much more effective and attractive results than the classic approach. What do I mean exactly? For example, if you are making an alien invasion game and have to show some fire, rain, thunder, fog, some special alien magic or even a meteor shower, using pre-built animations is a boring approach which may take a lot of time to build and is, most certainly, a static and restrictive form of animation. That means you are stuck with the animation you have pre-loaded in your game and altering it can be a challenging task — depending on the form of the pre-built animation. So, the question is clear — how to create dynamic, realistic and scalable animation that can be dynamically adapted to your needs, and not just in the way of size or speed, but also quantity, lifespan, motion, color and direction diversity…? That’s where a particle system comes to the rescue!</p><h4>A quick intro</h4><p>A particle system is a technique which enables you to recreate or simulate a certain phenomena by defining behavior rules for a group (large number) of small particles. Those rules may include several definitions, like geometry, physics or graphics of the particles. This technique is often used in game physics and motion graphics and is supported by many game engines. For this blog, I’ll use the <a href="https://medium.com/distant-horizons/corona-game-engine-when-how-to-apply-collision-events-93b42abf8110">Corona Game Engine</a> to create particle implementation since I use this engine for most of my games. But don’t worry, the same principles can be easily applied to other game engines, so I’ll try to make the blog as universal as possible. At least considering the particles themselves.</p><h4>Let’s dive into it</h4><p>What’s a better way to start a particles show-off than with a meteor shower, right? Well, just a meteor — at least for now. So, if you have never seen particles in action, now is the chance to do so. In the video below, you can see a meteor I created using a particle system. Pretty awesome, right?</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F387750410%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F387750410&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F850803331_295x166.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="426" height="222" frameborder="0" scrolling="no"><a href="https://medium.com/media/c0a583ec9e3d749b3d8d5c99c6fa5ce0/href">https://medium.com/media/c0a583ec9e3d749b3d8d5c99c6fa5ce0/href</a></iframe><p>Now, the question is how was this achieved? Let’s talk about the requirements. There are two key things defining a particle effect. First — since every particle effect consists of large number of small particles, you need an <strong>image</strong> that will represent a single particle. Second — as this image will be multiplied in the effect simulation stage, you need to define <strong>properties</strong> that will be applied to each and every one of them.</p><p><strong>The image</strong></p><p>The image should never be too complex. Most often, it’s a simple, small shape — single-colored image with an optional alpha-gradient. For better performance, it should also be as small as possible, considering both the file size and the image size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bkKYpEVeVTpXPM08" /></figure><p>You should always adjust or pick the shape depending on the effect your are trying to create. In particular, the left image was used to create the meteor effect. If I used the right image to create the meteor, I would still get an interesting result, but it wouldn’t quite resemble a meteor in the way the left image effect does.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F387776402%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F387776402&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F850835579_960.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="960" height="498" frameborder="0" scrolling="no"><a href="https://medium.com/media/173d7e864b47de449c6ecffab3d17591/href">https://medium.com/media/173d7e864b47de449c6ecffab3d17591/href</a></iframe><p><strong>Quick tip for designers:</strong> you can create a stash of dozens of images of different shapes, sizes and gradients and try out many of them while creating the effect. Once you get the effect properties set-up, just replace the image and see if it better suits your design preferences.</p><p><strong>Behavior rules — particle properties</strong></p><p>Next, that image will be multiplied many times and it needs to behave in the way you tell it to. But, what do you tell it exactly? The properties applicable to a particle (or a group of particles) can be divided into three categories: geometric, graphical and physical ones.</p><p>Geometric properties include basic definitions like the start and finish size of a particle, start and finish rotation etc. It also includes setting the variances of the properties. Right from the start, it is obvious why particles are a dynamic and non-restrictive form of animation. The properties you define will be randomly generated within the defined intervals and used to create particles. Consequently, every generated particle will have a different start and finish size, rotation etc. Additionally, if you wish, you can also set a specific property variance interval to 0 to ensure the static behavior of a specific definition.</p><p>Graphical properties apply the color and the alpha/blend settings to particles. These definitions include setting up the properties like:</p><ul><li>start red/green/blue color</li><li>start r/g/b color variance</li><li>finish r/g/b color</li><li>finish r/g/b color variance</li><li>start alpha</li><li>finish alpha</li><li>alpha variance</li><li>source blending</li><li>destination blending</li></ul><p>Pretty much, it’s a game you can play until you are satisfied with the results.</p><p>At this point, it would be great to make a distinction between a particle and an emitter. You can think of an emitter as the source of the particles that controls a particle system’s position and motion in 2D or 3D space. To make the distinction clear, it means there are certain properties that can be defined at the animation level. These would mainly be physical properties as the emitter is responsible for them. This enables you to define the particles as physical objects that will follow the motion rules you define:</p><ul><li>variances of the generated particles along the X, Y and Z axes</li><li>maximum number of particles</li><li>particle lifespan</li><li>X, Y or Z axis gravity</li><li>particle speed or speed variance</li><li>radial or tangential acceleration</li><li>min and max radius</li><li>rotations per second</li></ul><p>If you are interested in the complete set of attributes you can attach to a particle/emitter in the Corona Game Engine, take a look at this <a href="https://docs.coronalabs.com/api/type/EmitterObject/index.html">link</a>.</p><h4>Creating the effect</h4><p>The effect itself is actually very easy to configure. You can simply adjust the values of the <a href="https://docs.coronalabs.com/api/type/EmitterObject/index.html">attributes</a> by forming them in key-value pairs (I’ll show them below) or use the <a href="https://www.71squared.com/particledesigner">Particles Designer</a> if you are a Mac user. So, you can simply create an effect by dragging the sliders left or right without having to bother with the actual meaning of the properties. Nevertheless, knowing the background definitely helps to create desired effects easier and faster. Specifically, the meteor is defined as the “gravity” type emitter with increased value of the X gravity property (vs. zero value Y gravity) which attracts the sparks (particles) from the center of the meteor in the positive X axis direction, so you get the illusion of meteor leaving the trail behind it. Since every particle has a different lifespan and lifespan variance, only a small number of them will be generated with a longer lifespan — these particles will be pulled the most from the center and ‘form the trail’. As for the other elements, that’s mostly just playing with the colors.</p><p>If you are using the Particles Designer, the output you’ll get is a JSON file. The meteor effect particle definition I created looks like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cbf13f9da3f21f9e5f5bef29c6423461/href">https://medium.com/media/cbf13f9da3f21f9e5f5bef29c6423461/href</a></iframe><p>Now comes the developer’s part. To implement particles into your game, you first have to load the particle definition.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f0389d8d45bdd44159a6cf355b95fb8d/href">https://medium.com/media/f0389d8d45bdd44159a6cf355b95fb8d/href</a></iframe><p>As I said before, these can be key-value pairs as well. By doing that, you’ll find it much easier to alter the effect since every property can be easily reached and modified by the requirements of the game. For instance, if you are building an air hockey game and want to show an ice-chopping effect, you can (dynamically) emit the number of particles proportional to the force of the paddle hitting the puck. And that’s where the particles shine the most.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/20bf190352679ad56ecca336500d807d/href">https://medium.com/media/20bf190352679ad56ecca336500d807d/href</a></iframe><p>Now, you have to create an emitter object and position it on the screen. Don’t worry about the content positioning constants. You can find them in the meteor implementation <a href="https://github.com/Luja93/MeteorShower/blob/master/main.lua">code</a>.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fcae97b3d4287f0c8f7ea2bfa4ca396f/href">https://medium.com/media/fcae97b3d4287f0c8f7ea2bfa4ca396f/href</a></iframe><p>The created emitter object can be easily animated using the default transition library provided by the engine to move the effect through the (in my case) 2D space.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/efb47c77c99461d89a109b4276f6f3f8/href">https://medium.com/media/efb47c77c99461d89a109b4276f6f3f8/href</a></iframe><p>It is very important to highlight that particles won’t be destroyed until their lifespan and duration passes — even though they left the screen. Therefore, you should always adapt the effect duration to the actual needs to free the memory and improve performance. If your game needs to have long-running effects and it’s possible to switch the scene while the effect is still running, you can manually destroy the emitter to prevent memory leaks by using the following call:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/98e8a6769bdfdb10e3081b371e2deb03/href">https://medium.com/media/98e8a6769bdfdb10e3081b371e2deb03/href</a></iframe><h4>Performance tips</h4><p>As every particle effect is generated by multiplying the particle image and applying properties to each and every one of them, you should keep in mind and take care of both while creating effects. Too complex effects can easily affect performance, result in frame drops and ruin the gaming/user experience. To prevent that from happening, try to do the following things:</p><ul><li>use simple images to create effects</li><li>make images as small as possible, considering both the file and the image size — even though the image size will depend on the intent of the effect</li><li>use as few particles as possible to create the effect (try to reduce the maximum number of particles property as much as possible)</li><li>test your game on older devices to see how it performs and additionally reduce the maximum number of particles and/or adjust the effect to eliminate frame drops</li><li>properly remove emitters when switching the game scenes to free the memory and avoid memory leaks</li><li>don’t over-exaggerate with the usage of particles — they are fun and awesome, but should be used wisely and responsibly</li><li>many things still can and should be achieved using “the classic animation” approach</li></ul><h4>Where to go from here</h4><p>As any other display object, a particle object can also be added a physics body. That way you could detect when meteors hit the ground and, for instance, emit some explosion effect. If you are interested to learn more about physics implementation in mobile games, as well as detecting collision events, take a look at my <a href="https://medium.com/distant-horizons/corona-game-engine-when-how-to-apply-collision-events-93b42abf8110">collision implementation blog</a>. One more thing — keep in mind that emitters can also be attached to any other display object in the game, they can be additionally translated, rotated and scaled without altering its properties, so you definitely gain a lot of flexibility in regards to the effect manipulation.</p><p>Particles are one of those things that are extremely fun to play with, and since the implementation is not hard and it does not take a lot of work, it’s also a cool thing to experiment with — both from the design, as well as the development aspect. Even though you should not over-exaggerate with particle usage, a proper dose of the effect can definitely bring your game to another level.</p><p>Before we finish, I’ll leave you with the promised meteor shower -you can download the full code from my <a href="https://github.com/Luja93/MeteorShower">Github</a>. Have fun playing with particles!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fplayer.vimeo.com%2Fvideo%2F387750578%3Fapp_id%3D122963&amp;dntp=1&amp;display_name=Vimeo&amp;url=https%3A%2F%2Fvimeo.com%2F387750578&amp;image=https%3A%2F%2Fi.vimeocdn.com%2Fvideo%2F850803476_640.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=vimeo" width="640" height="332" frameborder="0" scrolling="no"><a href="https://medium.com/media/a1555a448ff4d080fd1a7fb065b8597a/href">https://medium.com/media/a1555a448ff4d080fd1a7fb065b8597a/href</a></iframe><p><em>Originally published at </em><a href="https://www.bornfight.com/blog/bring-your-games-to-life-with-particles/"><em>https://www.bornfight.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f27c8ce57ee1" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Corona Game Engine: when & how to apply collision events]]></title>
            <link>https://medium.com/distant-horizons/corona-game-engine-when-how-to-apply-collision-events-93b42abf8110?source=rss-474c2c801171------2</link>
            <guid isPermaLink="false">https://medium.com/p/93b42abf8110</guid>
            <category><![CDATA[mobile]]></category>
            <category><![CDATA[game-development]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[corona]]></category>
            <category><![CDATA[lua]]></category>
            <dc:creator><![CDATA[Luka Leopoldović]]></dc:creator>
            <pubDate>Wed, 24 Apr 2019 12:12:51 GMT</pubDate>
            <atom:updated>2019-04-26T14:04:16.818Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FAhI2kzl9lN-1WV_HtZH8Q.jpeg" /></figure><h3>You’ve probably played lots of mobile games that implemented physical properties and behaviour in certain game aspects. For instance, jumping off the platforms in Doodle Jump or demolishing wood piles in Angry Birds.</h3><p>But, have you ever wondered what’s behind all those interactions and how does the Doodler know when he can pass through a platform, and when to bounce up from it? How can that wood pile collapse so realistically when an Angry Bird hits it? It’s actually not that hard. They all get by with a little help from collision events.</p><p>Since most of my games are made with the Corona Game Engine, I’ll use Corona Collision (Physics) implementation and the Lua programming language to describe and code the examples related to the topic. Nevertheless, similar principles can easily be applied with other game engines as well, since many physics engines work much alike. Corona, in general, does such a wonderful job with the docs, so you may see a couple of references to the documentation in this text, since there was just no point in reinventing the wheel. :)</p><p>So, let’s dive into it!</p><h3>General overview</h3><p>First of all, it is important to highlight that every game engine uses a physics engine in the background to deal with physics. Corona, in particular, deals with physics by using the Box2D physics engine. This enables you to implement functionalities from the world of physics by simply assigning the physical properties to objects in the game and handling their interactions with proper methods.</p><p>Collision events are one of those. They enable you to detect and handle collisions between physical objects. Imagine playing a simple game where the character collects falling objects, catching the good ones and avoiding the bad ones. To detect when the character had interacted with a falling object, you would simply do a check in the collision event you had previously assigned to the character and to the falling objects.</p><p>This check can be as basic as:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1cd4b9a3cb97c6fd2a036a943a196fe8/href">https://medium.com/media/1cd4b9a3cb97c6fd2a036a943a196fe8/href</a></iframe><p>Since collision events are physical interaction detectors, it is assumed you had previously added physics bodies to objects you want to be able to interact with. This definition is simple, but it’s a must if you want your objects to correspond to physical interactions.</p><p>For instance, you could say:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/31a3345c1c497b5b0e1ead1b7401ec4b/href">https://medium.com/media/31a3345c1c497b5b0e1ead1b7401ec4b/href</a></iframe><p>As you can see, there are several definitions included here: the type of body (dynamic bodies move under simulation according to the forces like gravity or reactionary collision forces, and they accept the application of velocity, static bodies will not respond to the forces like gravity and they will act like they have infinite mass, kinematic bodies move under simulation only according to their velocity etc. — you can learn more about it on <a href="https://docs.coronalabs.com/guide/physics/physicsBodies/index.html">coronalabs.com</a>) and the physical properties which will take action in various physical interactions. For instance, if our character was a ball hitting the ground, it would bounce off pretty high since much of its velocity would return after the collision (bounce = 0.8). If our character was a man climbing a hill and we don’t want him to lean backwards and fall down while climbing it, we could freeze its rotation around a specific axis etc.</p><p>This all may sound like it takes a lot of specialized knowledge to implement, but it really doesn’t. A lot of simple games can easily be created with just the basic understanding of physics, since the engine handles most of the things for you.</p><h3>Collisions in specific</h3><p>As I said before, collision events enable you to detect and handle collision between physical objects. There are several types of collisions possible to define with Corona:</p><ul><li><em>pre-collision</em></li><li><em>collision</em></li><li><em>post-collision</em></li></ul><p>There’s also a sub-case of each collision event, defining it as:</p><ul><li><em>local collision</em></li><li><em>global collision</em></li></ul><p>Which one you choose depends on what you plan to do.</p><p>Let’s start with global vs. local collision. Local collisions are best utilized in one-to-many collision scenarios, while global collisions are best utilized in many-to-many collision scenarios — you can get the specifics on <a href="https://docs.coronalabs.com/guide/physics/collisionDetection/index.html">coronalabs.com</a>. So, our character, catching the good falling objects and avoiding the bad ones would perfectly fit with a local collision event. If your game had multiple characters, consider using a global collision event, which is defined as a global runtime, detecting collisions between all physics objects in the game.</p><p>Local collision events are described with <em>self</em> and <em>event</em> params, representing the object itself and, among else, other Corona display objects involved in the collision. Corona display objects possess a really cool feature — they behave like Lua tables, meaning that various data, like names, identifiers or categories can easily be added to them. This particularly comes to use while dealing with collision. An identifier can be added to every good and bad object (e.g. “good”, “bad”) and by comparing those identifiers inside the collision event, it is very easy to find out which one did the player just collect. If it is a good one, you could award player with score points. If not, you could reduce his life points.</p><p>This scenario can easily be built using regular <em>collision</em>. That means you are able to detect physical contacts between objects which are assigned a physics body. This event consists of <em>began</em> and <em>ended </em>phases, so you could perform actions on initial and broken contact moments. For instance, imagine you’re building a space game like Little Galaxy and you have defined your planet’s gravity fields using the physics joints technique. With <em>began</em> and <em>ended</em> phases of the collision event, you could find out when a satellite has entered and left the planet’s gravity field and then perform certain actions. Let’s return to our character catching the obstacles and see how this looks in action.</p><p>First of all, I’ll create some global constants for dealing with different screen sizes. This approach may vary from developer to developer. This one is related to content size defined in <a href="https://github.com/Luja93/CollidingWithCorona/blob/master/Collision%20with%20Corona%20Game%20Engine/config.lua">config.lua</a> and I have personally found this method to be most suitable for my use.</p><p>I will also create global enumeration, which I will use later as an identifier for falling objects:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5ce348112ad78e65856fefa3f582298/href">https://medium.com/media/d5ce348112ad78e65856fefa3f582298/href</a></iframe><p>Furthermore, I will implement the necessary library, start the physics and “turn off gravity”:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7c77008324cec2a87489361ab1bbcefd/href">https://medium.com/media/7c77008324cec2a87489361ab1bbcefd/href</a></iframe><p>Next, I am going to create our character. For the sake of example, it (as well as the falling objects) is going be represented with a simple circle:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/71661d20440a37e0273c0e68f70a1b95/href">https://medium.com/media/71661d20440a37e0273c0e68f70a1b95/href</a></iframe><p>The character has the Y anchor property set as 1. This means its Y axis reference point is set to its lowest point. Consequently, when it is positioned to the center of the screen, the circle bottom will be placed there. This will be very important in later “Doodle Jump” (<em>post-collision</em>) example.</p><p>As mentioned before, all objects that should participate in physical interactions, must be assigned a physics body:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bae4f7989cc58c37e50dcfa59287ecff/href">https://medium.com/media/bae4f7989cc58c37e50dcfa59287ecff/href</a></iframe><p>Notice that I have defined the character as a sensor. This means other physical object won’t be able to physically interact with the character (no bounce, no friction etc.) but we’re still going to be able to detect collisions. This principle is often applied when we don’t want objects colliding and flying around the screen due to following physical behaviour, but simply detect when they have interacted and do something based on the interaction itself (e.g., increase or decrease score).</p><p>Now, let’s create a function for generating falling objects:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1d70b88c858e8b07e88658a4ba32fa2f/href">https://medium.com/media/1d70b88c858e8b07e88658a4ba32fa2f/href</a></iframe><p>This function will be called with timer, generating an object every 2 seconds and animating it from the top to the bottom of the screen. As you can see, every obstacle is identified with a previously defined enumeration and, for visual differentiation, every good falling object will be colored green, while the bad ones will be colored red.</p><p>Now, you may wonder why do I set falling objects as sensors as well? In a worked out game scenario, you may want to use the accelerometer to lean your character left and right to collect/avoid falling objects and randomly generate the position where a falling object will start its journey to the bottom of the screen. If you narrow the time interval necessary for the object to generate as the player progresses through the game, it is likely that some obstacles will be generated very close to each other.</p><p>If they were not set as sensors, they would collide and behave very unnaturally, since transitions (not gravity!) are used for moving the objects from the top to the bottom of the screen. This way, especially if their falling speeds differ, they may freely pass through each other and you can still detect character collisions with these objects, since both are defined as physics bodies.</p><p>Now’s the time to define our collision event in the form of a function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/503d78891a6353e8e957044d5e78f984/href">https://medium.com/media/503d78891a6353e8e957044d5e78f984/href</a></iframe><p>This event must be joined and tied to our character in order to have any effect:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60010072a9a6c0b3d7669b49a653fbad/href">https://medium.com/media/60010072a9a6c0b3d7669b49a653fbad/href</a></iframe><p>Our listener now “listens” for any physical interactions our character gets involved with. Once it interacts with a falling object, a simple check is done to see if user collected a good or a bad object. For every good object collected, user is awarded with 10 points. On the other hand, if he collects a bad object, his points are reduced by 10. When that’s done, the falling object will be removed, and the character will be nicely animated to visually show a collision has occurred.</p><p>Let’s preview the results!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/420/1*sbPeXzamTDlwta7DnfhROg.gif" /><figcaption>Object-catching game in action</figcaption></figure><p>As you can see, this was all easily accomplished since there is a physics engine in the background dealing with all the complex stuff for you. You can download the full code <a href="https://github.com/Luja93/CollidingWithCorona/tree/master/Collision%20with%20Corona%20Game%20Engine"><strong>here</strong></a>.</p><p>Now, let’s see how <em>pre-collision</em> can be easily applied to accomplish some interesting behaviour. Maybe the best example to show this would be to create a Doodle Jump-like platform game with a bouncing character. Believe it or not, this essential game functionality isn’t any harder to implement than the previous “object-catching” one. We’ll start the same by first defining the UI elements and giving them a physics body.</p><p>This time, these are going to be a player and a set of hard-coded platforms:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72073b183ef9a4953c1f6b548ffd292a/href">https://medium.com/media/72073b183ef9a4953c1f6b548ffd292a/href</a></iframe><p>Again, notice the platforms are given an identifier and this time, they are defined as static bodies, while the character is still a dynamic one. The reason behind this is gravity:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c1267676f1ca25d32136a83a6f75f70/href">https://medium.com/media/0c1267676f1ca25d32136a83a6f75f70/href</a></iframe><p>In order for platforms not to collapse and fall down, they must be defined as static bodies, meaning they will not respond to forces like gravity. Our player, on the other hand, must be pulled down every time he jumps. Notice that the Y anchor point of our character is again set to its lowest point. This will be used in pre-collision event, checking if the character position (his feet) are above or below the platform he’s about to collide with.</p><p>If his feet are below, disable the contact. If his feet are above, give him a little push into the air:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5d9411a71be152f3800fc847b48bf791/href">https://medium.com/media/5d9411a71be152f3800fc847b48bf791/href</a></iframe><p>Pre-collision is a bit noisy and it can fire multiple times per contact. To give our character only one push into the air per contact, we can get his linear velocity, and based on the velocity sign (Y direction) determine if the character is falling down and approaching the platform. Since our character’s initial velocity is 0, we need to give him a little push at the start and he is good to go!</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/64954df45d4b148720aa6b76fc19f97e/href">https://medium.com/media/64954df45d4b148720aa6b76fc19f97e/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/443/1*0eznNcpquuqY2nqH4B-TzQ.gif" /><figcaption>Platform jump game in action</figcaption></figure><p>The next step would be creating a function for randomly generating platforms and moving them downwards as the character jumps up. Since that is not the topic, I’ll leave that for another blog. I just want to mention that these particular mechanics can be accomplished by using a variety of approaches. For the sake of the example, I have chosen this one. Don’t be scared to experiment! You can download the full demo code <a href="https://github.com/Luja93/CollidingWithCorona/tree/master/Pre-Collision%20with%20Corona%20Game%20Engine"><strong>here</strong></a>.</p><p>The last, but not least is a <em>post-collision</em> event. It’s the only collision event where the collision force and friction are reported (again, more info on <a href="https://docs.coronalabs.com/guide/physics/collisionDetection/index.html">coronalabs.com</a>). What this means for you as a game developer? Based on these values, you could, for instance, determine the strength and the quantity of certain events.</p><p>If you’re making a pinball game, you could play the sound of the bat hitting the ball proportional to the event force. If you are building an ice-hockey game and use particles to display ice chopping when a paddle hits the puck, you could emit more particles with a stronger hit.</p><p>For this example, I’ll create a ball hitting our character’s circle.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3533661e1292974d2d2e63c0f8d23e6e/href">https://medium.com/media/3533661e1292974d2d2e63c0f8d23e6e/href</a></iframe><p>The ball is placed vertically below the character. Now, I’ll apply some force to it, directing it towards the character, but with random X and Y force values, so you could see the differences in the final result (behaviour) after the ball was steered slightly different and hit the character at a different point.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a67af2345f1375890d2e34ad5d424f91/href">https://medium.com/media/a67af2345f1375890d2e34ad5d424f91/href</a></iframe><p>Post-collision event can be defined like this:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/762bfe3a082463db4f003143a8e255ae/href">https://medium.com/media/762bfe3a082463db4f003143a8e255ae/href</a></iframe><p>And the final result looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/444/1*qgcO8hC0-7N7i_EsTbgW2w.gif" /><figcaption>Post-collision game in action</figcaption></figure><p>The character is moving pretty realistically after the hit, right? All we did was set a few properties to the objects and the physics world itself. It’s because all mechanics behind this event are handled for you by the physics engine. Full code can be found <a href="https://github.com/Luja93/CollidingWithCorona/tree/master/Post-Collision%20with%20Corona%20Game%20Engine"><strong>here</strong></a>.</p><h3>Conclusion</h3><p>As you can see, collision manipulation is pretty handy. Since the physics engine does most of the stuff for you in the background, many basic (but very effective) things can easily be accomplished with just the basic understanding of physics and, of course, the game engine you’re working with.</p><p>Collision events can and should be paired with various other events, leaving you with endless possibilities, limited only by performance and your imagination.</p><p>__________<br>We’re available for partnerships and open for new projects. <a href="https://www.bornfight.com/contact/">If you have an idea you’d like to discuss, share it with our team!</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93b42abf8110" width="1" height="1" alt=""><hr><p><a href="https://medium.com/distant-horizons/corona-game-engine-when-how-to-apply-collision-events-93b42abf8110">Corona Game Engine: when &amp; how to apply collision events</a> was originally published in <a href="https://medium.com/distant-horizons">Distant Horizons</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>