Android - Two ScaleAnimation played sequently - java

I want to make simple animation where ImageView is zooming out, and after this, zooming in, and will be grate to change that image when it is invisible. I started with this code:
AnimationSet animationSet = new AnimationSet(true);
ScaleAnimation oldOutScaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
oldOutScaleAnimation.setDuration(500);
animationSet.addAnimation(oldOutScaleAnimation);
ScaleAnimation newInScaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
newInScaleAnimation.setDuration(500);
newInScaleAnimation.setStartOffset(500);
animationSet.addAnimation(newInScaleAnimation);
view.startAnimation(animationSet);
But I don't see animation, I see only:
Image
Image Disappeared
Image Appeared
There is no transtion.
Each of this animation separately works.
I don't want to do this in XML.
Thank you for any reply.

Related

Sprite tint with SpriteBatch.setColor

Why this code doesn't work?
The buttons should be green, but they remain white.
Code works perfect, if i use Textures instead of Sprites.
game.interface_batch.begin();
...
game.interface_batch.setColor(0.596f, 0.984f, 0.596f, 1.0f);
exit_button_sprite.draw(game.interface_batch);
play_button_sprite.draw(game.interface_batch);
settings_button_sprite.draw(game.interface_batch);
game.interface_batch.setColor(1.0f, 1.0f, 1.0f, 1.0f);
...
game.interface_batch.end();
How to change the color of multiple Sprites?
Code like this is really heavy for more than 3 sprites:
exit_button_sprite.setColor(0.596f, 0.984f, 0.596f, 1.0f);
play_button_sprite.setColor(0.596f, 0.984f, 0.596f, 1.0f);
settings_button_sprite.setColor(0.596f, 0.984f, 0.596f, 1.0f);
exit_button_sprite.draw(game.interface_batch);
play_button_sprite.draw(game.interface_batch);
settings_button_sprite.draw(game.interface_batch);

OpenGL 2D projection stretched by aspect ratio

I am currently trying to convert the drawing methods for my 2D java game to OpenGL by using JOGL, because native java seems rather slow for drawing high-res images in rapid succession. Now i want to use a 16:9 aspect ratio, but the problem is that my image is stretched to the sides. Currently i am only drawing a white rotating quad for testing this:
public void resize(GLAutoDrawable d, int width, int height) {
GL2 gl = d.getGL().getGL2(); // get the OpenGL 2 graphics context
gl.glViewport(0, 0, width, height);
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glOrtho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
}
public void display(GLAutoDrawable d) {
GL2 gl = d.getGL().getGL2(); // get the OpenGL 2 graphics context
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
gl.glColor3f(1.0f,1.0f,1.0f);
degree += 0.1f;
gl.glRotatef(degree, 0.0f, 0.0f, 1.0f);
gl.glBegin(GL2.GL_QUADS);
gl.glVertex2f(-0.25f, 0.25f);
gl.glVertex2f(0.25f, 0.25f);
gl.glVertex2f(0.25f, -0.25f);
gl.glVertex2f(-0.25f, -0.25f);
gl.glEnd();
gl.glRotatef(-degree, 0.0f, 0.0f, 1.0f);
gl.glFlush();
}
I know that you can somehow adress this problem by using glOrtho() and I tried many different values for this now, but none of them achieved a unstretched image. How do I have to use this? Or is there another simple solution for this?
The projection matrix transforms all vertex data from the eye coordinates to the clip coordinates.
Then, these clip coordinates are also transformed to the normalized device coordinates (NDC) by dividing with w component of the clip coordinates.
The normalized device coordinates is in range (-1, -1, -1) to (1, 1, 1).
With the orthographic projection, the eye space coordinates are linearly mapped to the NDC.
If the viewport is rectangular this has to be considered by mapping the coordinates.
float aspect = (float)width/height;
gl.glOrtho(-aspect, aspect, -1.0f, 1.0f, -1.0f, 1.0f);

glTranslate error in simple JOGL program

