Best Games of Telegram

Since Telegram announced its Game Platform we have been very enthusiastic to work in it as you might already know. After all, along this article, we have already published a tutorial about how to develop a game bot and another tutorial about porting your HTML5 games to Telegram.

But we also like to play and we realized it is not very easy to find games in Telegram (only for the moment… we hope); that’s why we want to list here our favorites games.


Don’t Die in @DontDieBot

Listen to me, this is a good one. Really challenging but extremely easy to learn. The responsiveness of the controls is perfect.Do Not Die

In each level you drag your character to pick up a key that will open the door of the next level. But don’t let the zombies see you… or smell you.


iBasket in @ludeiBot

What? Yes, it is one of our games, but we really worked hard on it to create a good game. And more than once we have had bad looks at the office when someone gets the first place in the rankings.iBasket HTML5

Simple. Colorful. Fun. Throw the balls and get the maximum amount of points in 90 seconds. Don’t think too much, if you don’t score for a certain amount of time you lose the score multiplier. And listen here, the key to be the best: clean shots give you 5 extra seconds of play, maybe using 2 seconds to aim instead of 1 is worth it.


Kung Fu Inc in @gamee

Tap left or right to throw a punch in either direction to destroy… vacuum cleaners?

Kung Fu Inc

Yep, that’s right. I guess somebody doesn’t really like Roombas. Try to not throw punches in the air, the combo multiplier is the key to reach the top of the ranking.


Jumper Frog in @microgamesbot

An old classic not so common nowadays. If you are young maybe you don’t even know it.

Jumper Frog

Jump across the road avoiding the cars and use the turtles and the logs to not fall in the water (just ignore the fact that every frog can swim, we all do). Your objective is to reach the top of the screen and eat every fly in the way.


Flappy Bird

There is more than one Flappy Bird and there aren’t many differences but visual aspect. Play the one you like the most, all of them are equally addictive.

Flappy BirdJumping SubmarineSkipper

Meteoric and Meteoric Plus in @gamee

Combine similar asteroids to form a planet. Combine the planets to create stars. Combine the stars and watch it EXPLODE!

In Meteoric, the asteroids fall from the top and you have to pile them next to their alike to combine them; whereas in Meteoric Plus, the asteroids appear randomly and you drag everything to the top, right, bottom or left (like in the game 2048), if two similar objects collide they will fuse.


2048 in @awesomebot

Speaking about 2048, that is a great game too. Of course we can find it in Telegram.

2048

One of the best games to compete with your friends. But for the love of Cthulhu, keep your highest tile in a corner of the board.


Sumon in @ludeiBot

A target number appears, you have to combine numbers in the board to sum the exact amount. Then, the target changes and you have to do it again until there are no more numbers in the board to complete the level. Easy, right?

Well, you have to do it fast; and it is better if the numbers you combine are far apart from each other. If you are one of those who asks why bother learning to do mental calculus if every mobile has a calculator nowadays, maybe it’s not that easy.

Sumon

Every level concedes notably more points than the previous one. So you might think that playing in a easy level for several minutes will assure you a place in the winners podium, when actually, anybody capable of playing in a harder level will surpass your score in a matter of a minute.


Hextris in @awesomebot

I’m sure you know Hextris. Another of those extremely simple games but incredibly competitive. Share it in your chats, you will see how everybody tries to get the record but “casually, they were just playing in the public transport”. Yeah… suuure… me too…

Hextris

I haven’t even put any effort to get that screenshot, I could do it better…


Do you agree with our list? Did we miss any game? Leave a comment if you found a really good game we didn’t list here. We want to try it, it’s not easy to find them.

How to adapt HTML5 games to be published on Telegram

The Announcement

On October 3rd, Telegram published its gaming platform. Now, the bots are able to launch HTML5 games inside Telegram and share your score with your friends. @gamebot and @gamee were the two first bots announced and Ludei is not going to be the last when it comes to HTML5.

The Rules

When creating a game with @BotFather, he will make you accept a series of rules:

  1. You will not implement any ads or any external links on your custom URL pages.
  2. You will not invite users to pay for any services provided on custom URL pages.
  3. You will not use any data collected over the course of user interaction with your custom URLs for spamming Telegram users.
  4. You will not transfer any Telegram data collected over the course of user interaction with your custom URLs to any third parties.
  5. In order to protect the privacy of Telegram users, your custom URL pages must not set any cookies.

Now, those are some serious rules that made us change some things in our games.

