i’m taking Two by Two from the Untold Entertainment library to see how various online monetization methods for Flash games pan out.

Introduction
Part 1: Armor Games
Part 2: Kongregate
Part 3: MochiAds
………./\……….Update: MindJolt

Addicting Games


Part 1: Armor Games

Pimp My GameArmor Games is a Flash portal that will sponsor games on a case-by-case basis, with a game’s worth being determined by the site’s moderators. The site owners appear to be very efficient at pimping out games themselves; the Armor Games splash screen seems to pop up in every conceivable corner of the Internatz.
Keep reading »

Pagination is a navigation style where you have a bunch of content that won’t fit on one screen, so you give your user BACK and NEXT arrow keys to flip through “pages” displaying the content. In many ways, it’s preferable to a scrolling navigation, because you don’t have to fill the box with all of your content at once - you can pull it down for your user on demand. (note: i’ve seen a few rare cases where a the application downloads content as you scroll the list, but in my experience it’s not very common)

You see pagination everywhere, and i use it at least once in every single game i build. It’s just handy. Check out the puzzle gallery in Jigsaw! for an example:

Jigsaw Pagination

Pagination at work

When i was first learning Flash and i had to set up these paginated galleries all the time, i would constantly make the same mistake. The left arrow button would fire a function that would be almost identical to the right arrow button’s function. For some bizarre reason, it took me YEARS to figure out how to set this up without duplicating code.

If you’re a smartypants and you figured this out long ago, more power to you. But if you’re just learning and you have a similar problem, here’s the trick:

ID, please

The first thing you need is an ID to store which “page” the user is looking at. Remember that our gallery is going to be completely code-created, so there are no actual “pages” to speak of - you decide how many items will appear on your pages. But you’ll use this ID value to figure out which content to display.

//AS2:
var ID:Number;
 
//AS3:
var ID:uint;

That’s the variable declaration. When you initialize your gallery screen, set ID to 0.

mod

Next, i give each arrow button a variable called “mod“. That’s short for “modifier“. The LEFT/BACK/PREVIOUS arrow gets a mod of -1, while the RIGHT/FORWARD/NEXT button gets a mod of 1.

btnArrowLeftClip.mod = -1;
btnArrowRightClip.mod = 1;

Interactify it!

Set up some button events or event listeners for your arrow buttons, and pass each button’s mod value to a common function.

//AS2:
btnArrowLeftClip.onRelease =
            btnArrowRightClip.onRelease = function():Void
{
     flipGallery(this.mod);
}
 
//AS3:
btnArrowRightClip.mod = 1;
btnArrowLeftClip.mod = -1;
 
btnArrowLeftClip.addEventListener(MouseEvent.CLICK, flipGallery);
btnArrowRightClip.addEventListener(MouseEvent.CLICK, flipGallery);

Flip it real good

Now, you just set up a flipGallery function. It accepts mod (-1 or 1) as input and uses that to change the ID value.

// AS2:
flipGallery = function(mod:Number):Void
{
      ID += mod;  
      // If mod is -1, ID goes down.  If mod is 1, ID goes up.
}
 
//AS3:
function flipGallery(e:MouseEvent):void
{
      ID += e.target.mod;
}

That’s a Wrap (?)

You’ll want to add some logic to your flipGallery function to wrap the ID variable. Figure out how much stuff you have to display, then figure out how much stuff you can fit on one “page”. That will give you totalItems and totalItemsPerPage values. Do some division to calculate a totalPages value.

Then, within your flipGallery function/method:

if(ID >= totalPages) ID = 0;
if(ID < 0) ID = totalPages-1; 
      // we subtract 1 because we're working with 0-base counting

So what do you actually do with your flipGallery function once the ID is set properly? If you have all of the things you want to display numbered sequentially and linked from the library (or stored in an array), just loop through totalItemsPerPage. Multiply ID (current page) by totalItemsPerPage and add it to your iterative value (usually i in a for loop). That’s the number of the correct item to display … so display it!

