Sign in to follow this  

Unity create fold able paper

Recommended Posts

Hello every one, i'm working on a game, i have been working with game engines like UDK and Unity for many years, now I come into Android and eclipse, 
i have a question and im really confused, lets describe.
i want to make an android game which is something like origami, the main problem is how to simulate the paper behavior, i mean folding the paper dynamically, 

i have searched times and time different options and ideas, i now think that i have this options to chose:

1- use bitmapmesh in android- 

with this option, i have some problems and questions about DrawBitmapMesh! i founded this code:

public class MainView extends SurfaceView implements SurfaceHolder.Callback, Runnable {
  private SurfaceHolder holder=null;
  private Thread thread=null;
  private int isDrag;
  private Paint paint;
  private Bitmap bmp;
  private float[] vers;
  private ArrayList<Circle> container;

  public MainView(Context context)

     isDrag = -1;
     container = new ArrayList<Circle>();
     paint = new Paint();
     paint.setColor(Color.rgb(200, 0, 0));
     bmp =  BitmapFactory.decodeResource(getResources(),R.drawable.img); 

  public void surfaceDestroyed(SurfaceHolder holder)
     thread = null;

  public void surfaceCreated(SurfaceHolder holder)
     this.holder = holder;
     thread = new Thread(this);

  public void surfaceChanged(SurfaceHolder holder, int format, int width, int height)
     // Place the circle to the four corners of the image
     Circle c1 = new Circle(25f, 10f, 10f);
     Circle c2 = new Circle(25f, bmp.getWidth()+10, 10f);
     Circle c3 = new Circle(25f, 10f, bmp.getHeight()+10);
     Circle c4 = new Circle(25f, bmp.getWidth()+10, bmp.getHeight()+10);

     // Create a containing array of coordinates
     vers = new float[]{c1.x, c1.y, c2.x, c2.y, c3.x, c3.y, c4.x, c4.y};
     if(thread != null) thread.start();

  public void run()
     while (thread != null)
        // Fill
        Canvas canvas = holder.lockCanvas();

        // Draw image
        canvas.drawBitmapMesh(bmp, 1, 1, vers, 0, null, 0, null);

        // And draw a circle
        int size = container.size();
        for(int i=0 ; i< size ; i++)
           Circle c = container.get(i);
           canvas.drawCircle(c.x, c.y, c.radius, paint);

  // Click at the time of the event
  public boolean onTouchEvent(MotionEvent event)
     float x = event.getX();
     float y = event.getY();

     // When touch screen
     if(event.getAction() == MotionEvent.ACTION_DOWN)
        int size = container.size();
        for(int i=0 ; i<size ; i++)
           Circle c = container.get(i);
           if((c.x-x)*(c.x-x) + (c.y-y)*(c.y-y) < c.radius*c.radius)
              isDrag = i;

     // During a drag
     else if (event.getAction() == MotionEvent.ACTION_MOVE)
        if(isDrag != -1)
           Circle c = container.get(isDrag);
           c.x = x;
           c.y = y;
           vers[isDrag*2] = c.x;
           vers[isDrag*2+1] = c.y;

     // When you release your finger
     else if(event.getAction() == MotionEvent.ACTION_UP)
        isDrag = -1;

     return true;

and these are the Circle and mainActivity classes:

public class Circle
   public float radius;
   public float x;
   public float y;
   public Circle(float radius, float x, float y)
      this.radius = radius;
      this.x = x;
      this.y = y;
public class MainActivity extends Activity {

   protected void onCreate(Bundle savedInstanceState) {
         setContentView(new MainView(this));

   public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(, menu);
      return true;


this option result is something like this:





this is not what i want, but it is some Shadow of it. the problem about this is that, it scales the bitmap, but i want to FOLD the paper! is it possible to complete this surface view and make something like this:






2- use OpenGl in andorid- 

another option is to use openGl to make a shape and then Implement the folding behavior

3- Create Custom meshes and -

one other option is to make custom meshes, Those are just triangles and then giving them correct uv coordinates, 

i dont know which one of these options are available to Implement , could any one help me which one (or any!) of these ways should i follow and how?

any suggestions will be helpful, 


Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

  • Announcements

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By BAG Labs
      Mobile SoS

      Platform: Android
      Genre: Board
      Link: Google Play
      This games sharpen memory and test your strategies to place S-O-S pattern within time limit and serve 3 difficulties as Easy, Normal, and Hard.

      Goals of the game is to put S-O-S words in patterns (Horizontal, Vertical, and Diagonal) alternately with enemy.
      Single Player Multiplayer Achievements Leaderboards  



      Link: Google Play
      Please help us improve this game with review
    • By abarnes
      I am a game development student in my second year of a three year program and I would like to start building my portfolio. I was thinking of creating some games to show what I can do to potential employers since I wont have any work related experience when I graduate. But as I'm sure you all know there are tons of ways to approach developing/designing a game and I'm curious if anyone had any insight as to any "standards" that come with this? Is it okay to use game engines like Unity, Unreal, Game Maker etc? Or would it be better to make a game from scratch to better show case your skills? Any and all advice will be greatly appreciated!
    • By Hilster
      Hello 2D Artists,
      I've started making a 2D Puzzle Adventure game for mobile and I'm looking for someone who would want in on creating assets for the game. The core of the programming is pretty much complete, you can walk within the grid laid out and push boxes, when there is an object on top of a pressure pad it will activate the linked objects or if there is one object with multiple linked pressure pads it requires you to activate all points for the object to become active. 

      The level iteration for the game is quick and simple, a Photoshop file that is made of individual pixels that represents objects is put into the game and it creates the level out of those pixels with the assigned objects.
      The objects that need sprites created so far is the character, box, pressure pad, door, trap door, the walls, the stairs and the tiled background.
      I intend to add more objects so the amount I'd like to add will be extended.
      My motivations for posting here is to have something that looks nice to be able to display on my portfolio, so if you're looking for a working game that you can place your art into and improve the look of your portfolio then we're in business.
      Please reply with a few past examples of your art below and I'll be in touch!
    • By thefollower
      I have set up my TcpClient to connect to my server and that works fine. But i am a bit confused how i read messages from the network stream with it continuously running via async, without ever closing the connection ?
      My TcpClient Manager class has:
      public async Task<bool> Connect(string address, int port) { try { await _tcpClient.ConnectAsync(address, port); IsConnected = true; return true; } catch(Exception e) { Debug.Log(e); return false; } } public async Task<int> Read(byte[] readBuffer) { if (!IsConnected) return -1; using (var networkStream = _tcpClient.GetStream()) { try { var bytesRead = await networkStream.ReadAsync(readBuffer, 0, readBuffer.Length); return bytesRead; } catch (Exception e) { Debug.Log(e); IsConnected = false; return -1; } } }  
      So i thought to just run a co-routine and call Read constantly to get the most recent message, but that doesn't make much sense to me since a co-routine would be blocked with the await. How is this actually done? The MS Docs don't have very good Async examples with the TcpClient class so i don't know fully get how to keep calling Read correctly.
  • Popular Now