sourcemars / cocos2d-android-1

Automatically exported from code.google.com/p/cocos2d-android-1
0 stars 0 forks source link

PageTurn transition doesn't work #7

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
my iphone app use this feature,and when i port it to android use 
cocos2d-android,it doesn't work.Is there any plan to support it?

Original issue reported on code.google.com by nac.ji...@gmail.com on 13 Oct 2010 at 2:28

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I found two bugs:::

1. CCGridAction.java file
//I modified like below
public void start(CCNode aTarget) {
        super.start(aTarget);
        System.out.println("CCGridAction start");

        CCGridBase newgrid = grid();
        CCGridBase targetGrid = target.getGrid();

        // Class<?> clazz = newgrid.getClass();
        if (targetGrid != null && targetGrid.reuseGrid() > 0) {
            if (targetGrid.isActive() &&
                    targetGrid.getGridWidth() == gridSize.x &&
                    targetGrid.getGridHeight() == gridSize.y &&
                    targetGrid.getClass() == newgrid.getClass()) {
                System.out.println("CCGridAction reuse grid");
                targetGrid.reuse(CCDirector.gl);
            } else {
                throw new RuntimeException("Cannot reuse grid_");
            }
        } else {
            System.out.println("CCGridAction else");
//            if (targetGrid != null && targetGrid.isActive())
//              targetGrid.setActive(false);

            target.setGrid(newgrid);

            if (target.getGrid() != null)
            {
                //System.out.println("CCGridAction targetGrid.setActive(true)");
                target.getGrid().setActive(true);
            }
        }
    }

2. I modified CCGrid3D.java
public void blit(GL10 gl) {
...
//before gl.glDrawElements() fucntion
indices.position(0); // It's IMPORTANT!!!!!!!!!!!!!!!!!!!!!!!!!!!!
...
}

Pageturn effect of android cocos2d has a lot of problems, but above solution 
enable pageturn  at least. : )

Original comment by yongRak...@gmail.com on 24 Nov 2010 at 7:52

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago

//Additionally, I modified like below::
//above code is inefficient. 

// at CCGridBase.java file
// you have to modify the maximum size of textureSize. I set 1024.
public CCGridBase(ccGridSize gSize) {
        CGSize s = CCDirector.sharedDirector().winSize();

        int w = CCTexture2D.toPow2((int)s.width);
        int h = CCTexture2D.toPow2((int)s.height);
        int textureSize = Math.max(w, h);
        if (textureSize > 1024) {
            textureSize = 1024;
        }

//I think vertices have a little bugs. 
//at CCGrid3D file,  
public void blit(GL10 gl) {
        int n = gridSize_.x * gridSize_.y;

        // Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
        // Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
        // Unneeded states: GL_COLOR_ARRAY
        gl.glDisableClientState(GL10.GL_COLOR_ARRAY);

        ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.limit()*3*4);
        //System.out.printf("vertices limit = %d\n", vertices.limit());
        vbb.order(ByteOrder.nativeOrder());
        mVertexBuffer = vbb.asFloatBuffer();            
        mVertexBuffer.clear();          
        mVertexBuffer.position(0);
        for (int i = 0; i < vertices.limit(); i=i+3) {            
            mVertexBuffer.put(vertices.get(i));
            mVertexBuffer.put(vertices.get(i+1));
            mVertexBuffer.put(vertices.get(i+2));            
        }
        mVertexBuffer.position(0);
        gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);

        //gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertices);
        gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, texCoordinates);
        gl.glDrawElements(GL10.GL_TRIANGLES, n * 6, GL10.GL_UNSIGNED_SHORT, indices);

        // restore GL default state
        gl.glEnableClientState(GL10.GL_COLOR_ARRAY);
    }

// at CCGridAction.java file
// you have to use target.getGrid(), not targetGrid
 public void start(CCNode aTarget) {
        super.start(aTarget);

        CCGridBase newgrid = grid();
        CCGridBase targetGrid = target.getGrid();

        // Class<?> clazz = newgrid.getClass();
        if (targetGrid != null && targetGrid.reuseGrid() > 0) {
            if (targetGrid.isActive() &&
                    targetGrid.getGridWidth() == gridSize.x &&
                    targetGrid.getGridHeight() == gridSize.y &&
                    targetGrid.getClass() == newgrid.getClass()) {
                targetGrid.reuse(CCDirector.gl);
            } else {
                throw new RuntimeException("Cannot reuse grid_");
            }
        } else {
            if (targetGrid != null && targetGrid.isActive())
                target.getGrid().setActive(false);

            target.setGrid(newgrid);

            if (target.getGrid() != null)
                target.getGrid().setActive(true);
                //targetGrid.setActive(true);
        }
    }

