Experiments with stand-alone games

A project to port LÖVE to Android handhelds
Locked
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Experiments with stand-alone games

Post by T-Bone »

Yes, I know that stand-alone games are of low-priority right now, but I was curious and started to play around a bit. In LoveLauncher.java, I saw that when you click on a .love file in the list, if calls

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file://" + (String) (parent.getAdapter().getItem(position))));
startActivity(i);
which seems to start up the game. So I thought, what the hell, I should simply be able to add something like this to public void onCreate(...), and it should start up my game straight away. So I made it like this:

Code: Select all

public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.launcher);
		
		Intent i = new Intent(LoveLauncher.this, LoveNative.class);
		i.setData(Uri.parse("android.resource://net.schattenkind.nativelove/" + R.raw.game));
		startActivity(i);
}
and I place my game, named game.love, inside net.schattenkind.nativelove/res/raw/, and tried it. It started LÖVE straight away, but it showed the no-game screen instead of my game. I think I'm referring to the file correctly. At least this is how I've learned to refer to local files inside the app.

Do any of you know what's wrong? I know love-native-android isn't quite ready yet, but it is getting there, and I'd love to play around a bit :neko:
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Experiments with stand-alone games

Post by bartbes »

Does it work when you point it at an external file, rather than a resource?
Moe
Party member
Posts: 115
Joined: Thu Dec 22, 2011 10:20 pm

Re: Experiments with stand-alone games

Post by Moe »

T-Bone wrote:Do any of you know what's wrong? I know love-native-android isn't quite ready yet, but it is getting there, and I'd love to play around a bit :neko:
and I place my game, named game.love, inside net.schattenkind.nativelove/res/raw/
Awesome, a reply but rearranging your post. :awesome:
Background: All data in the res folder is put into the apk. So if you want to access the data from the native layer, you have to provide a way to access the data within the apk. In our case, it would make sense to open it by physfs, so that you can actually access a real file. Seems a bit clumsy since we will get a physfs (.love) within a physfs(.apk), there might be an JNI-powered access or you can extract the apk to memory. In any case there will not be a simple way like fopen.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Experiments with stand-alone games

Post by T-Bone »

There has to be a simple way to access the contents from the apk from within JNI. Otherwise JNI would be kind of useless for designing, you know, apps and games.

Perhaps this could be of help? http://www.anddev.org/ndk_opengl_-_load ... 11978.html
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Experiments with stand-alone games

Post by bartbes »

The problem isn't that android doesn't provide access, the problem is physfs can't deal with archives within archives. Maybe you could try a folder in the resources?
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Experiments with stand-alone games

Post by T-Bone »

Oh, if that's the problem, then that can easily be solved. There is no need for it to be packed into a .love, if it can load a folder then that would be perfect. How would I refer to the folder in that case?
User avatar
kalle2990
Party member
Posts: 245
Joined: Sat Sep 12, 2009 1:17 pm
Location: Sweden

Re: Experiments with stand-alone games

Post by kalle2990 »

T-Bone wrote:Yes, I know that stand-alone games are of low-priority right now, but I was curious and started to play around a bit. In LoveLauncher.java, I saw that when you click on a .love file in the list, if calls

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file://" + (String) (parent.getAdapter().getItem(position))));
startActivity(i);
which seems to start up the game. So I thought, what the hell, I should simply be able to add something like this to public void onCreate(...), and it should start up my game straight away. So I made it like this:

Code: Select all

public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.launcher);
		
		Intent i = new Intent(LoveLauncher.this, LoveNative.class);
		i.setData(Uri.parse("android.resource://net.schattenkind.nativelove/" + R.raw.game));
		startActivity(i);
}
I'm not completely sure on how to link it from ./res/raw, but I'm quite sure R.raw.game points to an integer value. However, you could place it inside ./assets instead. This would look something like this file:///android_asset/game.love, I have tried this with a HTML file just recently and this is the easiest method I found ;)
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Experiments with stand-alone games

Post by bartbes »

kalle2990 wrote:but I'm quite sure R.raw.game points to an integer value
That is correct and intended, the uri contains the id.
User avatar
T-Bone
Inner party member
Posts: 1492
Joined: Thu Jun 09, 2011 9:03 am

Re: Experiments with stand-alone games

Post by T-Bone »

Can confirm that using the "assets" folder does not work, at least not the way I'm doing it, which is

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file:///android_asset/game"));
startActivity(i);
and

Code: Select all

Intent i = new Intent(LoveLauncher.this, LoveNative.class);
i.setData(Uri.parse("file:///android_asset/game.love"));
startActivity(i);
with folder and .love respectively.
Moe
Party member
Posts: 115
Joined: Thu Dec 22, 2011 10:20 pm

Re: Experiments with stand-alone games

Post by Moe »

T-Bone wrote:There has to be a simple way to access the contents from the apk from within JNI. Otherwise JNI would be kind of useless for designing, you know, apps and games.
Most games use JNI as few as possible, most likely they will pass events and loop triggers for the render loop.
Anyway, you can pass a file handle by JNI or something similar. I will take a look for a solution when I have some spare time. Meanwhile, you can extract the love file from the apk on the first run.
Locked

Who is online

Users browsing this forum: No registered users and 0 guests