Animated sprite one time and disapear - android

this.MyAnimatedSprite.animate(50, 0);
this.MyAnimatedSprite.setVisibility(false);
I am new to AndEngine and I want to animate whole AnimatedSprite once and let it disappear. In my code it only animates and stops but does not disappear, if I do setVisible(false).
It does not show animation even once.

You can do this by turning the visibility false after the animation is done.
this.MyAnimatedSprite.animate(50, 0, new IAnimationListener () {
#Override
public void onAnimationFinished(AnimatedSprite pAnimatedSprite) {
this.MyAnimatedSprite.setVisibile(false);
}
#Override
public void onAnimationStarted(AnimatedSprite pAnimatedSprite,
int pInitialLoopCount) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationFrameChanged(AnimatedSprite pAnimatedSprite,
int pOldFrameIndex, int pNewFrameIndex) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationLoopFinished(AnimatedSprite pAnimatedSprite,
int pRemainingLoopCount, int pInitialLoopCount) {
// TODO Auto-generated method stub
}});

Related

How I can cancel this white blank thing on the keyboard everytime when I click on a button

hey when I click on the custom keyboard it shows me this blank thing I don't want to appear on every single time I click on a button how can I remove this thing it's on the picture if u see it u will understand me more and thanks for helping
CustomKeyboardView.class
public class CustomKeyboardView extends KeyboardView {
public CustomKeyboardView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void showWithAnimation(Animation animation) {
animation.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
setVisibility(View.VISIBLE);
}
});
startAnimation(animation);
}
mainactivity.class
private CustomKeyboardView mKeyboardView;
private EditText mTargetView;
private Keyboard mKeyboard;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mKeyboard = new Keyboard(this, R.xml.keyboard);
mTargetView = (EditText) findViewById(R.id.target);
mTargetView.setOnTouchListener(new View.OnTouchListener() {
#Override
public boolean onTouch(View v, MotionEvent event) {
showKeyboardWithAnimation();
return true;
}
});
mKeyboardView = (CustomKeyboardView) findViewById(R.id.keyboard_view);
mKeyboardView.setKeyboard(mKeyboard);
mKeyboardView
.setOnKeyboardActionListener(new BasicOnKeyboardActionListener(
this));
}
private void showKeyboardWithAnimation() {
if (mKeyboardView.getVisibility() == View.GONE) {
Animation animation = AnimationUtils
.loadAnimation(KeyboardWidgetActivity.this,
R.anim.slide_in_bottom);
mKeyboardView.showWithAnimation(animation);
}
}
BasicOnKeyboardActionListener.class
public class BasicOnKeyboardActionListener implements KeyboardView.OnKeyboardActionListener {
private Activity mTargetActivity;
public BasicOnKeyboardActionListener(Activity targetActivity) {
mTargetActivity = targetActivity;
}
#Override
public void swipeUp() {
// TODO Auto-generated method stub
}
#Override
public void swipeRight() {
// TODO Auto-generated method stub
}
#Override
public void swipeLeft() {
// TODO Auto-generated method stub
}
#Override
public void swipeDown() {
// TODO Auto-generated method stub
}
#Override
public void onText(CharSequence text) {
// TODO Auto-generated method stub
}
#Override
public void onRelease(int primaryCode) {
// TODO Auto-generated method stub
}
#Override
public void onPress(int primaryCode) {
// TODO Auto-generated method stub
}
#Override
public void onKey(int primaryCode, int[] keyCodes) {
long eventTime = System.currentTimeMillis();
KeyEvent event = new KeyEvent(eventTime, eventTime,
KeyEvent.ACTION_DOWN, primaryCode, 0, 0, 0, 0,
KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE);
mTargetActivity.dispatchKeyEvent(event);
}
Set
mKeyboardView.setPreviewEnabled(false);
after setting findViewById for your keyboardview

Unable to play Video in Android LsitView

I have a listView in which
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int pos, long id) {
player.cueVideo("KJ9KzGQq0w");
}
});
private YouTubePlayer player= new YouTubePlayer() {
#Override
public void setShowFullscreenButton(boolean arg0) {
// TODO Auto-generated method stub
}
#Override
public void setPlaylistEventListener(PlaylistEventListener arg0) {
// TODO Auto-generated method stub
}
#Override
public void setPlayerStyle(PlayerStyle arg0) {
// TODO Auto-generated method stub
}
#Override
public void setPlayerStateChangeListener(PlayerStateChangeListener arg0) {
// TODO Auto-generated method stub
}
#Override
public void setPlaybackEventListener(PlaybackEventListener arg0) {
// TODO Auto-generated method stub
}
#Override
public void setOnFullscreenListener(OnFullscreenListener arg0) {
// TODO Auto-generated method stub
}
#Override
public void setManageAudioFocus(boolean arg0) {
// TODO Auto-generated method stub
}
#Override
public void setFullscreenControlFlags(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void setFullscreen(boolean arg0) {
// TODO Auto-generated method stub
}
#Override
public void seekToMillis(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void seekRelativeMillis(int arg0) {
// TODO Auto-generated method stub
}
#Override
public void release() {
// TODO Auto-generated method stub
}
#Override
public void previous() {
// TODO Auto-generated method stub
}
#Override
public void play() {
// TODO Auto-generated method stub
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void next() {
// TODO Auto-generated method stub
}
#Override
public void loadVideos(List<String> arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void loadVideos(List<String> arg0) {
// TODO Auto-generated method stub
}
#Override
public void loadVideo(String arg0, int arg1) {
// TODO Auto-generated method stub
}
#Override
public void loadVideo(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void loadPlaylist(String arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void loadPlaylist(String arg0) {
// TODO Auto-generated method stub
}
#Override
public boolean isPlaying() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean hasPrevious() {
// TODO Auto-generated method stub
return false;
}
#Override
public boolean hasNext() {
// TODO Auto-generated method stub
return false;
}
#Override
public int getFullscreenControlFlags() {
// TODO Auto-generated method stub
return 0;
}
#Override
public int getDurationMillis() {
// TODO Auto-generated method stub
return 0;
}
#Override
public int getCurrentTimeMillis() {
// TODO Auto-generated method stub
return 0;
}
#Override
public void cueVideos(List<String> arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void cueVideos(List<String> arg0) {
// TODO Auto-generated method stub
}
#Override
public void cueVideo(String arg0, int arg1) {
// TODO Auto-generated method stub
}
#Override
public void cueVideo(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void cuePlaylist(String arg0, int arg1, int arg2) {
// TODO Auto-generated method stub
}
#Override
public void cuePlaylist(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void addFullscreenControlFlag(int arg0) {
// TODO Auto-generated method stub
}
};
I am using YouTubeAPI for doing this
sample code in API
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,boolean wasRestored) {
if (!wasRestored) {
//player.cueVideo("wKJ9KzGQq0w");
}
}
I want to play a video as soon as an element in listView is clicked.
Change your player.cueVideo("wKJ9KzGQq0w"); to player.loadVideo("wKJ9KzGQq0w");.
loadVideo will automatically play when it has finished loading.
Made few changes
#Override
public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player1,boolean wasRestored) {
player=player1;
}
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int pos, long id) {
video_URL="eF9AC2Ce2ow";
video_player.loadVideo(video_URL);
}});

How to keep playing YouTubePlayer in Android

Now I'm creating an Android application witch use YouTube api to play Video.
But the player stop when I change Activity.
I want to keep Playing like a Music Player even when Activity will change.
I try to solve that by adding Static on YouTubePlayer.(But cannot solve.)
I mean I want to Keep it's playing when the Activity or the Application itself move to Background.
So if you have any ideas, please share with me :)
-----------------Code-----------------
public class PlayActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener,YouTubePlayer.PlayerStateChangeListener{
public static final String DEVELOPER_KEY = "My_Dev_Key";
private LinearLayout yPos;
private static YouTubePlayer yt;
private YouTubePlayerView ytp;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.play);
yPos = (LinearLayout)findViewById(R.id.youtube_pos);
try{
ytp = new YouTubePlayerView(this);
ytp.initialize(DEVELOPER_KEY, this);
}catch(Exception e){
finish();
}
yPos.addView(ytp);
}
#Override
public void onAdStarted() {
// TODO Auto-generated method stub
}
#Override
public void onError(ErrorReason arg0) {
// TODO Auto-generated method stub
}
#Override
public void onLoaded(String arg0) {
// TODO Auto-generated method stub
}
#Override
public void onLoading() {
// TODO Auto-generated method stub
}
#Override
public void onVideoEnded() {
// TODO Auto-generated method stub
}
#Override
public void onVideoStarted() {
// TODO Auto-generated method stub
}
#Override
public void onInitializationFailure(Provider arg0,
YouTubeInitializationResult arg1) {
// TODO Auto-generated method stub
}
#Override
public void onInitializationSuccess(Provider arg0, YouTubePlayer arg1,
boolean arg2) {
// TODO Auto-generated method stub
if(!arg2){
if(yt == null){
yt = arg1;
yt.setPlayerStateChangeListener(this);
yt.setPlayerStyle(YouTubePlayer.PlayerStyle.DEFAULT);
yt.loadVideo("u0v5A6cQOhs");
}
}
}
}

Reloading Animated sprite while on the game scene Andengine

While on the game play scene, when player fires, the enemy will automatically animate and have to move out from the scene. i tried alot but didn't find the solution.
here is my code.
it = bulletList.iterator();
while (it.hasNext()) {
final Bullet b = (Bullet) it.next();
if (b.sprite.collidesWith(enemy)) {
engine.runOnUpdateThread(new Runnable() {
public void run() {
enemy.animate(new long[]{100,100,100,100,100},10,14,1
, new IAnimationListener() {
#Override
public void onAnimationStarted(AnimatedSprite pAnimatedSprite,int
pInitialLoopCount) {
}
#Override
public void onAnimationLoopFinished(AnimatedSprite pAnimatedSprite,
int pRemainingLoopCount, int
pInitialLoopCount) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationFrameChanged(AnimatedSprite pAnimatedSprite,
int pOldFrameIndex, int pNewFrameIndex) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationFinished(AnimatedSprite pAnimatedSprite) {
// TODO Auto-generated method stub
detachChild(sprite);
}
});
enemy.setIgnoreUpdate(true);
it.remove();
break;
}
}
}
what is it that's actually happening?
i did not understand...
But i understood your code a bit.And i recommend you to remove the runonupdatethread.
And put your animation code outside the runonupdatetheard and try it.
I animate the sprite directly...

LibGdx - need help on Screen class

I've been using libgdx for the past 3 weeks..
I created two screens referencing to a game:
public class Game extends Game {
TitleScreen titleScreen;
SplashScreen splashScreen;
#Override
public void create() {
// TODO Auto-generated method stub
titleScreen = new TitleScreen(this);
splashScreen = new SplashScreen(this);
setScreen(splashScreen);
}
}
and
public class SplashScreen implements Screen {
Game game;
public SplashScreen(Game game) {
// TODO Auto-generated constructor stub
this.game = game;
}
#Override
public void show() {
// TODO Auto-generated method stub
}
#Override
public void hide() {
// TODO Auto-generated method stub
}
#Override
public void render(float delta) {
// TODO Auto-generated method stub
Gdx.gl.glClearColor(0.5f, 1f, 1f, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
if(Gdx.input.justTouched()){
game.splashScreen.dispose();
game.setScreen(game.titlescreen);
}
}
#Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
#Override
public void pause() {
// TODO Auto-generated method stub
}
#Override
public void resume() {
// TODO Auto-generated method stub
}
#Override
public void dispose() {
// TODO Auto-generated method stub
}
How do I dispose the splashscreen entirely? When I called the game.setscreen(game.splashscreen) in titlescreen class, it resume the splashscreen;. I'm expecting to set a new splashscreen..
Create a new splash screen every time you want to show a splash from the beginning:
game.setScreen(new SplashScreen(game));

Categories

Resources