I am developing an android game on Eclipse in which a sprite is jumping on several platforms to get to the top but I am having difficulties. Here is my case: I have the character sprite (I'll name this as Sprite1 in this case) that moves and I am creating another 3 sprites(the platforms) at random positions when my app starts. The platforms are successfully created when the app starts. But the collision between them and Sprite1 is not detected. I tried many solutions and I am stuck for a couple of days now. Any help or suggestion will be appreciated.
I tried making rects when the platforms are created then using the rects to detecting collisions but they still don't collide. I use Java language. :)
I use this to create the sprites and detect collisions:
Creating platform sprites (this is how i randomly spawn platforms, if there are mistakes here, i'm sure i just copied wrong because the creating or platform sprites works correctly.):
public void addRandomPlatform(){
Random rand = new Random();
randPlat = CCSprite.sprite("platform2.png");
randPlat.setPosition(actualX, actualY);
actualY -= (int)(randPlat.getContentSize().height*4);
addChild(randPlat,2);
}
Then I just call this method when my app starts.
Detecting Collision:
playerRect = CGRect.make(player.getPosition().x - (player.getContentSize().width / 4.0f),//- (player.getContentSize().width / 2.0f),
player.getPosition().y - (player.getContentSize().height / 2.0f),
player.getContentSize().width/3.0f,
player.getContentSize().height/8.0f);
if(CGRect.intersects(playerRect, randPlat))
{
*my codes for stopping the jump*
}
I hope this is clear. Thanks in advance!