Due to these rules we had to remove every way of promoting the rest of our games and every social media integration like Twitter or Facebook. Thankfully, we didn’t collect any information for third parties neither used cookies in our games -removing all that sounds like a headache.

Game Rules by @BotFather

Game rules by @BotFather

Sharing the games

The first thing you notice when reading the technical post is the script you have to include inside your games. It is a rather short script. This is because launching a game inside Telegram means opening a URL, provided by our bot, in the webview of Telegram. Our game should need hardly any changes.

<script src="https://telegram.org/js/games.js"></script>

This script provides us with the TelegramGameProxy.shareScore() method, which is used to share the game (but not a score, weird) with Telegram chats. It works like the usual share button in Telegram, there is no complexity with this part. We added a button with the shareScore() function at the result screen of each game in case you don’t know what to do with it.

Sending scores

The name “shareScore“ is quite confusing since you can’t even pass it a parameter to share. To actually send a score you should also read our post about a game bot creation. The game must send the score to the bot (with a HTTP POST, in our case) and the bot is responsible of notifying Telegram of our score. But how does the bot know who we are when it receives it? We solved this problem sending along the score a number of identifiers the bot previously added to the URL of the page. These identifiers are always userId (identifies the user) and either inlineId (if the bot was summoned with an inline call), or the pair chatId and messageId. The necessary ones are in the request Telegram sends to our bot when a user taps the play button.

Update scores in Telegram

@ludeiBot updates scores in Telegram

To sum it up: the user activates the play button, Telegram asks our bot for a URL to open and sends the identifications of the user, the bot returns a URL containing those identifiers in a query, and finally, our game can send the score and the identifiers of the user so the bot can update the rankings.

Detecting Telegram

At this point we have a game that can be published to Telegram, but why would we use two versions of the source code of our game? We still want to be able to promote our games if the user plays at ludei.net. If we can know when the game is executing as a Telegram game we can serve it from its original server to Telegram. Any special change we made for Telegram just has to follow a condition.

At first we tried checking window.TelegramWebviewProxy !== undefined  (like Telegram does in its script), but somehow TelegramWebviewProxy is undefined even inside the Telegram webview, so in the end, we just check if the URL contains the identifiers of Telegram our bot adds. In our case the identifiers were query parameters because our games already had a method to parse them. Although they could have been hash parameter too; Telegram exposes an object containing them.

Testing your game

The last thing to do is testing. Most of the testing can be done easily like with any web page development: set up a local server and open the URL in your devices. But we found some resolution problems when Telegram launched the games. Some elements appeared several times larger than when using a typical browser app. Therefore, one last advice from us is to create a minimal test bot, capable of just launching the games, enough to be able to fix any bug that might appear only in Telegram.

Our games

Check out our games (please open the following links on your mobile device):

HTML5 games are hot in China

For the past several months we have been traveling to China to attend HTML5 game development related conferences where we have been invited to participate as speakers (GMGC, H5GDC, ChinaJoy, …). It has been an amazing experience to see how both the Chinese markets and developers are embracing HTML5 as a possible great way to drive gaming content in a different direction from the polluted and very complex to stand out of what are the so called “traditional” native content stores (iTunes, GooglePlay, Amazon, …). We have and still are learning a lot about this interesting new ecosystem that is being developed in China.

GMGCH5 H5GDC

HTML5 games section at GMGC and the HTML5 Game Developer Conference (yes, H5GDC!).

GDCTalkChinaJoy

It is strange to have lived how the western countries have led the HTML5 game development for some years now, but there has not been a great reception from the markets. We are still using the same native markets as any other technology to build native games using HTML5. And do not get us wrong, it is one of the many beauties of HTML5: content can be delivered in many different forms, including native apps.

The great advantage from HTML5, apart from being cross-platform, is that it can provide new ways to access content on demand. This kind of possibilities work the best in the area of social networks, where engagement can be achieved in a much easier and organic way: just provide a link to some content and download/consume it right away. It is what we are doing in our Facebook or Twitter timeline’s in a daily basis with web content. Imagine being able to integrate the missing pieces of realtime communication with the other players that a social network provides, with monetization using some kind of virtual currency, native feature access, great performance, etc. from within the social network app itself.

