Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm creating a RPG game, I need to create a monster respawn area like the Pokemon games where if I walk through the long grass areas a Pokemon can appear. I already created the battle scene, I've seen examples of tile collision with solid objects but I don't know how create a collision action with passable objects.

share|improve this question

2 Answers 2

I suppose you could call it a collision, but it's more like an intersection. You can create a trigger zone that activates when the player enters it. A simple way of doing that would just create a list of these zones, then check to see if the player is inside them every frame or when the player moves. A zone is just two points, a min and a max. Then you can check when something is inside like so:

public boolean contains(float x, float z) {
    return (x >= minX && x < maxX &&
        z >= minZ && z < maxZ);
}
share|improve this answer
    
actually i'm populating the tiles of map that have the property("monsterRespawn","true") with rectangle objects, my idea is when the character step over the tile where any of this objects exist, trigger a random action of can be attacked or not, but i'dont know if is good idea and how call a certain action when the player is over the tile –  dakairus Jul 20 '12 at 18:28

Finally i got how create the respawn zone, i create 2 arrays of tmxmap objects and extract is properties in the example i create wall(unwalkable zone) and isMonsterRespawn zone, where if the player collide with that zone certain action happens, in my example case the respawn zone change the color tile. There i can set an action that cant send my character to the battle scene with a randomly chance:

private void createUnwalkableObjects(TMXTiledMap map,final AnimatedSprite pl) {

 for(final TMXObjectGroup group: this.mTMXTiledMap.getTMXObjectGroups()) {

   if(group.getTMXObjectGroupProperties().containsTMXProperty("wall", "true")){
             // This is our "wall" layer. Create the boxes from it
   for(final TMXObject object : group.getTMXObjects()) {

                final Rectangle rect = new Rectangle(object.getX(), object.getY(),object.getWidth(), object.getHeight());
                rect.setVisible(false);
                final FixtureDef boxFixtureDef = PhysicsFactory.createFixtureDef(0, 0, 1f);
                PhysicsFactory.createBoxBody(this.mPhysicsWorld, rect, BodyType.StaticBody, boxFixtureDef);
                mScene.attachChild(rect);
             }
         }if(group.getTMXObjectGroupProperties().containsTMXProperty("IsMonsterSpawnArea", "true")){
             // This is our "wall" layer. Create the boxes from it
             for(final TMXObject object : group.getTMXObjects()) {
                final Rectangle rect = new Rectangle(object.getX(), object.getY(),object.getWidth(), object.getHeight());
    rect.setVisible(true);
    mScene.attachChild(rect);
    mScene.registerUpdateHandler(new IUpdateHandler() {
                    @Override
                    public void reset() {

}

                    @Override
                    public void onUpdate(final float pSecondsElapsed) {
                        if(pl.collidesWith(rect)){
//here the action when the player collides the zone
                            rect.setColor(1, 0, 1);}else{
                                rect.setColor(1, 0, 0);
                            }   
                        }

                });

             }
         }
     }

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.