how to animate background image

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

how to animate background image

Postby mala » Wed Mar 03, 2010 1:36 pm

hi all,
I am new in android plateform. I am working with graphics.
I can move an image in the emulator screen. I set my image as background with the java coding. the coding set is as follows::


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Toast;

public class BounceView extends View {

protected Drawable myBackground, mySprite,mySprite2;
protected Point myBackgroundPos=new Point(0,0);
protected Point mySpritePos = new Point(10,100);
protected Point mySpritePos2 = new Point(15,800);
protected enum HorizontalDirection {LEFT, RIGHT}
protected enum VerticalDirection {UP, DOWN}
protected HorizontalDirection myXDirection = HorizontalDirection.RIGHT;
protected VerticalDirection myYDirection = VerticalDirection.UP;
public BounceView(Context context){
super(context);
// this.setBackgroundDrawable(this.getResources().getDrawable(R.drawable.test));
this.myBackground=this.getResources().getDrawable(R.drawable.test);
this.mySprite = this.getResources().getDrawable(R.drawable.splash1);
this.mySprite2 = this.getResources().getDrawable(R.drawable.splash1);
}

protected void onDraw(Canvas canvas) {

this.myBackground.setBounds(this.myBackgroundPos.x,this.myBackgroundPos.y,
this.myBackgroundPos.x + 480, this.myBackgroundPos.y + 800);


this.mySprite.setBounds(this.mySpritePos.x, this.mySpritePos.y,
this.mySpritePos.x + 100, this.mySpritePos.y + 100);

// Toast.makeText(getContext(),"button pressed"+this.mySprite.x,Toast.LENGTH_SHORT).show();

this.mySprite2.setBounds(this.mySpritePos2.x, this.mySpritePos2.y,
this.mySpritePos2.x + 100, this.mySpritePos2.y + 100);

if(myBackgroundPos.y ==this.getBottom()){
this.myYDirection = VerticalDirection.DOWN;
this.myBackgroundPos.y-=10;


}

if (mySpritePos.x >=this.getWidth() - mySprite.getBounds().width()){
this.myXDirection = HorizontalDirection.LEFT;

//Toast.makeText(getContext(),"button pressed"+this.mySpritePos.x,Toast.LENGTH_SHORT).show();

} else if (mySpritePos.x <= 0) {
this.myXDirection = HorizontalDirection.RIGHT;
}
if (mySpritePos2.y >= this.getWidth() - mySprite2.getBounds().width()){
this.myYDirection = VerticalDirection.UP;

} else if (mySpritePos2.y <= 0) {
this.myYDirection = VerticalDirection.DOWN;
}


if (this.myXDirection == HorizontalDirection.RIGHT) {
this.mySpritePos.x+= 10;
} else {
this.mySpritePos.x -= 10;
}
if (this.myYDirection == VerticalDirection.UP) {
this.mySpritePos2.y -= 10;

} else {
this.mySpritePos2.y += 10;
}

this.myBackground.draw(canvas);
this.mySprite.draw(canvas);
this.mySprite2.draw(canvas);

}

Now I want to animate the background image along with with other images.. I am sticking with that..
I know this the right place to get the solution..
Please help me.. Its urgent for me :?

Thanks in advance
mala
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Jan 07, 2010 5:57 am
Location: bangalore

Top

Postby makario » Thu Mar 18, 2010 6:24 pm

Hey, I'm pretty new to Android development, but perhaps this is what you're looking for.

http://www.droidnova.com/2d-sprite-anim ... d,471.html
makario
Freshman
Freshman
 
Posts: 2
Joined: Thu Mar 18, 2010 6:21 pm

Postby mala » Tue Mar 23, 2010 1:06 pm

hi,
Thanks for the reply.
But I already searched there.. unable to find anything..
mala
Junior Developer
Junior Developer
 
Posts: 17
Joined: Thu Jan 07, 2010 5:57 am
Location: bangalore

Re: how to animate background image

Postby Sagar jacky » Wed Dec 05, 2012 12:33 pm

I feel that would be the basic training session definitely required for the top management peoples in an organization and I strongly believe this would be a refreshment session for them. Hope to see many people’s come out with the great ideas like this. Windows help and live chat support number
Sagar jacky
Junior Developer
Junior Developer
 
Posts: 19
Joined: Wed Nov 21, 2012 6:03 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 1 guest