Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
EASY - Sprite collision detection? - Gideros Forum

EASY - Sprite collision detection?

edited November 2012 in General questions
In Corona, we use physics.addBody to create physics properties from Sprite then listen for collision event.

Now with Gideros, I've tried to add box2D body to Sprite, all fine but unfortunately by doing this, the sprite movement doesn't work - it just drop (i read some tutorials but most of them use gravity on physic body) When I set gravity = 0, movement function is useless.

I found Simple Collision Detection for Sprite here http://www.giderosmobile.com/forum/discussion/121/simple-collision-detection but cannot apply because i don't know how to manually loop through a sprite group/collection and check for collision with item in other sprite group/collection

Sorry for my bad english, hope you guys can understand. This seem to be a basic knowledge but I would waste a lot of time discovering it without your help.

Thank so much :D
Tagged:

Comments

  • zaniarzaniar Member
    Accepted Answer
    If you add box2d body to a sprite, you can't move the sprite. Just move the body instead.

    For looping over a group of sprite, basicaly you need to save sprites in a table then loop over that table and call the collision function. Here is an illustrative code:
    sprites = {} -- assume that sprites table filled with sprites
     
    for i = 1, #sprites do
    	for j = 1, #sprites do
    		if sprites[i] ~= sprites[j] then
    			sprites[i]:collision(sprites[j])
    		end
    	end
    end
    I hope it helps ;-)
  • Got it, thank @zaniar.

    Btw, is it affect performance if we loop like this? Compare with using physics?
  • zaniarzaniar Member
    Accepted Answer
    I don't know about performance. But, considering that physics engine calculate more than just collision, a loop should be more efficient than a physics engine for just collision detection. CMIIW

    Here is a great alternative for collision detection without physics and an optimized one
    http://www.tntparticlesengine.com/?cat=15
Sign In or Register to comment.