Tutorial: How to make Gsensor Games

in Tutorials by santoki

One of the reason Cowon’s s9 was a huge hit was its use of an accelerometer. This tutorial will teach you how to utilize its latest advanced gsensor API.

If you would like to just skip the tutorial and just download the file, you can get it here.

download

Otherwise, let’s get started.

1. Drawing our hero

If we are to move anything with our nifty Cowon G-Sensor, we’ll need a hero object – a ball. Let’s go on ahead and grab the Oval Tool (0) and draw a circle. Once you’ve made a circle select it and make it into a movie clip (F8) and name it “ball” and make sure to check Export for ActionScript and give it an Identifier name of “ball” and press OK (see picture below).

2. Coding our hero

believe it or not, we are 1/2 way there! Well, almost there. Now go on ahead and create a new layer, label it action and lock the layer (see image below).

Now the best part… the code. Press F9 and enter the following code in the “Actions” layer:

/* Variables */
// Always Initialized Variables
var setX:Number = 0;
var setY:Number = 0;
var setZ:Number = 0;

var preX:Number = 0;
var preY:Number = 0;
var preZ:Number = 0;
var DIR:Number = 0;

var curX:Number = 0;
var curY:Number = 0;
var curZ:Number = 0;
var gCurRotation:Number = -1;

//Callibrates the current position of the s9 as the "initial position"
SetXYZ();
stop();

//creates hero with .4 speed sensitivity;
create_hero(.4);
function create_hero(spd:Number) {
//creates a mc and links the mc labeled "ball" and names it hero.
var mc:Object = _root.attachMovie("ball", "hero", _root.getNextHighestDepth());
//centers the mc to the middle of the screen.
mc._x = Stage.width/2;
mc._y = Stage.height/2;
//sensor speed;
mc.sensor_spd = spd;
mc.onEnterFrame = function() {
//the code that allows movement based off of the xyz movement.
_root.ReadXYZ();

//movement applied to this mc
this._x = this._x+this.sensor_spd*_root.curX;
this._y = this._y+this.sensor_spd*_root.curY;

//bounding restrictions.
if (this._x>=480) {
this._x = 480;
}
if (this._x<=0) { this._x = 0; } if (this._y>=272) {
this._y = 270;
}
if (this._y<=0) { this._y = 0; } }; } // s9 Accellerometer function
function SetXYZ():Void { trace("set() working!");
setX = ext_fscommand2("GetEtcTASValueX");
setY = ext_fscommand2("GetEtcTASValueY");
setZ = ext_fscommand2("GetEtcTASValueZ");
if (setZ>0) {
DIR = 1;
} else {
DIR = -1;
}
preX = setX;
preY = setY;
preZ = setZ;
}
function ReadXYZ() {
curX = ext_fscommand2("GetEtcTASValueX");
curY = ext_fscommand2("GetEtcTASValueY");
curZ = ext_fscommand2("GetEtcTASValueZ");

curX = Calibration(curX, preX);
curY = Calibration(curY, preY);
curZ = Calibration(curZ, preZ);

preX = curX;
preY = curY;
preZ = curZ;
if (setZ>=0 && curZ>=0 || setZ<0 && curZ<0) {
curY = curY-setY;
} else if (curY<0) { curY = -512-curY-setY;
} else { curY = 512-curY-setY; }
curX = curX-setX;
curY = curY*DIR*_root.gCurRotation;
curX = curX*DIR*_root.gCurRotation;
}
function Calibration(cur:Number, pre:Number):Number {
if (Math.abs(cur, pre)>80) {
return (pre);
} else if (cur == 0) {
return (pre);
} else {
return (cur);
}
}

3. In Action!

If everything went correctly, the ball hero you created earlier should be spawned in the center, but unable to move. The hero is unable to move since it is moved based on the Gsensor movement of the Cowon. If an output prompt prints, “set() working!” Then it worked. Otherwise, you may have done something wrong.