There’s a little more work involved with actually laying out your items on the stage so that they’re not all lumped together. i’ll leave that up to your discretion. i just wanted to talk about the mod method, because i would have appreciated it very much if the Ghost of Christmas Future had written this article for me and emailed it to me back in 2002.

Ghost of Christmas Future helps Scrooge with Flash programming

Will Tiny Tim ever learn Actionscript, spirit?

Shall we have some more?

Was that helpful? Not? Do you have a way better way to do it? Is there another topic you want to see covered? Let me know!

- Ryan

AS3 Tutorial - Math.random()

March 23rd, 2008

i haven’t written many Flash tutorials because i feel like a bit of a poser. i see the brilliant codeheads posting these tutes to make Flash do incredible things and i think “man - that’s leagues ahead of where i’m at.” But i forget that with eight years’ experience using Actionscript, i do actually know a thing or two that will help someone new to Flash/Actionscript.

This article is from an email i sent to a Humber College student explaining how to pull a random number in Flash, how to make it an integer, and how to get a random number within a range.

The student, Michael, was creating a game with an asteroid belt. He wanted to randomly distribute the asteroids along the y axis, and to give them a random speed value within a range. The range would increase with each new level.

~~ BEGIN TRANSMISSION ~~

Hi Michael.

Whenever you want x amount of something, that’s obviously your cue to create a variable. So since you need x amount of asteroids, let’s make a totalAsteroids variable:

var totalAsteroids:uint = 5;  // you can tweak this value up or down, of course

The other two things you’re looking at are random numbers within ranges. You need a random number within a range to distribute the asteroids along the y axis. You need a random number within a range to determine the speed of the asteroids, which goes up (i assume?) each level.

So! Here’s the basic random code:

var someNumber:Number = Math.random();

That’ll get you a decimal number betwen 0 and 1. Try running this code a few times in Flash to prove it:

var someNum:Number = Math.random();
trace(someNum);

You just multiply that number if you need a bigger range. Look at this:

var someNum:Number = Math.random()*5;

That will give you a decimal number between 0 and 5, because everything has been multiplied by 5.

Decimal numbers might not serve your purposes well. Here are a few ways to clean up your someNum result:

var someNum:Number = Math.floor(Math.random()*5);
// gives you 0, 1, 2, 3, or 4 by "flattening" the decimal number
var someNum:Number = Math.ceil(Math.random()*5);
// gives you 1, 2, 3, 4, or 5 by raising the decimal number
var someNum:Number = Math.round(Math.random()*5);
// gives you 0, 1, 2, 3, 4, or 5
by rounding the decimal number up or down

See? You just wrap Math.roundingMethod() around your Math.random() method. You stick your Math.random() statement inside the Math.roundingMethod() brackets.

So far so good. Now what if you need a random number within a range? Say, any number between 5 and 20?

Well, 20 minus 5 is 15. That’s your range. You need a random number out of 15.

Then just add the lower limit (5) to bump the number up. Does that make sense?

var someNum:Number = Math.ceil(Math.random()*15);
// gives you 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, or 15
var someNum:Number = Math.ceil(Math.random()*15) + 5;
// gives you 5, 6, 7, 8, ,9 ,10, 11, 12, 13, 14, 15, 16, 17, 18, 19, or 20

So really, we could knock all these numbers out and just use variables.

var minLimit:uint = 5;
var maxLimit:uint = 20;
/* These two variables change
depending on the level of the game.
To be more specific, they'll probably
be called minSpeed and maxSpeed.*/
 
var range:uint = maxLimit - minLimit;
 
var someNum:Number = Math.ceil(Math.random()*range) + minLimit;

This works for your asteroid speed. It also works for asteroid placement. Do you see how? You’re just telling Flash the minimum limit for asteroid placement (somewhere near the top of the gameplay field) and the maxiumum limit (near the bottom of the screen). Then you pull a random number within that range and bump the number up by adding the minLimit value.

