Skip to content

Instantly share code, notes, and snippets.

@noonat noonat/Game.as
Created Jun 15, 2011

Embed
What would you like to do?
AIR 2.7 Android Example Makefile
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<application xmlns="http://ns.adobe.com/air/application/2.6">
<id>game</id>
<versionNumber>1.0.0</versionNumber>
<filename>game</filename>
<description></description>
<!-- To localize the description, use the following format for the description element.
<description>
<text xml:lang="en">English App description goes here</text>
<text xml:lang="fr">French App description goes here</text>
<text xml:lang="ja">Japanese App description goes here</text>
</description>
-->
<name>Game</name>
<!-- To localize the name, use the following format for the name element.
<name>
<text xml:lang="en">English App name goes here</text>
<text xml:lang="fr">French App name goes here</text>
<text xml:lang="ja">Japanese App name goes here</text>
</name>
-->
<copyright></copyright>
<initialWindow>
<content>game.swf</content>
<systemChrome>standard</systemChrome>
<transparent>false</transparent>
<visible>true</visible>
<fullScreen>false</fullScreen>
<autoOrients>false</autoOrients>
<aspectRatio>landscape</aspectRatio>
<renderMode>cpu</renderMode>
</initialWindow>
<customUpdateUI>false</customUpdateUI>
<allowBrowserInvocation>false</allowBrowserInvocation>
<icon></icon>
<android>
<manifestAdditions><![CDATA[<manifest><uses-permission android:name="android.permission.INTERNET"/></manifest>]]></manifestAdditions>
</android>
<versionLabel></versionLabel>
</application>
package {
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.utils.getTimer;
public class Game extends Sprite {
private var _ballX:Number;
private var _ballY:Number;
private var _ballVelX:Number;
private var _ballVelY:Number;
private var _ballRadius:Number;
private var _elapsed:Number;
private var _time:Number;
private var _width:Number;
private var _height:Number;
function Game() {
if (stage) {
onAddedToStage();
} else {
addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
}
}
private function onAddedToStage(event:Event=null):void {
addEventListener(Event.ENTER_FRAME, onEnterFrame);
removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
stage.addEventListener(Event.RESIZE, onResize);
stage.align = StageAlign.TOP_LEFT;
stage.frameRate = 30;
stage.scaleMode = StageScaleMode.NO_SCALE;
_width = stage.stageWidth;
_height = stage.stageHeight;
_ballX = Math.random() * _height;
_ballY = Math.random() * _width;
_ballVelX = _ballVelY = Math.min(_width, _height) / 2;
_ballRadius = 16;
_time = getTimer() / 1000;
}
private function onEnterFrame(event:Event=null):void {
var time:Number = getTimer() / 1000;
_elapsed = time - _time;
_time = time;
_ballX += _ballVelX * _elapsed;
_ballY += _ballVelY * _elapsed;
if (_ballX - _ballRadius < 0) {
_ballX = _ballRadius;
_ballVelX *= -1;
} else if (_ballX + _ballRadius > _width) {
_ballX = _width - _ballRadius;
_ballVelX *= -1;
}
if (_ballY - _ballRadius < 0) {
_ballY = _ballRadius;
_ballVelY *= -1;
} else if (_ballY + _ballRadius > _height) {
_ballY = _height - _ballRadius;
_ballVelY *= -1;
}
graphics.clear();
graphics.beginFill(0x331155);
graphics.drawRect(0, 0, _width, _height);
graphics.endFill();
graphics.beginFill(0x33ccff);
graphics.drawCircle(_ballX, _ballY, _ballRadius);
graphics.endFill();
}
private function onResize(event:Event):void {
_width = stage.stageWidth;
_height = stage.stageHeight;
}
}
}
# This is an example Makefile for building Android apps using AIR 2.7. You
# need to have the SDK installed and added to your path.
#
# To install the AIR 2.7 runtime on your device, run:
#
# make install-runtime
#
# To run the game on the device, just run "make".
#
default: launch
game.swf: Game.as
amxmlc -sp+=. -output game.swf Game.as
game.apk: game.swf game-app.xml certificate.p12
adt -package -target apk -storetype pkcs12 -keystore certificate.p12 game.apk game-app.xml game.swf
certificate.p12:
ifeq ($(PASSWORD),)
@echo "\nYou need to create a password. Run:\n\n\tmake certificate.p12 PASSWORD=yourpassword\n" && false
else
adt -certificate -validityPeriod 25 -cn SelfSigned 1024-RSA certificate.p12 $(PASSWORD)
endif
clean:
rm -f game.apk game.swf
debug: game.swf
adl game-app.xml
launch: install
adt -launchApp -platform android -appid game
install: game.apk
-$(MAKE) uninstall # uninstall errors can be ignored
adt -installApp -platform android -package ./game.apk
install-runtime:
-$(MAKE) uninstall-runtime # uninstall errors can be ignored
adt -installRuntime -platform android
uninstall:
adt -uninstallApp -platform android -appid game
uninstall-runtime:
adt -uninstallRuntime -platform android
.PHONY: clean debug install install-runtime uninstall uninstall-runtime
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.