Differences between GLES2 and GLES2 Anchor Center

In this article, I will try to describe most important differences between two major AndEngine branches, GLES2 and GLES2 Anchor Center, there are some major differences between them.

In  my previous article, I was explaining differences between GLES1 (really old, not active, not recommended) and GLES2.

Currently, there are 3 AndEngine branches, which are:

  • GLES1 - old, abandoned by development, also almost not used by AndEngine developers, which means poor support. 
  • GLES2 - successor of the GLES1 branch, still actively used by developers, but its strongly recommended to move to the latest version of the engine.
  • GLES2 Anchor Center - latest version of the engine, quoting author:

"Rather sooner than later the GLES2-AnchorCenter branch will be merged into the GLES2 branch!
The main, most significant change in the GLES2 Anchor Center is that the coordinate system has changed. The coordinate system in the GLES2 Anchor Center branch has its origin in the lower left, this was changed for multiple reasons:

  • It is the native OpenGL coordinate system. (I can save a few +- calculations here and there.)
  • It is the same coordinate system as cocos2d-iphone and cocos2d-x. (This eases porting efforts in both directions by a whole bunch!)
  • It allowed author of the engine to easily/efficiently write the AndEngineCocosBuilderExtension, which allows reading a format exported by CocosBuilder.
  • It just feels more natural for any side-scrolling game.


Another thing that changed in this branch is that the anchorpoints (rotatincenter, scalecenter, etc…) are now relative, from 0.0 to 1.0, instead of being absolute values. So in general, AndEngine got a little more cocos2d-like on this branch, which is definitely not a bad thing.

To better understand, how does coordinate system works in GLES2 Anchor Center, lets take a look at this sample image:

Okay, lets say its our scene, lets say our camera size is 800x by 480y,

  • bottom left corner is 0x, 0y, top left corner is 0x, 480y
  • bottom right corner is 800x, 0y, top right corner is 800x, 480y
  • we have 3 images: image A, image B, and image C
  • image A is 50 width by 50 height, so to place it in the following position  we needed to place it on the 25x, 25y. 
  • imageB is 200 width by 150 height, I wanted to place it in the middle of the screen, which means its positioned in the 400x, 240y (which is 0.5 * camera width, by 0.5 * camera height)
  • image A and imageB are both attached to the scene.
  • image C is attached to the imageB (on the 0x, 0y - of the imageB)

Following this diagram, you should understand how does it work.

Comparison between AndEngine GLES1 and GLES2

1. What does GLES1 and GLES2 mean?
They are three AndEngine versions (branches), GLES2 and GLES2 Anchor Center which is is latest version of the engine, GLES1 version development  has been stopped. That's why if you are new, its STRONGLY recommended to use latest version of the engine, obviously its always better to work with newest software. Be aware that on my website, in my articles, I am always trying to use latest engine version.



2. Most important differences between those two versions:
Firs of all, GLES2 requires Android version >= 2.2
Some developers says that GLES2 is slower in comparison with GLES1 in some cases.
GLES2 is latest, and currently developed version of the engine.
If you want to know most important improvements in GLES2, please check THIS THREAD.

3. Which one should I select?
For me there are no doubts, you should use latest version of the engine. But if you decided to publish your application for wider android audience, GLES2 might be bad idea, because it requires android version >= 2.2 The good news is the fact, that this version is currently supported by 89% of devices worldwide - according to the official informations - MORE INFO HERE. So what's the conclusion? Basically everything depends on your application needs. Latest engine version, more features, active development!

See also: GLES2 vs GLES2 Anchor Center - differences.
4. Performance differences:

As previously mentioned, some developers says, that GLES2 is slower in some cases in compare to GLES1, also it has been proven by some tests. But even though, I strongly recommend to use latest software version

How to make Clone Object in Java

The clone method generates a duplicate copy of the object on which it is called.
The object cloning is a way to create exact copy of an object. For this purpose, clone() method of Object class is used to clone an object.
Only classes that implement the Cloneable interface can be cloned. The Cloneable interface defines no members. It is used to indicate that a class allows a bitwise copy of an object (that is, a clone) to be made.
How to make Clone Object in Java,make Clone Object in Java,Clone Object in Java,Object in Java,

If you try to call clone( ) on a class that does not implement Cloneable, a CloneNotSupportedException is thrown. A clone is simply an exact copy of the original.

Example :
class Data implements Cloneable{
    
    int data1;
    int data2;
    
