aeCollision question...?

Create fast, sprite powered games with Animation Engine, co-developed with DerBrill Software!

Moderators: heatherlaine, kevinmiller, robinmiller, malte

Post Reply
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 45
Joined: Tue May 06, 2008 11:24 pm

aeCollision question...?

Post by jpatten » Tue Jun 12, 2012 5:21 am


I'm having trouble having aeCollision recognize a collision between to objects. In an attempt to use newer AE calls for moving objects, I seem to have hit a roadblock regarding initiating an aeCollision call.

Here's what I have:

Code: Select all

global newShot

on keyDown theKey
   if theKey = space then
      end if
end keyDown

on createShot
   lock screen
   lock messages
   clone btn "bulletTemplate" 
   put the id of it into newShot
   put the BulletList of current card into tBulletList
   put newShot & cr after tBulletList
   if line 1 of tBulletList is empty then delete line 1 of tBulletList
   set the Bulletlist of this card to tBulletList
   set the name of btn id newshot to "bullet"
   set the layer of btn id newshot to 1
   set the loc of btn id newShot to the loc of grc "shooter"
   put the long ID of btn id newShot into tLongID
   put cd fld "theAngle" into tBulletAngle
   get pointOnCircle(loc of last btn, tBulletAngle,1200)
   put it into tTargetEnd
   if  there is a btn id newShot then
      aeMoveto tLongID,tTargetEnd,1000
     send aeStartListeningForCollisions to btn id newShot in 1 sec
      send DeleteBullet to btn id newShot in 2 seconds
   end if
    end createShot

on DeleteBullet newShot
 put the bulletList of current card into tBullets
   put the ID of target into tTargetBullet
      if there is a btn id tTargetBullet then
     if the left of btn id tTargetBullet > the right of this card or the right of button id tTargetBullet < 0 or the bottom of button id tTargetBullet < 0 or the top of button id tTargetBullet > the bottom of this card then
             put the long id of btn id tTargetBullet into tLongIDofButton
            delete line 1 of tBullets
            delete button id tTargetBullet
         end if
      end if
set the bulletlist of current card to tBullets
end DeleteBullet

on CheckMe
   repeat for each line theEnemy in the allEnemies of this cd
      send movePolygonal to img ID theEnemy
   end repeat
   wait 0 with messages
   unlock screen
   if the flag of btn "startGame" then send checkme to me in 30 milliseconds
end CheckMe

command GetTargets
    repeat with i = 2 to the number of images
         put the long id of image i & cr after tList
      end repeat
      delete char -1 of tList
      set the aeListenForCollisionsWith of button  id newShot to tList
end GetTargets

on aeCollision pObjects
   if the visible of pObjects is true then
      put pObjects -- let me know the object was hit
      pass aeCollision
      pass aeCollision
      end if
   end aeCollision
The tList seems to be correct when I check it, but when a collision takes place between the bullet button and one of the enemy images, the collision does not register. Any suggestions?

Thank you!
(19.84 KiB) Downloaded 268 times

Posts: 1098
Joined: Thu Feb 23, 2006 8:34 pm
Location: Ostenfeld germany

Re: aeCollision question...?

Post by malte » Tue Jun 12, 2012 12:36 pm

Hi John,

sorry I am not as responsive as I should be atm. Am pretty deep into a consulting project pretty far away from home.

The problem appears to be, that you start listening for collisions after a second (this is when your bullet already is moved off screen :-) )

I will try to look a little more in depth tonight, but that is my first vague guess.

All the best,


Livecode Opensource Backer
Livecode Opensource Backer

Re: aeCollision question...?

Post by jpattenGA2lcj » Thu Jun 14, 2012 6:18 pm

Hi Malte...

No problem. I did change listening from 1 second to 10 milliseconds, but that did not make a difference.

Thank you!

Post Reply

Return to “Animation Engine”