Entitymodifiers not working (AndEngine / Android) - android

I'm playing around with AndEngine. No docs available for reading, so I'm just shooting in the dark here.
Finally got a splash screen showing. Now I'm trying to add some transitions to it, but no luck here. Here's the code:
#Override
public void onLoadComplete() {
mHandler.postDelayed(fadeAway, 2500);
}
protected Runnable fadeAway = new Runnable() {
#Override
public void run() {
// The only child of the scene is our splash sprite
scene.getLastChild().registerEntityModifier(new SequenceEntityModifier(
new ScaleModifier(2500, 100.0f, 200.0f),
new RotationModifier(2500, 0.0f, 78.0f),
new AlphaModifier(2500, 1.0f, 0.0f)
));
}
};
What happens is that the postDelayed() runs fine (waiting for 2.5 secs), but then everything goes black immediately. What I was expecting was that the splash screen should zoom in to 200%, then rotate 78 degrees, then fade out, but since everything goes black it feels that the duration of the modifiers is not working.
Is there an apparent error here?
EDIT: Alright, found the errors: 1) Apparently the pDuration (first argument) is supposed to be in seconds, not milliseconds as everywhere else 2) In ScaleModifier(), 1.0f equals the original size, so that argument is not in percent as expected.
(No flame, but I'm truly amazed how people managed to learn how to use this library without any documentation. There's not a single comment or note in the whole source code. Did people trial-and-error-reverse-engineered everything to find out how it's supposed to work? Can't believe the author put this vast amount of work for this library and never supplied any docs.)

Your errors is listed below:
All durations in AndEngine are in seconds.
Normal scale is 1.0f not 100.0f.
There is no need for Android Handler. You should delay your works in onUpdate methods of the engine or other AndEngine stuff.
You should apply animations only in update thread not anywhere else. mEngine.runOnUpdateThread(...)

Related

Libgdx Stage.setActionsRequestRendering(true) not working as expected

I'm trying to disable continues frame rendering in LibGDX.
As stated in libgdx documentation here, it can be done by calling setContinuousRendering(false) and which worked well.
Other thing i want to do is when action is applied on some actor , every frame must be rendered until action has not finished.
for that i called the method from stage setActionsRequestRendering(true) which changes nothing. frames are dropped and not rendered.
Applied actions on the actors are working but it is applied directly without any effects.
What I'm missing here?
Update :
I have an Actor which is image and applying action to the actor like this.
img.addAction(Actions.moveTo(x, y, 0.5f, Interpolation.swingIn));
This actions skips first few frames. also fps logger displays random number of frames between 1-20 when action is active. There is no other issue which may affect frame rates.
Also this same action works as expected if this action is applied after dragging actor. but does not work if applied after clicking.
Action applied after drag.
img.addAction(Actions.sequence(
Actions.moveTo(x, y, 0.5f , Interpolation.exp5Out),
Actions.run(new Runnable() {
#Override
public void run() {
dragged = true;
}
})));
At first here is the wiki entry for continous rendering.
To anwser your question: You are missing to call
Gdx.graphics.requestRendering();
on your own. Many default actions as mentioned in the wiki entry are calling this method, so they request a render call. For your own custom actions you have to do this manualy.

Unity 2D Android ball jumping script AddForce

