Quantcast
Channel: Play My Code
Viewing all articles
Browse latest Browse all 10

Update: API Additions, Bug Fixes

$
0
0

Following our last major release, we’ve rolled out an incremental update which includes a few handy API additions we didn’t have time to get out the door last time ’round, as well as some extra polish and a number of bug fixes.

Controls Class: getKeysDown() & getKeysPressed()

One can check if a key is down, but what if you want to get the names of the currently pressed keys? The new Controls class methods getKeysDown() and getKeysPressed() make this a snap.

    controls = getControls()

    // an array of keys which are currently down
    down = controls.getKeysDown()

    // an array of keys pressed on this frame only
    pressed = controls.getKeysPressed()

Test the new functionality in the demo below (code here):

More info about both of these can be found in the docs: getKeysDown and getKeysPressed. These are perfect if you’re planning on building a typing game!

Number Class: Wrap

Often, you might want to build a game world where going off the side of the screen makes you reappear on the opposite side. You can call this ‘wrapping’ or ‘rolling’ over the edge. Another case when you need to do this: when you want to either add or subtract from an array index, and again have it wrap over either edge so it doesn’t go out of bounds.

Whilst one could use modulus (the % symbol) to ensure values wrap within certain bounds, the wrap method makes this a lot easier to understand and use.

    x = 800
    // x will roll over either edge
    x.wrap( 0, getScreenWidth() )

If the number is less or greater than the range given, than a value which wraps around that range is returned.

Segments & Inner Segments

Finally, we’ve added some more sets of drawing functions, both for drawing to the screen as well as for drawing on images. drawSegment and fillSegment are used for drawing a segment (or sector) of a circle.

We’ve also added drawInnerSegment and fillInnerSegment. These allow you to draw a segment where the inner section is cleared out, like a wide arc. Check out the example below for a demonstration (code here):

As always, if you’ve any suggestions or feedback then do please let us know via our forums, @playmycode on Twitter or via the Feedback tab you’ll find at the top left of this page.


Viewing all articles
Browse latest Browse all 10

Trending Articles