Updates: Forking & Copying, Experiments Section, Language Improvements and More

Posted: by Seb under Play My Code Announcements

Our latest update is out and ready, including project copying & forking, a new Experiments section intended for demo and test projects, plus language additions & improvements as well as a round of under-the-hood improvements.

Forking & Copying Projects

First off, Play My Code projects can now be copied and forked; highly-requested features useful not just for those who like to build multiple games from a common codebase (such as Jayenkai) but also for users who like to modify and extend the creations of others.

Copying works pretty much as one might imagine: clicking the Copy button (found alongside any of your projects on the My Games page) will create a new copy of that project – code, assets and all. ‘Forking’ refers to the copying of projects written by others, enabling users to create their own version of someone else’s code to modify as they see fit. The Fork button can be found underneath any game on the site. Currently, any project on Play My Code can be forked, but those worried about their work being “ripped off” should be pleased to know that the original source is quoted on a forked project.

Experiments Section

Play My Code is primarily built for creating and sharing games, the intention being to create the world’s biggest user-generated gaming portal – however, lots of users write tests, demos and experimental code which doesn’t really fit in with the “finished” titles one currently finds on the Play page. Currently there’s no way to easily browse through these projects, so we’ve added an Experiments section to the Play page which will enable experimental projects to gain more recognition.

This ties into project forking too – users may find an effect or test which they wish to study or use in their own game. To enable your code to appear in the Experiments section, set it as “Experiment” from the drop-down menu on the My Games page. The Experiment category replaces the Demo category, so any project currently previously set as Demo will appear in the Experiments section automatically.

new Array( size )

A common case for writing code is to build a new array, pre-initialized with a number of elements. Until now you’ve had to do this yourself, but with this update Arrays now have proper constructors. There are several ways you can use them.

The first way is to just pass in a size when you create an Array, and all elements will be initialized to ‘null’.

// make an Array containing 5 nulls
// old way
arr = [ null, null, null, null, null ]

// new way
arr = new Array( 5 )

What if you don’t want to default each element to ‘null’? You can pass the default value in as the second argument:

// creates the array: [ 0, 0, 0, 0, 0 ]
ns = new Array( 5, 0 )

Finally, you can also attach a block and initialize each element using that, for more advanced cases:

images = new Array( 5 ) do |i|
    return new Image( 'player_animation_' + i + '.png' )

Full documentation on Array constructors is available here.


Another feature for arrays is the ‘random’ element. This will return a random entry from the array. This is useful for retrieving a random enemy factory, a random image, or some other random value from a collection.

tetrisBlocks = [ squareBlock, iBlock, jBlock,
        lBlock sBlock, tBlock, zBlock ]

nextBlock = tetrisBlocks.random()

You can find documentation about this here.

Multi-line String improvements

We have always supported multi-line strings, using the ‘\n’ character. However, using the enter key has not been supported until now:

text = "A multi line
string that
is spread over

Delta Time Improvements

The delta time value retrieved has previously been a little hackish, often jumping around wildly, and sometimes this can mess up games. So we’ve looked at this and added maximum/minimum bounds, so the delta time no longer jumps to extremes. This will make any game currently using delta time much more stable.


We’ve also streamlined how you can work with delta time. Currently, you can get the delta time using the ‘onEachFrame’ function:

onEachFrame() do |delta|
    // pass delta in to other parts of the game
    updatePlayer( delta )
    updateEnemies( delta )
    updateBullets( delta )

However, you then need to pass this into any function or method that uses delta time, and this can be annoying. To improve this, we’ve added the getDelta function for retrieving the delta time for the current frame anywhere.

x = x + speedY*getDelta()
    y = y + speedY*getDelta()

This is the same value as the ‘delta’ value you can retrieve from ‘onEachFrame’. Find full documentation here.

multAlpha( alpha )

When using multiple nested ‘setAlpha’ blocks, you often want to have the alpha value depend on the outside one. For example:

setAlpha( fade ) do
    setAlpha( 0.3*getAlpha() ) do
    setAlpha( 1*getAlpha() ) do
    setAlpha( 0.8*getAlpha() ) do

Here, the inner sections will draw at their own alpha values, multiplied against the outer ‘fade’ value, which is retrieved using ‘getAlpha’. To make that a little more terse, ‘multAlpha’ will do that multiplication for you.

setAlpha( fade ) do
    multAlpha( 0.3 ) do
    multAlpha( 1 ) do
    multAlpha( 0.8 ) do

It makes juggling alpha values a little easier. Find the documentation here.


We provide a Timer class to help build animations. It allows you to retrieve a value whilst the timer lives. However, it’s very common that you want to perform an action when the Timer ends, and currently you have to manually check for this and perform the appropriate action yourself. To make this easier, we’ve added the ‘onExpire’ method.

color = :blue

// In 1 second,
// change the colour from blue to red.
t = new Timer( 1000 ).onExpire() do
    color = :red

onEachFrame() do
    fill( :black )
    setColor( color ) do
        fillRect( 100, 100, 50, 50, true )

You can find the documentation for this here. onExpire can also be cancelled, and the method to do this is documented here.

Bugfixes and Tweaks

We’ve made many and various bugfixes, tweaks and optimisations with this release, including:

  • If statements are now faster
  • Scaling drawRotatedImage() would sometimes crash – fixed
  • Some documentation layout bugs fixed
  • Some IE9 CSS bugs fixed
  • The Number.wrap() method didn’t work under certain circumstances – fixed
  • Some Asset Manager corner case bugs have been fixed alongside some subtle tweaks, making it slightly nicer to use
  • If .play() is called on a sound which is still playing, it will retrigger it without .stop() needing to be called first
  • Number.toString() now works as advertised, rather than returning a string with the value ‘Number’ as it did before
  • Error messages in the IDE have been improved
  • Opera-specific bug where a crash could occur when manipulating an image’s pixels – fixed

As always, we greatly value your feedback and input when it comes to updates and improvements – leave a comment on this post, send @playmycode a tweet, leave a post on our forum or use the feedback form to drop us a line (find the tab on the left-hand side of the screen) if you’ve got any suggestions or impressions. Happy coding!

Leave a Response

Your email address will not be published. Required fields are marked *