I am new to Unity and I am trying to learn the basics, I learn physics at school(ten grade).
What I have done so far - added a ball to my project and used gravity on it with RigidBody.
I want to make the ball jump suddenly on air when there is some touch input, for example - flappy bird.
My script is basic:
void Update()
{
if (Input.touchCount == 1)
{
GetComponent<Rigidbody>().AddForce(new Vector2(0, 10), ForceMode.Impulse);
}
}
With this script, the ball is falling(gravity) and when I touch the script, is Y coordinate changes but it happens by sudden (no animation) and it changes by like ~1 and continue falling(I can't keep the ball on screen) , also I can make it jump only once, if I press multiple times it will jump only once, as you can see here:
https://vid.me/aRfk
Thank you for helping.
I have created same scene in Unity3D Editor and played a little with same setup you have. And yes I had similar problems adding force on Update and also (but less) on FixedUpdate. But adding force on LateUpdate seems to work okay.
Here is my code:
public Rigidbody2D rb2dBall;
void LateUpdate()
{
if(Input.GetKeyUp(KeyCode.Space))
{
rb2dBall.AddForce (Vector2.up * 10f, ForceMode2D.Impulse);
}
}
And also I turned on interpolation:
I cant say why the physics bahaves like this, could be some bug in Unity3D 5.X since on FixedUpdate it should work fine.
Firstly, when working with physics in Unity, it's highly recomended to use the FixedUpdate method, instead of the Update. You can check in this link http://docs.unity3d.com/ScriptReference/MonoBehaviour.FixedUpdate.html
The second thing is that maybe you are not applying so much force at the ball, the force needed to give a quite impulse will depends of the mass of your ball's rigidbody. So try to do something like that:
GetComponent<Rigidbody>().AddForce(Vector2.up * 100, ForceMode.Impulse);
Change the fixed value 100 to adjust your needs.

Andengine - any missing FPS causes other scene entities to slightly shake as it chases a fast entity

I am creating an Andengine game and I copied this SmoothChaseCamera class from the Andengine development book I bought.
package com.killercoolgames.djdestiny.custom.andengine;
import com.killercoolgames.djdestiny.MainActivity;
import org.andengine.engine.camera.SmoothCamera;
import org.andengine.entity.IEntity;
public class SmoothChaseCamera extends SmoothCamera {
private static final MainActivity MAIN_ACTIVITY = MainActivity.getInstance();
private IEntity chaseEntity;
public SmoothChaseCamera(float x, float y, float width, float height) {
super(x, y, width, height, 3000f, 1000f, 1f);
}
#Override
public void setChaseEntity(IEntity chaseEntity) {
super.setChaseEntity(chaseEntity);
this.chaseEntity = chaseEntity;
}
#Override
public void updateChaseEntity() {
if( chaseEntity != null ) {
// Always follow the entity and the camera's centerY will be slightly ahead of the entity.
setCenter(getCenterX(), chaseEntity.getY() + MAIN_ACTIVITY.CAMERA_HEIGHT / 3);
}
}
#Override
public void reset() {
super.reset();
set(0, 0, MAIN_ACTIVITY.CAMERA_WIDTH, MAIN_ACTIVITY.CAMERA_HEIGHT);
setCenterDirect(MAIN_ACTIVITY.CAMERA_WIDTH / 2, MAIN_ACTIVITY.CAMERA_HEIGHT / 2);
}
}
It does work correctly and everything and when I turn off all parallax layers and collision detection in my game, It does run at 59.80 FPS or higher normally on my real Samsung Galaxy Tab 4 device. If I make the chaseEntity have a high velocity of 300f or higher. The entity is moving pretty fast and the camera does follow it, but I notice a jut/shake occur every second on all entities on the scene except the chased entity. If I reduce the velocity down to 50f or less, I still get the same FPS, but because I am going slower, you do not notice the shake at all. I do believe that the camera is following correctly, because there is no jittering when looking at the chased entity, but if i look at any other objects in the scene, they jitter as the camera moves.
The problem is I need the entity to go fast because he is flying fast, and the level should end when he hits a certain Y. Ive tried adjusting other entities in the scene to account for the speeds. Ive tried slowing down the player and increasing the enemies speed and the issue still occurs. I am creating a game where you are constantly flying upwards as you move past enemies in the scene. The camera is super smooth following the entity it is chasing always. It is just the other entities in the scene seem to not be updating smoothly.
I have tried disabling everything to see if I could hit 60FPS and I think its not possible to hit everytime, which makes sense. I think it is the camera causing the issue but I am not sure. The moment I start to turn other stuff on in the game, my lag does go up abit to 59.50 FPS or higher but sometimes it will still stay the same around the 59.80 consistently with all stuff on, and it kind of tells me its the camera not being able to keep up. Is this the case? How to fix this?
After doing some debugging today, I do believe its just any lagging FPS left that does not make it to 60FPS is what is causing the lag. I am not sure how to fix this. I am using a PhysicsHandler to update the sprites position for the camera to follow. I tried doing a MoveModifier and still had the same issue. I cannot figure out a way to keep the camera moving upwards smoothly.
I even tried doing a FixedStepEngine and with that, it make the lag consistent but I could never actually get rid of it. It always was there but much worse when switching to a FixedStepEngine.

Android OpenGL gameloop outside onDrawFrame

I've got a problem with creating gameloop for my first game. I've read a lot about it but still can't figure it out. It's based on OpenGL so I've used onDrawFrame as a game loop and it works fine on my phone. Problem is that onDrawFrame is refresh time depends on hardware so it runs way too fast on some devices. So what I want is adding a separate game loop that will refresh itself at constant period of time on all smartphones. (and onDrawFrame will only take care of graphics as it should)
As for now I have:
myGameRenderer class with all openGl stuff an onDrawFrame
myGLSurfaceView that supports touch events
myGameActivity
onDrawFrame activates myGameUpdate function that controls changing positions of all objects in game depending on info from myGLSurfaceView
I've tried with creating new Runnable but it doesn't seem to work, I can't figure out how to start that runnable and where i should place it (I've tried to place it in myGameRenderer class, but it didn't seem to work, nothing was moving:
private final Runnable mUpdateDisplay = new Runnable() {
#Override
public void run() {
update();
}};
private void update() {
//some update stuff blablabla
//some update stuff blablabla
mHandler.postDelayed(mUpdateDisplay,40); //to refresh at 25 fps
}
but I guess I don't get the idea of it - I mean I create this runnable.
I've tried to place it in onCreateSurface to start it but no effect.
So - is the generall idea ok? And how to start the loop? Where to place it? Or should I use any other way?
Ok it was simple - I was just missing r.run();
But as allways there's something. Now it works as i wanted - I mean frames doesn't depend on hardware, but everything is not as smooth as it was - and part of objects in 3d are flickering. Seems like some objects visibly are drawn faster, some later and it looks ugly.
So what am I doing wrong? Is there a better way?

Graphics Choppy

I was trying to make an into transition to my game by having two bitmaps slide apart, like a garage door opening from the middle and half sliding downwards and half upwards. Anyway, when I do it, it looks really choppy and the frame rate seems unstable/unreliable. Here's how I'm doing it.
public class TFView extends View{
...
public void startlevel(Canvas c){
long l =(SystemClock.currentThreadTimeMillis()-starttime)/3;//*(height/500);
if(l<1000){
c.drawBitmap(metalbottom,0,height/2+l,p);
c.drawBitmap(metaltop,0,0-l,p);}
}
public void endlevel(Canvas c){
long l =(SystemClock.currentThreadTimeMillis()-failtime)/3;
if(l>=height/2){
c.drawBitmap(metaltop, 0, 0, p);
c.drawBitmap(metalbottom, 0,height/2 , p);
}
else{
c.drawBitmap(metalbottom,0,-height/2+l,p);
c.drawBitmap(metaltop,0,height-l,p);}
}}
and i set the times for when I want to open/close the doors respectively. So what do you think I should change to make it a more smooth transition? Would converting it to surfaceview help?
I had the same problem. I know what you mean with "choppy". The animation speed is NOT consistent even though you have a time based animation i.e. you are using
SystemClock.currentThreadTimeMillis()
The choppiness is caused by currentThreadTimeMillis(). It "returns milliseconds running in the current thread". That is, when you use currentThreadTimeMillis() "time" only elapses when the current thread is RUNNING. But your renderer thread is NOT ALWAYS running - as you would expect in a multitasking environment. Thus every time the thread is not running your animation is also not "running" (time is not elapsing).
Solution: Use
SystemClock.elapsedRealtime()
I have to admit I'm not the best when it comes to animation in Android but I thought I'd contribute.
From your explanation, could you use TranslateAnimation? Your animation would then be very smooth.
As far as I'm aware, if the animations Android provides are not sufficient you should be drawing your graphics in a separate thread, implementing SurfaceView.
This may help or take a look at the Lunar Lander example.

Categories

Resources