Archive for category Software

Apple Big Bloody Thicko

I quite like the Genius feature in iTunes, because it often produces pretty good selections. It has some sort of mental block with John Parr’s “St. Elmo’s Fire” though.
Dialogue box showing iTunes' genius function being unable to find a match for St. Elmo's Fire
My library is full of cheesy 80s crap, but it refuses to find a single match for the track. I’ve tried renaming the track (dropping the “Man In Motion” bit) and updating Genius, but it’s just not happening. Somehow it’s quite happy generating 100 completely appropriate matches for obscure ambient dronester loscil.

, , , ,

No Comments

Programming tip #383

If you’re using somebody’s API, don’t just litter your code with calls to it. Wrap it. Always wrap it. It’s much easier to add your own hooks in later if it’s in code you can actually modify. And on that day you thought would never arrive when you have to replace the API with another one, you’re going to realise that you’ve done something wrong as soon as you open the find dialogue box. Search and replace in code files is usually a sign of badness.

Write your own interfaces and keep those foreign hooks in a small wrapper where they belong.

http://en.wikipedia.org/wiki/Adapter_pattern

2 Comments

Flash bug in Chrome? Dragging outside of SWF

Update: This seems to be fixed as of Chrome 12.0.742.91.

For games like Bloons it’s essential to be able to click inside of the game, move the mouse with the button still held down, and have the game track the mouse movements until the player lets go of the mouse button. If we couldn’t do this it would break every game where the player has to move the mouse outside of the screen to aim a shot (which is a lot of games).

It seems that in Chrome on Mac this behaviour is broken, and the game will no longer track the mouse movement outside of the SWF area. In fact, the mouse button click state will be invalid until the user performs a click within the SWF to reset it. Disaster.

This report suggests that this was an old bug that has started happening again on recent versions of Chrome. Are you experiencing the problem? Try the SWF below; in any other browser you should be able to hold the button down and see the arrow follow your cursor position, even outside of the SWF area. In Chrome it will stop tracking it outside of the SWF area, and will erroneously think your mouse button is held down when you return the cursor to the SWF area. You’ll see the same problem if you try to play a game like Bloons.

If you’re releasing something soon, test it in Chrome first and consider delaying release until it’s fixed.

If you’re NOT experiencing the bug in a version of Chrome post reply to this post with your player and browser version.

Update: According to reports it’s fine on Windows.

2 Comments

Tutorial: How to use APIs

Step 1: Read the docs.
Step 2: Use the API.

FFS.

, ,

5 Comments

Animation cache addition to cocos2d for iPhone

There was already a texture cache and a sprite frame cache, but for some no reason no cache for animations. I’ve hacked one up based on the sprite frame cache, but it’s not well-tested yet.

Source:
CCAnimationCache.h
CCAnimationCache.m

,

1 Comment

SWFToXML and importing Flash scenes into Cocos2D on iPhone

Update May 1, 2010: The “Flash CS5 Uncompressed Document (*.xfl)” XML files exported by Flash CS5 are far superior to the files generated by this tool. I would recommend that you use that facility of CS5 if possible! At this point I’m only keeping this tool up because CS5 isn’t free.

SWFToXML reads the structure of the items on the stage of a single-frame SWF file and generates an XML file/plist describing it. Combined with the SWFToPNG tool this gives us a way to replicate a Flash scene easily on the iPhone with Cocos2D and Zwoptex. Simply traverse the XML or load it as a property list into an array, and instantiate the SWFToPNG/Zwoptex-generated animations by the class name and transformations given by SWFToXML. The structure of the Flash display list is preserved, along with the names of the items on the stage.

As well as being useful for migrating Flash content, this is also useful for utilising Flash for its own merits, such as laying out screen content and placing items in position for levels, etc.

SWFToXML Air Installer
SWFToXML source code

, , ,

4 Comments

SWFToPNG, a tool to help convert Flash assets to suitable formats for cocos2d, iPhone and iPad development

I am currently porting a Flash game to the iPhone. The first stumbling block was getting assets out of Flash into a sprite sheet or for import into Zwoptex. Sure, Flash has functionality to export a movie to a series of PNG images, but it’s terrible. It cuts out animation unless you’re using Graphics (no MovieClips), which often means editing your graphics until they look wrong (no filters, etc.), and then there’s all the tedious cropping to do.

I wrote a small utility for myself that automatically renders out the symbols in a SWF to a series of PNG files, and optionally crops out the transparent bits around the edges as well as retaining the registration points of the items. I figured that this might be useful for others, so I’m putting it online now, along with source in case anybody wants to improve it.

It is a bit rough and ready. There’s very little in the way of error checking, and it might not work the way you want it to. Here are the caveats:

  • This only works with AVM2 SWFs, so that’s Flash 9 player and higher with AS3
  • It will only understand MovieClips on the timeline (no buttons!) and they must be exported for ActionScript for the filenames to be correct (this is easy enough to do with a few clicks in the Flash IDE).
  • The program is memory-intensive. A bitmap is created for each frame of the SWF and held in memory until the files have been written (it was designed this way to facilitate cropping and quick development; it’s not intended as an export utility for your ten minute animations!)
  • Timeline code that causes clips to loop infinitely will also cause the rendering to loop infinitely.
  • Other stuff, probably

A suggested workflow:

  • Create a new FLA file. Drag the movie clips that you want to export on to the stage.
  • Publish a SWF.
  • Run the SWF through SWFToPNG. You should now have an ordered series of PNGs representing each MovieClip on the stage
  • Load these files into Zwoptex to create a sprite sheet and plist file for Zwoptex.

SWFToPNG is released under the terms of the GNU General Public License.

SWFToPNG Air Installer (sorry, it has to be AIR because Flex’s security restrictions would make the user have to run a file browse dialog for each file written)
SWFToPNG source code

, , ,

20 Comments