Posts Tagged ‘nme’

prevent android from dimming (w/ haxe and nme)

I’m going to do this in the easiest way I can think of. For anything more complicated, an NME extension would probably work well for this sort of thing!

After starting a new NME project in FlashDevelop, I created MainActivity.java in the project directory:

package ::APP_PACKAGE::;

import android.os.Bundle;
import android.view.WindowManager;

public class MainActivity extends org.haxe.nme.GameActivity {
	
	 protected void onCreate(Bundle state) {
		super.onCreate(state);
		getWindow().addFlags( WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
	 }
}

After that, I added a template entry to application.nmml:

<template path="MainActivity.java" rename="src/[package_path]/MainActivity.java" if="android" />

In my case, [package_path] was com/gigglingcorpse/test/dontdimm/.

Works for me at least!

Deciding where to go

As part of an experiment I was working on, I needed to decide how an object should turn based on what it saw. Some objects would attract it, and some it would prefer to turn away from.
Turns out that’s more complicated than I expected.
So I pulled that portion out to test in an interactive example.

I’m not dissatisfied with the result, but it remains to be seen how it will work out in the larger experiment. For example, the algorithm seems overly complex. There are a whole bunch of Math.sin, Math.cos, and Math.atan2 calls. I don’t know how slow or fast these really are (I should check), but I wonder how it will fare as the number of objects increases. It’s possible that I tend to worry about that sort of thing too much: future cost.

(Either JavaScript is not active or you are using an old version of Adobe Flash Player. Please install the newest Flash Player.)

Click to set pleasing items, and ctrl+click to set displeasing ones. You can drag them around, but the longer your mouse is down the larger they will grow, and with it their effect on the blue circle.
Press the space bar to clear them.

(more…)

haxe to java to nme to android! (part 1)

NME is a great solution for writing applications for the Android platform, but sometimes it’s nice to escape the confines of GameActivity.java. This is fairly easy to do, but unfortunately until now it meant writing Java.

Which is fine for some people, but given the option I’d avoid it. (For one thing, it’s lead me to using two separate editors simultaneously: FlashDevelop and Notepad++.)

The convenience of using NME, along with the power and freedom that comes from using Java for Android, without ever having to leave HaXe, is one of the benefits of HaXe’s upcoming Java target. And for me, it’s a pretty major one.

There are three main steps. The first is writing the code, and the other two are the two-stage compilation process. I imagine most of the stuff I discuss will end up being automated nicely, but for now this is how I went about it.

(more…)

An SMS relay for android

I made a simple SMS relay for my android (Andrew) last night. In case you want to do something similar, good news I’m about to explain its code!

Note: I used NME and notepad++ and flashdevelop and java, instead of NME and haXe, or Eclipse and Java. This might strike you as strange. It probably is strange, but it’s easier and more comfortable for me. The code shown will mostly be java and XML, which should match up nicely if you’re using Eclipse and Java, and you can take a look at Programming for android in Java but using NME if you’re using NME.

Let’s start with AndroidManifest.xml:

< ?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:installLocation="::ANDROID_INSTALL_LOCATION::" android:versionCode="1" android:versionName="1.0" package="::APP_PACKAGE::">
	<application android:label="::APP_TITLE::" android:debuggable="true"::if (HAS_ICON):: android:icon="@drawable/icon"::end::>
		<receiver android:name=".TextMessageReceiver" >
            <intent -filter android:priority="999">
                <action android:name="android.provider.Telephony.SMS_RECEIVED" />
            </intent>
        </receiver>
		<service android:name=".SMSService" />
	</application>

	<uses -sdk android:minSdkVersion="7"/>
	
	 <uses -permission android:name="android.permission.RECEIVE_SMS" />
	 <uses -permission android:name="android.permission.SEND_SMS" />
	 <uses -permission android:name="android.permission.WRITE_SMS" />
	 <uses -permission android:name="android.permission.READ_CONTACTS" />
</manifest> 

(more…)

.