Reputation: 37
Just as the title says, can flash be used in an android game to show animation? Like say an animated Lightning bolt appearing on the screen when a user touches a spot on the touch screen?
If this is not possible, what are alternatives to this?
Thanks.
Upvotes: 3
Views: 3908
Reputation: 455
Android's graphics and animation faculties are plenty for displaying a lightning bolt.
Using Flash for this would be a waste of resources.
It sounds like you are getting started with Android's UI. Can you give us a little more information on what you want to accomplish? Maybe one of us can get you goin.
In the mean time maybe this will help:
package com.arrdude.forumanswer;
import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
public class TouchLightningActivity extends Activity implements OnTouchListener {
FrameLayout mainframe;
ImageView lightning;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mainframe = (FrameLayout) findViewById(R.id.mainframe);
lightning = (ImageView) findViewById(R.id.imageView1);
mainframe.setOnTouchListener(this);
}
@Override
public boolean onTouch(View v, MotionEvent event) {
System.out.println(event);
//lots of interesting things going on here to look at if you are not yet familiar with touch listeners
if(event.getAction()==MotionEvent.ACTION_DOWN){
lightning.setVisibility(View.VISIBLE);
}else if(event.getAction()==MotionEvent.ACTION_UP
|| event.getAction()==MotionEvent.ACTION_OUTSIDE){
lightning.setVisibility(View.INVISIBLE);
}
return false;
}
}
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mainframe"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_gravity="center"
android:background="@drawable/background"
>
<ImageView android:src="@drawable/lightning"
android:id="@+id/imageView1"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:visibility="invisible"></ImageView>
</FrameLayout>
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.arrdude.forumanswer"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="4" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".TouchLightningActivity"
android:label="@string/app_name" android:screenOrientation="landscape">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Drawables:
Before The Storm by Larisa Larisa: public domain image from here
Upvotes: 1
Reputation: 2015
Yes, it should be possible, most likely through a WebView. However, an animated lightning bolt in an onTouch from the actual Android UI is not possible, unless your whole app, or at least the part that needs to display the lightning bulb, is a Web-app.
There are other ways to do this, and much better way to make games in Android. I suggest you take a look at: http://developer.android.com/guide/topics/graphics/index.html
Upvotes: 1