To create your asteroids field, loop through your totalAsteroids value, and for each asteroid you add to the screen from the library, get a random number within range and set the asteroid’s y position to that result.

for(var i:uint = 0; i<totalAsteroids; i++)
{
   var theAsteroid:Asteroid = new Asteroid();
   // create a new instance of your Asteroid class (not shown)
   var theClip:MovieClip = theAsteroid.clip = new AsteroidClip();
   // attach a MovieClip from the library
 
   theAsteroid.clip.y =
           Math.ceil(Math.random()*screenRange) + minYLimit;
   // Pull a random screen position
 
   theAsteroid.speed =
           Math.ceil(Math.random()*speedRange) + minSpeed;
   // Pull a random speed
 
   theAsteroid.dir = Math.round(Math.random())*2-1;
   // Randomly grab 1 or -1 for the direction.
   // During the game's update loop, multiply the speed
   // by the direction to make the asteroid move left to right,
   // or right to left
 
   theAsteroid.dir == 1 ?
           theAsteroid.clip.x = 0 : theAsteroid.clip.x = maxXLimit;
   // Put the asteroid at the right or left side of the screen,
   // depending on which direction it'll be travelling
 
   addChild(theAsteroid.clip);
   // Put that puppy on the stage!
}

Obviously what’s missing here is the game’s update and draw loops which will position the asteroids and position their graphics. i’ll save that for another post.

Addendum: Props to SmilyOrg from #actionscript on EFNet for the random direction code. i use it all the time, and i always forget how it goes.

i’ve had a hand in over fifty Flash games to date. My best advice to someone who wants to learn the software is to get a Flash Jedi - someone you can call up at three in the morning and pester for Actionscript advice. A Bert to your Ernie, if you will.

In my early days at Corus Entertainment / YTV, my Flash Jedi was Michael Lalonde, the amazing talent behind a comic strip called Ornery Boy, and father of a large number of bastard Flash game babies himself. My memory’s a bit hazy, but i credit this tip to Michael.

A Flash Sound Class Alternative

The YTV.com developers would often help each other out with some of the more difficult Flash problems that arose. Pride being what it was, the problem would have to get pretty bad before we’d solicit each other’s advice. Most of the time, all it took was a fresh pair of eyes to get past the hurtle. Every once in a while, the problem was so inexplicable that it boiled down to a Flash bug, and a work-around was necessary. Never did i see so many such unsolvable problems than when somebody worked with (against?) the Flash Sound Class.

Flash Sound Class got you down? Here’s the low-tech workaround that will probably drive “real” programmers nuts:

Keep reading »

GDC on a Dollar a Day

February 19th, 2008

Sorry for the misleading title. There’s absolutely no way you can attend the annual Game Developers Conference in San Francisco on a dollar a day unless you engage in a list of unsavoury activities, including but not limited to trespassing, mugging, and impersonating a Valve employee (which is apparently a capital offense in California due to a strange legal precedent set in 2001).

There are, as i’ve discovered, ways to get here by hemorrhaging less money than usual, which i will presently document for your reading pleasure:

1. Alumnus/Early Bird pass pricing.

This is an obvious one, and it requires a little advance planning and foresight. If you’ve ever attended GDC and are on the conference’s mailing list, a few months prior to the event you’ll be offered a special discount price. For the rest of us plebes, there’s the early bird price, which cuts off a month and a half before the event. The difference in an all-access pass at the regular price and the early bird price is around five hundred bucks, so it’s worth your while to plan a trip to GDC in advance.

2. Volunteer program.

A great option for students and hobos, the volunteer program requires you to write an essay or two on why you’re a worthy charity case. If you’re accepted into the program, you’re required to pull twenty hours of “stand around in a pink shirt duty” before you’re given a free all-access pass, though i’m not sure how much of the conference is left to be seen once you’ve sunk your twenty hours. The program also heavily subsidizes your accommodations by reducing, for example, a $275/night room at the San Francisco Hilton down to $50/night. The hitch is that you might have to share a queen-sized bed with another volunteer whom you’ve never met. This, in my opinion, is an excellent way to make new contacts and form fast friendships. Call it up close and personal networking.