All this is what is happening in China right now. Of course, there are plenty of differences between the Chinese market and its user base compared with western countries, but the idea is exactly the same. Chinese social networks (so called Super Apps in China) are very diverse and users are used to being active in more than one at the same time. These networks are great platforms for native game distribution nowadays. But the experience is disconnected as the user selects the game and has to go to a store to download the content and execute it as a separate app. With HTML5, Chinese super apps are able to engage the user inside the app and still provide all the mechanisms the social network is able to provide. This is the type of HTML5 content use case we at Ludei have been waiting for years but in the Western countries haven’t been successful yet for different reasons (the messaging app Kik has been the only significant example). So imagine our excitement when we started to travel to China to learn from what’s happening there.

It is very early still but China has established the steps in the right direction to make this whole HTML5 gaming ecosystem a reality. New technology companies have started to create great technology and tools, markets/super apps are embracing HTML5 and creating new sections for this type of content and users are starting to show that acquiring them can be much easier if the whole experience is integrated inside the social network and the content is virally distributed among players. The perfect storm.

This is a great opportunity for Ludei. China is a great believer in the benefits of HTML5 runtimes and Ludei has both the technology and the community to provide great content to the Chinese market. Runtimes are being integrated inside the Super Apps so the fragmentation, performance and feature problems of traditional webviews are eliminated to the benefit of the developers.

