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!

haxe java target for android demo code

Man, I am having the hardest time naming these posts, but I promise that I’m not just typing random words next to each other.

I’ve uploaded the code for my demo from CauĂȘ’s presentation; which you should be able to browse or checkout if you want to try it for yourself. There’s a description.txt file in there that should.. you know, describe some things.

Hopefully I didn’t break it between then and now! That would be embarassing, but let me know if that is the case and I’ll try to fix it and feel shame simultaneously.

 

In case you missed it, the code is here: http://svn.gigglingcorpse.com/examples/haxe java toast/

 

If you want to read more about the demo, I’ve talked about it in a few of my past posts:

  1. My experience getting started with the Java target for Haxe
  2. How I set up my NME project directory for Haxe to Java for Android
  3. The Haxe code for java, and how I used Android’s native interface XML stuff

 

That’s all!

Your friend,
Brad

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 for android (part 2)

Last time I discussed setting up a project to create java code, for android, from haxe. I left out some neat stuff because it was already pretty long. If you read it, you probably noticed.

For example, the program was called Haxe-Java Toast, which from the code presented is wildly inaccurate. Well, maybe not wildly, but you get the idea.

My goal was to do was create an android application with its interface defined by XML, and which called a function from the Android SDK (in this case triggered a Toast). What I pasted last time was a subset of the code in MyActivity.java.

There may end up being a lot of code here.

 

(more…)

.