How to swap the position of two sprites?

| | August 18, 2015

I’m making a game like Candy Crush with Cocos2D in Android. I’ve made the sprites but I want to swap to sprites by touch .

How to swap the position of two sprites?

One Response to “How to swap the position of two sprites?”

  1. To do this, all that you need to write is something like this, a simple swap function:

    class Point
    {
    
    private int x, y;
    
    procedure swapPositions(Point a)
    {
       Point temp = a;
    
       a.x = x;
       x = temp.x;
    
       a.y = y;
       y = temp.y;
    }
    
    }
    

    Note: this is pseudo-code and it will not work if you try to use it. You must write your own, with this concept, and fit it into your current game’s build.

Leave a Reply