“Where’s your other hand?”

“Between two pillows.”

“THOSE AREN’T PILLOWS!!!!”

Cue hilarity.

3. Off-peak airline deals.

i ran into one delegate who had purchased an unlimited air travel package from Air Canada for the sum of - i think - $1600? This enabled him to fly anywhere in North America, weekends and Tuesdays only, for two months. Unlimited. That’s what i call “a steal”. Almost literally. It’s like he’d put an airplane in his pocket and tried to smuggle it out of the airport.

4. Media credentials.

Like most other big conferences, if you’re able to prove your media credentials, you can get a conference pass for free. i’ve never tried for one, though i’m sure i could qualify. If it’s anything like E3 used to be, you have only to kick up a fan blog a few months prior to the event to lay claim to a pass. Indeed, i hope it’s a little more difficult than that, otherwise GDC may turn into what E3 had become at its most bloated: a fan convention for tourists.

5. The OMDC Export Fund.

Of interest only to Ontario game and new media companies, the Ontario Media Development Corporation’s Export Fund subsidizes a good part of your trip in exchange for … your mortal soul? i’m not sure. i haven’t looked into it. But it’s possible that if you live in Iowa or Behrain or some place without a booming game-based economy, your local government is looking to create a booming game-based economy, so ask around. Free money never hurt anyone. Unless that money was rolled into wads and packed into your rectum in a heavily-lubricated condom so that you could mule it over the Turkish border. Sources say that hurts quite a bit, thank you very much.

6. Contests and events.

Some folks i know received a little help with their trip last year by entering their game into a competition that was featured during the conference. i don’t know the details, but i do know that many of these contests and awards have some of the longest lead times in advance of the conference, so if you hope to cut costs for next year, start designing your indie game masterpiece now.

PROBLEM: Pressing CTRL+SHIFT+ENTER to test your AIR movie in debug mode does not produce any results.

SOLUTION: What’s going on is that the Adobe AIR Debug Launcher did not shut down properly when you clicked the X (close gadget) on the AIR movie you were testing. Or, if your AIR app didn’t even have window chrome with a close gadget, you couldn’t shut the process down.

On a Windows system, open the Task Manager (CTRL+ALT+DEL) and click on the Processes tab. Find adl.exe and shut it down. Now you’ll be able to test your AIR app again without closing and relaunching the entire Flash IDE!

PROBLEM: Trace actions don’t appear in the output window when i test an Adobe AIR swf.

SOLUTION Instead of using CTRL+ENTER to test the movie, use CTRL+SHIFT+ENTER to debug the movie. i was lucky enough to catch a small footnote in the AIR documentation that mentioned this bug. In case you missed it, there’s your solution.

We’ve been linked to by a fellow agency called Airtight Interactive on the subject of altering cross-domain bitmap data in Flash. They mention the server-side proxy work-around that i’ve used, calling it “prohibitive” for large-scale apps. That was the concern i raised when a casual games publisher approached me to ditribute Jigsaw! across its extremely high-traffic game portals.

Untold Entertainment’s advantage is that we do not bear the bandwidth costs that the jigsaw game’s Custom image feature may bring down like so much Biblical wrath. There are ways to mitigate the cost, which i’ll discuss after posting the solution.

(Click to read about Adobe’s rationale for preventing cross-domain image manipulation in Flash.)

PROBLEM:

Images loaded into a Flash swf from another domain (ie www.notMyOwnSite.com), won’t respond to BitmapData methods like draw().

SOLUTION:

Flash needs to see that the image comes from your own domain. To pull this off, you set up a server-side script and pass the image url to it. The script loads the image to your domain, and returns that image to Flash. Since the image comes from your domain now, you can mess around with it all you like.

The script i use is written in PHP. Here it is, at its most basic:

<?php
 
$mimetype = $_GET['mimetype'];
$file = $_GET['file'];
 
header("Content-Type: $mimetype");
readfile($file);
?>

There are some clear problems with this approach:

1. Since your server has to load the image, you carry the bandwidth cost for trafficking that image. i consider this the cost of doing business. If you want to offer a cool feature like custom player-created jigsaw puzzles, you have to pony up the cash.

And then, logically:

2. Some malicious user could set up a script to repeatedly pass enormous images through your server every second of every day, putting you in the poorhouse, or forcing your provider to shut your site down. This is best handled by adding limits to the script. Prevent users from loading images above a certain filesize, and limit the number of script calls per user.

Sheet Happened!

January 21st, 2008

Sheet Happened!

i’m not above profiling the mistakes i make as i bring my new business to its feet. It’s possible some of you are budding entrepreneurs planning to follow the same path. So here’s my hot entrepreneurial tip of the day: DO YOUR RESEARCH.

Two months ago, i hunkered down to learn Actionscript 3, and i needed a project to practice on. i chose Sheet Happens!, a hobbyist sheet music app that allows you to transpose the chords in a Notepad-like environment. A good long while into production, i thought “Hey … i wonder if there’s anything like this on the market?”

As it turns out, there is one teensy tiny product out there called iChords. It doesn’t do exactly the same thing as Sheet Happens!. You can actually feed it an MP3, and iChords will dynamically “listen” to the song and display the chords as the song plays.

iChords

iChords: 8000% better than Sheet Happens!

If Sheet Happens! is a car, iChords is a spaceship that transforms into a robot that eats cars for a mid-day snack.

To add insult to injury, iChords ships with D’Accord Chords Notepad, which looks exactly like Windows Notepad, with two extra menu additions: Transpose Up, and Transpose Down. That’s right - not only does iChords have a far better feature set than Sheet Happens!, it actually replicates the entire Sheet Happens! feature set as a footnote.

Sheet Happens! was also an excuse to launch an Adobe Integrated Runtime (AIR) app, which integrates Flash with the user’s desktop. This brings up a second, equally excellent tip for small business owners: start with what you know. Untold Entertainment Inc.’s bread and butter is making Flash games, deployed to the browser. i haven’t heard a lot of demand for AIR apps, but i thought we could be on the bleeding edge. The trouble with that is after two months, Untold Entertainment’s games library stays the same size, and we have this music software anomaly that probably won’t interest our core clients.

All told, developing Sheet Happens! wasn’t a complete waste of time. i have a much better handle on AS3 now, and will be periodically posting SNAFUs and programming tricks to help anyone else transitioning from AS2 to AS3.

i recently had to step back into old Actionscript 2 code, and it was like sliding my foot into a well-worn, mildewy sports sock where the sweat dried and mummified the sock into the shape of my foot. i was amazed at how quickly and easily i could program in AS2. i almost closed my eyes as i typed, and the code just flowed out of me. Contrast that with AS3, where i have to pay careful consideration to each line, and every time i compile i get a truckload of errors.

i worry that delving into my old code will undo all of the AS3 training i’ve done. i need to limit my exposure, like an 8-year old sneaking tiny glimpses at the sun, wondering how long it’ll be before he goes blind.

iChords can be purchased for an amazingly low price at finer download sites everywhere. Sheet Happens! can not.

PROBLEM:

TextField.setSelection doesn’t select any text!

SOLUTION:

Set the stage.focus property to your TextField object.

// Selects all the text in myTextField:
myTextField.selectable = true;
myTextField.stage.focus = myTextField;
myTextField.setSelection(0, myTextField.text.length);

Other search terms:
setSelection not working
setSelection not responding
setSelection broken
setSelection bug
setSelection buggy
DOUBLE_CLICK problem

Proudly powered by WordPress. Theme developed with WordPress Theme Generator by Party Industries & Hogwarts Digital.
Copyright © untoldentertainment.com. All rights reserved.