We have been in touch with all the players in the sector: developers, publishers, technology providers, markets, carriers, … and we are working hard to establish a great way to help all the great developers that have used Cocoon so far to publish their games (or any HTML5 game developer out there regardless if they haven’t used Ludei’s tools 😉 reach this very interesting but complex market in China. We have created a close relationship with the most important HTML5 game publishers in China and many developers are aware of Ludei and using Cocoon to publish their games already in the country. As a matter of fact, the game that has been awarded as the best HTML5 game in China has been developed by Wozlla, a company that has been using Cocoon for over 3 years now and with which we have a very close relationship.

WozllaAwardOur friends from Wozlla receiving their “best HTML5 game” award at H5GDC

We will make all the efforts possible to make the transition to this market as easy as possible for anyone that wants to leverage their content in the country of the Great Wall.

Exciting times for HTML5 games.

Techniques to Optimize Memory Use in CocoonJS Canvas+ Environment

Memory is a critical resource in HTML5/JavaScript game development, especially on mobile devices. In a desktop environment you can load tons of textures but on some low-end mobile devices you can reach the maximum RAM limit quickly. Although JavaScript encourages automatic memory management by using a garbage collection mechanism, you shouldn’t ignore effective memory management techniques. HTML5/JavaScript applications can suffer the same memory related problems as native applications, such as memory leaks, out of memory issues and they must also deal with garbage collection pauses. 

This post will give you some general advice on memory optimization for HTML5 games and some CocoonJS Canvas+ specific tips.

Effective asset loading

Preloading all the assets at the start is the easiest and quickest way to manage the memory but it only works for small games where all the assets fit into the available memory. You shouldn’t preload everything on a heavy game, only the assets that you need each time, and dispose of the unneeded assets as soon as possible. Your game memory usage depends highly on your game engine (some of them do a better job than others). Don’t expect that the browser or the garbage collector will fix all your problems and that you can stop worrying about effective memory management.

Texture packer

Javascript images and canvas objects are backed into OpenGL textures and FBOs, usually using RGBA format, 32 bits per pixel. Think about it, for example a 2048×2048 image eats 16MB of memory!  Some GPUs require POT (Power Of Two) textures for the best performance, so keep in mind that some images could use more memory than their real size and use 2^n size textures whenever you can.

We recommend that you pack all your textures using one of the Sprite Packer tools out there. That way you’ll waste less memory and improve performance (by avoiding the number of context switchings) and loading times. Some HTML5 engines are able to pack all your textures at runtime, others don’t, so please check your engine features first.

Garbage Collection

JavaScript automatically frees objects when it detects that they are not used anymore, this process is called garbage collection. During a collection the execution on your page can be suspended for a moment. If your game creates too many JavaScript objects in each frame it can lead to noticeable pause issues. This is another example that proves that it is a mistake to forget about memory management on JavaScript. You should reuse javascript objects whenever possible.

The dispose method

Image and Canvas objects are disposed when the garbage collector detects that they are not reachable in the JS code. The disposal is not immediate, it may take some seconds depending on the heuristic rules of the JavaScript virtual machine. Using a WebGL context the developer has more precise control over the WebGL texture and buffers disposal but that’s not the case when using a 2d context or when dealing with Image and Canvas objects.

CocoonJS’ Canvas+ environment exposes a method called “dispose” on canvas, image and audio objects. This method immediately frees the associated texture or internal buffer, which is very useful for games with heavy textures or for games that need a greater control over the memory.

Using this CocoonJS Canvas+ exclusive feature is very easy. Imagine we have an image object represented by the “myImage” variable.

myImage.dispose && myImage.dispose(); // The same for canvas and audio objects.

The memory warning event

iOS and Android native applications are able to receive a memory warning notification from the system. The default implementation in Canvas+ and WebView+ environments is to perform a garbage collection and free as many internal cached data objects as possible.

From CocoonJS Canvas +2.1, the environment exposes the “memorywarning“ notification as a window listener. It is strongly recommended that you implement this method and free up as much memory as possible by disposing of cached data objects, images on canvases that can be recreated.

Cocoon.on(“memorywarning”, function() {
  // dispose of cached images and canvases that can be recreated
});

Texture reducer

Texture reducer is a CocoonJS Canvas+ exclusive feature. When your game targets all resolutions you need huge textures for iPad retina like devices and small textures for small mobile devices. A game developer has many ways to handle this:

  1. Create different asset packages, HD and normal. Good solution but bigger app size.
  2. Scale down HD resources. Excessive memory usage and performance impact on small devices.
  3. Create smaller asset packages on runtime rendering to a canvas/texture. Good solution but some JavaScript engines don’t support this.

The CocoonJS Canvas+ texture reducer feature can transparently do the job for you. It uses the third approach and it is highly customizable (for example, you can only apply it to certain resources). Check out the complete API documentation to see how to set it up.

As the texture reduction lowers the quality of the final images to be displayed, an interesting approach that we have recommended to some customers is to apply it only for certain device models, leaving higher resolution for some others (you can use the “navigator.userAgent” property to identify the device model). This, of course, it is not an easy task on Android due to the big number of device types, but on iOS is definitively an interesting option, specially for older devices such as the iPhone4 or the iPad Mini 1st generation.

Max Memory Threshold

This new CocoonJS Canvas+ exclusive feature available from version 2.1 and higher, exposes the “setMaxMemory” utility method. When the max memory threshold is set, CocoonJS checks the total amount of texture sizes (images and canvases). When the runtime memory size reaches the max memory threshold, CocoonJS disposes of the least recently used textures until the memory fits the threshold. It disposes of textures used for JS Image objects (which can be reloaded later if needed or are drawn again). It doesn’t dispose of canvas objects because they cannot be reconstructed if they are used again in a render operation. This extension is designed to be used in 2D contexts, because in WebGL contexts the developer is the one responsible for memory disposal.

Check out the API documentation.

Lazy Loading

Another CocoonJS Canvas+ exclusive feature available on version 2.1 and higher we have added the “cocoonLazyLoad” boolean property to Image objects (we have also added a duplicate called “idtkLoadDisposed” for retro compatibility with Construct2). When the property is set to true, the image is not loaded until it’s used in a render operation. Engines that load all the assets at startup can benefit from this property. But do not forget to purge the textures when they are not needed again, for example, using the dispose mechanism described earlier!

NPOT Textures

Canvas+ uses POT (Power Of Two) textures by default in 2d contexts. This is very useful for performance improvements, especially on mobiles with old GPUs. But it can waste memory on games that don’t use packed or 2^n textures. In CocoonJS Canvas+ version 2.1 you can allow NPOT textures in Canvas2D contexts (they were already supported in WebGL).

Check out the API documentation.

Conclusion

We have covered some basics of memory management in HTML5 games and exposed Canvas+ specific tips and tools.  We are always open to your suggestions. Remember that if you have some problem with memory usage in Canvas+ and you think that the problem is on our side you can send us a testcase and we’ll be glad to help you.

Additional Notes about Ludei’s Canvas+ Environment

CocoonJS’ Canvas+ is not a full browser, but a highly optimized JavaScript Virtual Machine for Canvas 2D and WebGL environments. Comparing it to a full fetched browser is not recommended as browsers include “a lot of magic tricks” (and that is why sometimes they are big and slow). For example, a browser might be able to handle a 5000 by 5000 pixels image but that does not mean that the underlying device is able to do it, just that the browser is handling some things internally for you either lowering the quality of the image (downscaling it) or subdividing it. Very few native technologies (C++ game engines) allow this kind of features as the developers should know how to handle this situations correctly (do not use 5000×5000 textures in the first place). Here at Ludei we never intended to create a new browser, but provide a highly specialized runtime environment so HTML5 developers can be closer to the native side without ever leaving JavaScript and the great HTML5 APIs.

CocoonJS In App Purchases are easier than ever in Kiwi JS

WE  apple-touch-icon-144-precomposed  KiwiJS

KiwiJS is a game development framework that uses JavaScript and HTML5. Ludei and the team behind it have been working to make it compatible with Canvas+ in CocoonJS. Their feedback has been invaluable and CocoonJS has improved much thanks to this collaboration, as we do with any other game engine out there.

 

Both platforms have been compatible for a while now but today we are pleased to announce that our friends over at Gamelab have just launched version 1.0 of their HTML5 game framework Kiwi.js and a much needed In-App purchasing Plugin for CocoonJS! What we found is that this new version of Kiwi is easy for developers to use, comes with a ton of documentation, runs fast and offers a lot of useful features. The In-App Purchasing Plugin (which comes with an example store fashioned off the Kingdom Rush store) allows users to sell their consumable game items to players and to create virtual currencies within their game. Also available for purchase is a Cartoon Particle Effects Pack that promises to make your HTML5 games pop! 

 

Kiwi.js founder, Dan Milward, says that while the ‘indies’ are a well catered for community, his company has identified a need for professional services that provide a higher level of customer support to the industry as a whole. “What we want to see is the HTML5 space taken more seriously and used to create serious games. Our pro add-ons, customer support model and IP partners will all go towards helping make this happen.”

 

For more information head over to the kiwi website.

CocoonJS and Construct2’s “Great HTML5 Gaming Performance Test: 2014 edition”

Scirra, the company behind Construct2, a great HTML5 game authoring framework, released “The Great HTML5 Gaming Performance Test: 2014 edition” weeks ago. In this test, they used a Construct2 based game demo and executed it in numerous environments. Surprisingly (and we want to think that by mistake), they did not include CocoonJS’ Canvas+ in the comparison, but to help Scirra provide as much information as possible, and to be fair to the Construct2 developer community that has been actively using CocoonJS, we have used the same demo in almost all of the same devices (and some interesting additional one like an iPad1 with iOS 5!). These are the results:

Device Canvas+ canvas2d Canvas+ webgl Chrome34 webgl Firefox webgl Safari 7 canvas2d Ejecta webgl
Nexus 4 58 60  59 58 N/A N/A
Nexus 7 52 60 59 51 N/A N/A
SGS3 58 59 58 58 N/A N/A
iPad 2 53 55 N/A N/A 46 55
iPad 1 20 35 N/A N/A N/A N/A
iPhone 4S 32 51  N/A N/A 40 51
iPhone 5 60 60 N/A N/A 60 N/A
Kindle 44 58  N/A N/A N/A N/A

As you can see Canvas+ is really efficient for both 2d and webgl contexts in all of the devices that were tested (even on an iPad1!!!).

It is also important to remember that Chrome, Firefox and Safari are not technologies to create native apps for iOS or Android. If someone wants to run a game on a mobile browser, this list gives a good glimps of what to expect, but not all of the final users/players have these browsers and their latest versions installed (specially on Android) and most of these technologies won’t be an option to create native apps for existing mobile markets. Moreover, Safari has Nitro JIT so the comparison is also biased. Bottom line is that CocoonJS is still the only technology that allows webgl native app deployment for both iOS and Android using the same execution environment, with no fragmentation and with an easy one click final deployment.

The good news is that the new CocoonJS release 2.0.1 is soon to be out and with it anyone will be able test these results on his/her own easily by installing the CocoonJS Launcher App for iOS and/or Android. This new version of CocoonJS will execute any Construct2 project exported for the web out of the box, so this perf test will also work just by pointing to the following URL (either typing it or using the provided QRCode for your convenience):

http://www.scirra.com/demos/c2/sbperftest/

ScirraPerfTestURL

Happy perf-testing! 😉

Celebrating a full year of WebGL inside CocoonJS with ThreeJS running on iOS!

WebGL is spreading everywhere and to celebrate this and the fact that it’s been over a year that CocoonJS has provided support for it inside it’s Canvas+ technology for iOS and Android, we have recorded this video of some of the great ThreeJS demos and games running on iOS!

ThreeJS is the most well known and used open source WebGL engine and the de facto standard today to develop web 3D interactive experiences. At Ludei, we strongly believe that WebGL is the future of advanced computer graphics on the web and that is why we have been actively supporting any technology that pushes it forward during the last year. Type in (or use a QRCode) a URL to a WebGL demo and execute using the CocoonJS Launcher App either in Canvas+ or WebView+, both our HTML5 execution environments that support WebGL, and unleash WebGL on your device today!