Code archives/Algorithms/CollideImage2
This code has been declared by its author to be Public Domain code.
Download source code
| |||||
This function just use CollideImage, but returns an array *without* the object we are testing. This allows collision between images of the same layer (which is not possible with CollideImage). Use it like this: CollideImage2(x,y,frame,0,playerLayer,player) (collideImage would work as well) Then, later on, to check collisions: if collideImage2(x, y, frame, playerLayer, 0, null, self) then blah (where self is the image you are currently testing) | |||||
' Function checking the collision, but will remove the testedObject from the list of collision. This allows ' collision for objects of the same layer. Function CollideImage2:Object[](image:TImage, x, y, frame, collideMask%, writeMask%, id:Object, testedObject:Object=Null) Local collidedObjects:Object[] = CollideImage(image, x, y, frame, collideMask, writeMask, id) ' Test if the object is present in the collision list Local testedObjectPresent:Byte = False For Local collidedObject:Object = EachIn collidedObjects If collidedObject = testedObject Then testedObjectPresent = True Next ' Create the new array we will return Local dim If testedObjectPresent Then dim = collidedObjects.length - 1 Else dim = collidedObjects.length Local collidedObjectsReturned:Object[dim] ' Remove the object from the collision list if it's present Local i = 0 For Local collidedObject:Object = EachIn collidedObjects If collidedObject <> testedObject Then collidedObjectsReturned[i] = collidedObject i:+1 EndIf Next Return collidedObjectsReturned End Function |
Comments
None.
Code Archives Forum