    public Data cloning()
    {  
        try{
            return (Data)super.clone();  
        }catch (CloneNotSupportedException cns) {
            System.out.println("Cloning Error");
            return this;
        }
    }  
}

public class Javaapp {

    public static void main(String[] args) {
        
        Data d1 = new Data();
        d1.data1 = 50;
        d1.data2 = 100;
        System.out.println("d1.data1 = "+d1.data1);
        System.out.println("d1.data2 = "+d1.data2);
        
        Data d2 = d1.cloning();
        System.out.println("d2.data1 = "+d2.data1);
        System.out.println("d2.data2 = "+d2.data2);
    }
}
Flow of Program :
For see the flow of working click on image

Have any trouble or queries please comment below.

Repeat Task at particular time in Java

Sometimes you need to schedule your task and want to repeat them at particular time like check the notification of user after ever 5 sec etc.
For this purpose Java has Timer and TimerTask class but what is it ?
  • java.util.Timer is a utility class that can be used to schedule a thread to be executed at certain time in future. Java Timer class can be used to schedule a task to be run one-time or to be run at regular intervals.
  • java.util.TimerTask is an abstract class that implements Runnable interface and we need to extend this class to create our own TimerTask that can be scheduled using java Timer class.
Repeat Task at particular time in Java,Task at particular time in Java,particular time in Java,time in Java,timer and timer task in java,timer in java,timertask in java,timer example java

package com.blogspot.geekonjava;
 
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
 
public class MyTimerTask extends TimerTask {
 
    @Override
    public void run() {
        System.out.println("Timer task started at:"+new Date());
        completeTask();
        System.out.println("Timer task finished at:"+new Date());
    }
 
    private void completeTask() {
        try {
            //assuming it takes 20 secs to complete the task
            Thread.sleep(20000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
     
    public static void main(String args[]){
        TimerTask timerTask = new MyTimerTask();
        //running timer task as daemon thread
        Timer timer = new Timer(true);
        timer.scheduleAtFixedRate(timerTask, 0, 10*1000);
        System.out.println("TimerTask started");
        //cancel after sometime
        try {
            Thread.sleep(120000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        timer.cancel();
        System.out.println("TimerTask cancelled");
        try {
            Thread.sleep(30000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
 
}

Result :
Notice that one thread execution will take 20 seconds but Timer object is scheduled to run the task every 10 seconds

Timer class is thread safe and multiple threads can share a single Timer object without need for external synchronization.
Timer class uses java.util.TaskQueue to add tasks at given regular interval and at any time there can be only one thread running the TimerTask, for example if you are creating a Timer to run every 10 seconds but single thread execution takes 20 seconds, then Timer object will keep adding tasks to the queue and as soon as one thread is finished, it will notify the queue and another thread will start executing.

Why Quartz doesn't remove deleted job from the scheduling

Sometimes when we use Quartz for schedule the task in Java and when you want to remove the old task then you would be face some unexpected error.
Your old Quartz task remain running and these type of error got by my friend David :

Start from hereScheduling Job in Java via Quartz Scheduler

Question by David 
I'm developing scheduled services.
The application is developed using JDK 1.6, Spring Framework 2.5.6 and Quartz 1.8.4 to schedule jobs.
I've two clustered servers with WebLogic Server 10.3.5.
The behavior that I noticed is that if a job is removed (or renamed) from the application, Quartz keeps trying to launch the old job (which seems to be registered in the database that Quartz uses to synchronize its instances).
Can someone explain the reason for this behavior?
My need is that when I delete a job in the application and I restart WebLogic instances, Quartz does not attempt to boot the old job.
Thanks in advance.
You can fixed these error.
Why Quartz doesn't remove deleted job from the scheduling,Quartz doesn't remove deleted job from the scheduling,doesn't remove deleted job from the scheduling,remove deleted job from the scheduling,deleted job from the scheduling,job from the scheduling,remove quartz in java

See this also : Use Quartz Scheduler with Java Web Application
You need to remove the job explicitly from the quartz scheduler, have you done that?
For example if you have this scedhuler
private org.quartz.Scheduler myScheduler = null;
you need to invoke:

myScheduler.deleteJob(...
when the job is removed or renamed.

If you do, maybe you're passing incorrect key?

Alternatively, when you build the quartz job, you can use: jobBuilder.storeDurably(false) This will cause your quartz job to be deleted automatically when there are no longer active trigger associated to it.