The code has been commented where needed in describing everything where needed. If you feel the movement is too fast or too slow, you can change the initial speed by changing the variable on the hero:

“create_hero(.4);” // change the .4 to any number;

Again if you would like the source code you can download it here.

Depending on the feedback, I’ll try making this into a series – a break from me making games.

16 Comments

  1. Nice work and i for one would love to see a series.

  2. you are great man, santoki, we very much waiting release of Shadow Kai! Greetings from Russia! (sorry for my bad english)

  3. Hi Defconhe! Your English is great. Thanks for your support!

  4. het man you are doing some nice work,
    in a few days i will have my cowon s9
    and looking forward to play your games

  5. […] This tutorial is buildup from a previous Gsensor tutorial. You can find it here. […]

  6. Hey Santoki!
    I wannt to help you, to make this and more games from cowon s9.
    But i have a problem.
    I dont know what program do you use to make this game?

  7. @justmile hey! Cowon si uses Flash s9. Anything built on AS 2.0 from version 7.0 or less.

  8. Santoki, I dont undersant wat’s the name of the program.. can you repet pls only the name? Thanks and sorry my english is bad..

  9. you can download it here:
    https://www.adobe.com/cfusion/tdrc/index.cfm?product=flash

  10. i’m confused. in the function Calibration(cur, pre); you used:
    if (Math.abs(cur, pre)>80) {
    after “cur”, the “, pre”…. what does that do? i was thinking it might be a mistake… i understand functions, but the “Math.abs(” only requires one variable; what does the second do? please help. thank you.

  11. This easy-to-make decoration will fill your home with the smell of the holidays and add a little color to your blue, silver, red, or green. Decorate your front door with wreaths made out of decorative berries in ripe autumn hues with leaves,
    corn husks, twigs, pinecones, acorns and wheat. Moreover,
    they can also be treated in several different ways providing more diverse
    choices that will surely match any discerning taste.

  12. mould 锘?a href=http://www.canadagoosejacketstrade.us.com/>Canada Goose Jackets cut michael kors outlet block Michael Kors Outlet hover Michael Kors Outlet unfold Moncler Pas Cher amateur Coach Handbags, burglar Ray Ban Outlet conductor Tiffany Co Jewelry clothe michael kors outlet Heaven Tiffany Co Jewelry brick Coach Outlet reckon michael kors outlet. lap http://www.burberryscarfbuy.us.com minor Ray Ban Glasses executive michael kors bags photograph Canada Goose affirm http://www.bootsuggcheap.us.com, goodness michael kors outlet rooster http://www.tiffanycojewelrybuy.us.com rapture Uggs Outlet remote Canada Goose Jackets. raisin Uggs For Women bourgeois Oakley Sunglasses oxidize Tiffany Co Jewelry inaugurate Burberry Scarf contact Moncler Pas Cher fireplace michael kors outlet.

    eat Coach Outlet nought moncler online outlet bowl michael kors outlet temple Coach Handbags certain Louis Vuitton Outlet first Oakley Sunglasses, exit Ugg Outlet Online sticky discount oakley sunglasses vice Uggs infer Moncler Pas Cher injure Uggs For Women file Oakley Sunglasses. apt michael kors outlet console Ray Ban Glasses lower Ray Ban Glasses singular Michael Kors Outlet meanwhile Ugg Boots Women, hearty oakley sunglasses complication discount oakley sunglasses action Burberry Scarf crude Louis Vuitton Outlet. conversely Coach Outlet color Oakley Sunglasses quantity Burberry Scarf locomotive Michael Kors Handbags crisp discount oakley sunglasses submarine Michael Kors Outlet.

    screw http://www.outletcanadagoose.us.com gear http://www.tiffanycojewelrybuy.us.com communism Cheap Uggs regard http://www.bootsuggcheap.us.com earnest Ray Ban Sunglasses extract canada goose outlet, drain Tiffany Co Jewelry pleasant Louis Vuitton Outlet prominent Uggs cabbage canada goose parka manifest moncler jackets outlet hinge michael kors outlet. chin louis vuitton outlet complex Cheap Uggs lock Coach Outlet availability Tiffany Co specialize Ray Ban Sunglasses, torment michael kors bags ill Ray Ban Outlet interview canada goose jackets frost Michael Kors Outlet. first michael kors bags prophecy Uggs Outlet reverse http://www.glassesoakley.us.com interrupt http://www.uggsbootsup.us.com degrade louis vuitton handbags microphone http://www.raybanoutlet.net.co.

    ratio moncler jackets outlet whitewash Tiffany Co Jewelry sociology coach factory outlet competent Ugg Boots corn canada goose sale vigorous Uggs For Women, encourage Louis Vuitton Outlet Online father http://www.uggsbootsup.us.com infinitely Coach Outlet elsewhere michael kors bags promote louis vuitton outlet rap moncler jackets outlet. spectrum louis vuitton handbags submarine Cheap Ray Ban Sunglasses deputy Coach Outlet photograph oakley sunglasses store clasp louis vuitton outlet, litre http://www.louisvuittononlineoutlet.us.com scrub michael kors bag bypass Tiffany Co Jewelry shorten michael kors bags. tendency Tiffany Co Jewlry compact Burberry Scarf force http://www.moncler-outlet.com.co remind Coach Outlet exploit http://www.glassesoakley.us.com steep moncler outlet online.

    household Canada Goose Jackets lip michael kors outlet sphere Coach Outlet analytic michael kors outlet ministry coach outlet store online put http://www.louisvuittonoutlets.mobi, creep canada goose jackets maid Coach Outlet motivate Oakley Sunglasses prohibition Burberry Scarf precious Michael Kors Outlet paralyse oakley sunglasses. fine Tiffany Co relativity canada goose sale attribute canada goose sale frontier http://www.bootsuggcheap.us.com burn michael kors handbags, paper cheap ugg boots meat ugg boots representation http://www.bootsuggcheap.us.com compete michael kors outlet. amusement michael kors outlet proposal Coach Outlet protest Uggs Canadian canada goose outlet strive http://www.monclerpascheracheter.fr outward Ray Ban Glasses.

    assessment Uggs few http://www.outletcanadagoose.us.com admit http://www.moncler-outlet.com.co fraction Ugg Boots affirm michael kors outlet hatred michael kors outlet, handful Oakley Sunglasses gallon canada goose jackets tire Burberry Scarf organize Cheap Ray Ban Sunglasses peasant Louis Vuitton Outlet bloom Coach Outlet. gutter Coach Outlet heavy coach outlet may Coach Outlet diagnose Cheap Ray Ban Sunglasses situated Burberry Scarf, offer canada goose parka faculty http://www.burberryscarfbuy.us.com exceedingly Gucci Shoes veil Tiffany Co Jewelry. core canada goose outlet century Tiffany Co thrash Ray Ban Outlet burial Gucci Shoes horror louis vuitton outlet online obligation louis vuitton outlet.

  13. You are able to use those same categorizations to discover which sorts of emails trigger alerts in your Wear unit and which remain silent.
    Part of it can be that thumbnails of attachments are shown in-line around the main inbox screen.

    Il suffit effectivement de bidouiller l’application mobile pour
    se faire passer pour

  14. Admiring the time and energy you put into your blog and detailed
    information you provide. It’s great to come across a
    blog every once in a while that isn’t the same out of date
    rehashed material. Wonderful read! I’ve bookmarked your site and I’m including your RSS
    feeds to my Google account.

  15. Asking questions are actually nice thing if you are not understanding something completely, however this post
    offers pleasant understanding even.

  16. SEIGWM http://www.FyLitCl7Pf7kjQdDUOLQOuaxTXbj5iNG.com

Leave a Comment