Category Archives: Code

Code posts

Bitmap Fonts in Corona SDK

Using your own, custom fonts in games and apps is essential to create the right GUI. Sometimes this can be done with a standard font asset drawn natively; however this doesn’t always provide you with enough artistic licence to create what you really need, and in some cases, ie Windows Phone, using native fonts has a huge impact on performance. There is a solution. Bitmap fonts. Although the idea of bitmaps fonts isn’t new, in fact its very old; using them in you Corona projects can typically be a pain. Many years ago, someone wrote bmf.lua, which worked a treat to draw your bitmap fonts onto your scene, however it had a few shortfalls. Corona SDK then released graphics 2.0, which broke bmf.lua completely.

The following article will walk you through my workflow for producing and using bitmap fonts in corona; including a version of bmf.lua that I have updated for the following functions:

  • Corona Graphics 2.0 Compatible
  • Corona SDK image map format compatible
  • .fnt definition file compatible
  • Read the drawn width and height at run-time
  • Re-size the font at run-time, without having to destroy and reinitialize.

Continue reading

MySQL Header

Coding MySQL PHP calls the correct way

A vast majority of websites are coded using PHP. Chances are if you have a PHP website, it is being driven by a MySQL database back-end… and the chances are that the code you are using to get data to and from the PHP script to the MySQL includes the MySQL functions.

MySQL functions are quick and easy to implement; however they contain gaping security holes that easily allow SQL injections and cross site scripting attacks. For this reason, using the MySQL functions is being strongly advised against, by anyone in the know, including the PHP developers themselves. In short, it is essential that you remove these functions for the security of your website. At this point, a lot of developers may shy away from having to update what could be hundreds of scripts, however the changes required are actually not too much different than what you already have and in the end, is essential for the security of your website and services.

Continue reading

wordpress

Adding Ajax Pagination to Timeline in Wedding WP Theme

Wedding theme screenshot

Wedding theme screenshot

Wedding is a responsive WordPress theme that can be found here. I purchased the theme as I required a timeline feature on a site that I had been working on. The wedding theme happened to have a timeline that I liked. It had one small problem though… it had no pagination.

The site I needed the timeline for could potentially have a lot of timeline posts, so loading them all at once when the page loads was not ideal. So after reaching out to the author of the theme with no success, I modified the theme to enable a ajax load more pagination using the existing theme functions.

Continue reading

wordpress

Show Recent Blog Posts

When using WordPress as your CMS of choice, there often becomes a need to display a list of recent blog posts on a non-blog page (such as a static homepage).

For an example of this, just check out my home page here. The “from the blog” section is a custom bit of code that I wrote to display a list of recent blog posts.

The recent blog posts list is useful as it enable users to get a snapshot of what is going on in your blog, without actually having to visit the page.

There are two ways I explored to solve this particular problem:

  • Shortcode that can be placed anywhere
  • Snippet of code that sits directly in your template page file

This article will explore both ways.

Continue reading

Coding background image

Authenticating Saved Data in Apps

Cheating is becoming a bigger and bigger problem for developers. You only have to look at the leader boards for the ‘Flappy Bird’ game and you will find hundreds of users on 999999. It’s near impossible to actually achieve that in the game, but users can easily access the files used to save this data and modify it to meet their needs.

It’s not only high scores that are an issue. Developers need a way of keeping track of in-app purchases, and this is often saved on the device in the form of JSON or SQL files. This obviously opens the door up to users activating features or items without paying for them.

There is however, a simple solution to check if the data being saved, then loaded back into the app is genuine or not. This is in the form of a checksum. A simple calculation using the data you want to save, a random key, and the resultant. Simply calculate a checksum at data save and store the result with the saved data. When it comes to load the data back in, perform the same calculation and ensure that the result matches the result that was saved.

Continue reading

Automation Header

InTouch Word Wrap

With this code you can create multiple lines of text in InTouch using one input string.
The code is defined as a quick function, and can be called from within a code block, or on an animation event.
Simply pass in the text string to split, the number of characters per line, and which line you want to return.

For example:
You have a text string that is 50 characters long, and you want to display it over 3 lines on a screen, but are limited to 20 characters per line.
Draw 3 lines of text on the screen.
Animate the text as follows:

  • Text 1: string input animation: Call SplitStringIntoLines(‘*YOUR STRING TAG*’, 20, 1)
  • Text 2: string input animation: Call SplitStringIntoLines(‘*YOUR STRING TAG*’, 20, 2)
  • Text 3: string input animation: Call SplitStringIntoLines(‘*YOUR STRING TAG*’, 20, 3)

Continue reading