Namespaces
Variants
Actions

Create a moving ball using accelerometer with Kuneri Lite

Jump to: navigation, search

In this post we’ll see how to use accelerometer in Flash Lite with Kuneri Lite. We’ll do a small example of the moving ball application, however simpler than the original application.

First of all, you have to create two layers, with names ‘content’ and ‘actions’. After this, create a movieclip with a circle like the showed below. Put the movieclip in the Stage with an instance name ‘ball_mc’.

Bolinha.jpg

After this, put the below code in the first frame of the ‘actions’ layer.

//Set fullScreen
fscommand2("FullScreen", true);
 
var lv:LoadVars = new LoadVars();
var X, Y, acelX, acelY, posX, posY;
 
//Reset the kuneri Lite variables.
klXAxis = 0;
klYAxis = 0;
 
lv.onLoad = function(success:Boolean){
if(success)
if(lv.klError == 0){
//Read the position.
lv.load("http://127.0.0.1:1001/Basic/accelerometer
 ?klCommand=readsensor"
);
X = lv.klXAxis;
Y = lv.klYAxis;
}
}
 
onEnterFrame = function():Void{
//Calculate the respective constant acceleration.
if(X > 0)
acelX = -1;
else acelX = 1;
if(Y > 0)
acelY = -1;
else acelY = 1;
 
posX = Math.abs(X/10) * acelX;
posY = Math.abs(Y/10) * acelY;
 
moveBall(posX, posY);
//Verify the limits of screen.
verifyPosition(ball_mc._x, ball_mc._y);
}
 
function verifyPosition(posX:Number, posY:Number):Void{
if(posY <= 10)
ball_mc._y = 10;
if(posY >= 310)
ball_mc._y = 310;
if(posX <= 10)
ball_mc._x = 10;
if(posX >= 230)
ball_mc._x = 230;
}
 
function moveBall(posX:Number, posY:Number):Void{
ball_mc._x += posX;
ball_mc._y += posY;
}
 
//Start the accelerometer, before first read.
lv.load("http://127.0.0.1:1001/Basic/accelerometer?klCommand=startsensor");
 
stop();

In this example the acceleration is constant, because this is a simple example for to create a moving ball with Flash Lite using KuneriLite accelerometer plugin by Flash Lite.

Comments

As FlashLite do not provide the access to system resources for S60 3rd edition devices, the Kuneri-Lite is used to bridge the gap.

The article demonstrates the use of this KuneriLite to access the devices native accelerometer. The article is recommended to try the implementation of KuneriLite and the accelerometer.

This page was last modified on 5 August 2011, at 02:58.
68 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2012 All rights reserved