//And, I modified CCPageTurn3D.java file. 
//below code will turn along Y-axis with flat page
//It's optional.
 public class CCPageTurn3D extends CCGrid3DAction 
{
    public float ay;
    public float theta;
    public float rho;

    public static CCPageTurn3D action(ccGridSize gSize, float d) 
    {
        return new CCPageTurn3D(gSize, d);
    }

    protected CCPageTurn3D(ccGridSize gSize, float d)
    {
        super(gSize, d);
        theta = 90.0f;
        ay = -400.0f;
    }

    /*
     * Update each tick
     * Time is the percentage of the way through the duration
     */
    @Override
    public void update(float time) 
    {
        System.out.println("CCPageTurn3D update()");
        rho = (float) (time * Math.PI);

        float sinTheta = (float)Math.sin(theta);
        float cosTheta = (float)Math.cos(theta);

        for( int i = 0; i <=gridSize.x; i++ ) {
            for( int j = 0; j <= gridSize.y; j++ ) {
                // Get original vertex
                CCVertex3D  p = originalVertex(ccGridSize.ccg(i,j));
                //System.out.printf("vertex[%d][%d] (%f, %f, %f) ->", i, j, p.x, p.y, p.z);

                float R = (float)Math.sqrt((p.x*p.x) + ((p.y - ay)*(p.y - ay)));
                float r = R * sinTheta;
                float alpha = (float)Math.asin( p.x / R );
                float beta = alpha / sinTheta;
                float cosBeta = (float)Math.cos( beta );

                p.x -= 300;
                //p.y -= 300;

                float x = (float)( r * Math.sin(beta));
                float y = ( R + ay - ( r*(1 - cosBeta)*sinTheta));
                float z = (r * ( 1 - cosBeta ) * cosTheta) ;

                p.x = (float) (x*Math.cos(rho) - z*Math.sin(rho));
                p.y = y;
                p.z = (float) (x*Math.sin(rho) + z*Math.cos(rho));

                p.x += 300;

                setVertex(ccGridSize.ccg(i,j), p);
                //System.out.printf("(%f, %f, %f)\n",  p.x, p.y, p.z);

            }
        }
    }

}

Original comment by yongRak...@gmail.com on 29 Nov 2010 at 5:05

GoogleCodeExporter commented 8 years ago
Now, I'm suffering with http://www.cocos2d-iphone.org/forum/topic/4324 issue. 

setting the variable depthBufferFormat_ of CCDirector doesn't work. : ( 

Original comment by yongRak...@gmail.com on 29 Nov 2010 at 7:51

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
I found the bug again : )
I overloaded the CCTexture2D(Creator) function and init() function in 
CCTexture2D.java file like below:

public CCTexture2D(Bitmap image, CGSize imageSize, CGSize contentSize) {
...
init(bitmap, imageSize, contentSize);
}
private void init(Bitmap image, CGSize imageSize, CGSize contentSize) {
        mBitmap = image;

        mWidth = image.getWidth();
        mHeight = image.getHeight();
        mContentSize = contentSize;
...
}

// And, I called above overloaded function at CCGridBase(ccGridSize gSize) 
function
// like below:
public CCGridBase(ccGridSize gSize) {
...
CCTexture2D texture = new CCTexture2D(bitmap, CGSize.make(textureSize, 
textureSize), CGSize.make(s.width, s.height));
...
}

// you know that coordinates of texture must be limited by actual size of 
display. 

Original comment by yongRak...@gmail.com on 29 Nov 2010 at 11:25

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Sorry, but I'm not familiar with git. (I love svn.)

I found some memory leak using klocwork tool. 

every overrided finalize() function must call super.finalize(); 

Original comment by yongRak...@gmail.com on 14 Dec 2010 at 1:16

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Hi ,I am new to android ,can u tell me how to implement the 2d page flip using 
this.

Original comment by ramuduma...@gmail.com on 23 Jan 2011 at 11:57

GoogleCodeExporter commented 8 years ago
Hi,
I have some questions:

1. Is there any option how to fix this problem with page turn transition ? 
I tried pieces of code on this page, application didn't crash that was good, 
but application page transition animation didn't work. This transition effect 
is very important for my project because I make  a port of iPhone application 
and they must be all the same.

2. When will be submitted the merged code ? I found here: "some day later" .... 
: (

Thanks

Original comment by hajek.mi...@gmail.com on 13 Apr 2011 at 3:38

GoogleCodeExporter commented 8 years ago
Hi,

I'm newbie with android cocos2d. I do an application with many transition 
effect. Is there any update for transition bug in the previous comment? 

I hope admin release new android cocos2d version.

Thanks and regards,
Vu Phung

Original comment by vu.phungthe on 17 Dec 2012 at 4:10