I am trying to create a simple JOGL program, and have run into a problem. I just imported all of the necessary packages into my class file, however now, every time I use the glTranslate function, it is being flagged red as an error, for example at the end of this block of code.
public void lab2a(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glTranslatef(-1.0f, -1.0f, -6f);
// Drawing first rectangle (blue)
gl.glBegin(GL.GL_QUADS);
gl.glColor3f(0f, 0f, 1f); // sets color to blue
gl.glVertex3f(-0.5f, 0.5f, 0.0f); //Top left vertice
gl.glVertex3f(0.5f, 0.5f, 0.0f); //Top right vertice
gl.glVertex3f(-0.5f, -0.5f, 0.0f); //Bottom left vertice
gl.glVertex3f(0.5f, -0.5f, 0.0f); //Bottom right vertice
gl.glEnd();
gl.glTranslate(1.1f, 0f, 0f);
The flag reads: "cannot find symbol", and is present for each use of glTranslate I use. Does anybody have any idea how to fix this?
Your source code is obsolete, it uses JOGL 1 whose maintenance was stopped in 2010.
Please switch to JOGL 2, go to jogamp.org. Replace GL.GL_QUADS by GL2.GL_QUADS, replace GL gl = drawable.getGL() by GL2 gl = drawable.getGL().getGL2(), etc... Look at the API documentation here.

Android slide up window

Can anyone point me to an example, or a lib to use for a slide up window. I have an app and on an action I want to slide a window up from the bottom of the screen that displays info to the user.
I would like the window to slide up only a little bit to show the info. Kind of like a hnt to the user, maybe 1/4 way up the screen.
This window can be manually dismissed or on a timer. I am looking to do this with xamarin, but a java example would also help.
You might have to change some of the variables in this method.
I use this one in one of my apps. Animates a relativeLayout from bottom to top
private void animate(){
RelativeLayout rl = (RelativeLayout)findViewById(R.id.yourLayout);
AnimationSet set = new AnimationSet(true);
Animation animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
Animation.RELATIVE_TO_SELF, 0.85f, Animation.RELATIVE_TO_SELF, 0.0f
);
animation.setDuration(250);
set.addAnimation(animation);
LayoutAnimationController controller = new LayoutAnimationController(set, 0.25f);
rl.setLayoutAnimation(controller);
}

Java openGL - drawing a 3D object

Im looking to draw a 3D object in openGL but whats the best way to approach this? I was thinking of drawing the side profile of it in 2D and maybe then fleshing it out to become 3D but is that possible? I think it would be easier to do it that way then just go straight into 3D but if you cant then id just be wasting my time.
I also cant figure out how to add the sky and maybe even the sea with a reflection, is this easily done?
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
gl.glColor3f(1.0f, 1.0f, 1.0f);
gl.glPushMatrix();
gl.glTranslatef(-1.0f, 0.0f, 0.0f);
gl.glRotatef((float) shoulder, 0.0f, 0.0f, 1.0f);
gl.glTranslatef(1.0f, 0.0f, 0.0f);
// gl.glPushMatrix();
gl.glScalef(2.0f, 0.4f, 1.0f);
glut.glutWireCube(1.0f);
// gl.glPopMatrix();
gl.glTranslatef(1.0f, 0.0f, 0.0f);
gl.glRotatef((float) elbow, 0.0f, 0.0f, 1.0f);
gl.glTranslatef(1.0f, 0.0f, 0.0f);
// gl.glPushMatrix();
gl.glScalef(2.0f, 0.4f, 1.0f);
glut.glutWireCube(1.0f);
// gl.glPopMatrix();
gl.glTranslatef(1.0f, 1.0f, 1.0f);
gl.glRotatef((float) hand, 0.0f, 0.0f, 1.0f);
gl.glTranslatef(1.0f, 0.0f, 0.0f);
// gl.glPushMatrix();
gl.glScalef(2.0f, 0.4f, 1.0f);
glut.glutWireCube(1.0f);
// gl.glPopMatrix();
Ive just been trying random numbers to try and get it to work but not such luck so far!
Ok first, reflections can be hard depending on how you want to do them. You will definitely need to learn more OpenGL before attempting something like that. Second, 3D objects require some more matrix stuff, this is an example from my init method in my 3D game:
private void initGl() {
glViewport(0, 0, Display.getWidth(), Display.getHeight());
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
GLU.gluPerspective(45.0f, Display.getWidth() / Display.getHeight(), 1.0f, 100.0f);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClearDepth(1.0f);
glDepthFunc(GL_LEQUAL);
glEnable(GL_DEPTH_TEST);
glShadeModel(GL_SMOOTH);
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
glEnable(GL_FOG);
glFogi(GL_FOG_MODE, GL_EXP2);
glFogf(GL_FOG_DENSITY, density);
glHint(GL_FOG_DENSITY, GL_FASTEST);
glEnable(GL_CULL_FACE);
glCullFace(GL_BACK);
}
You will also need to clear the buffer like this before drawing:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
You are almost correct when you say just flesh out a 2D object. If we were still using immediate mode (glBegin()/glEnd()), your approach would be correct. However, immediate mode is deprecated now and we usually use VBOs. I would suggest going on YouTube and searching for theCodingUniverse if you are using LWJGL, he has a video on VBOs and advanced rendering, its how I learned them!
Good luck in the world of 3D, its not easy at all, but its (in my opinion), much more satisfying than 2D when you get something working.
Also, consider investing in the RedBook, its all about LWJGL.

Categories

Resources