Ooops
November 28, 2020, 01:50:03 PM

Author Topic: [bmx] CollideImage2 by RepeatUntil [ 1+ years ago ]  (Read 641 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] CollideImage2 by RepeatUntil [ 1+ years ago ]
« on: June 29, 2017, 12:28:38 AM »
Title : CollideImage2
Author : RepeatUntil
Posted : 1+ years ago

Description : 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)


Code :
Code: BlitzMax
  1. ' Function checking the collision, but will remove the testedObject from the list of collision. This allows
  2. ' collision for objects of the same layer.
  3. Function CollideImage2:Object[](image:TImage, x, y, frame, collideMask%, writeMask%,  id:Object, testedObject:Object=Null)
  4.         Local collidedObjects:Object[] = CollideImage(image, x, y, frame, collideMask, writeMask, id)
  5.         ' Test if the object is present in the collision list
  6.         Local testedObjectPresent:Byte = False
  7.         For Local collidedObject:Object = EachIn collidedObjects
  8.                 If collidedObject = testedObject Then testedObjectPresent = True
  9.         Next
  10.         ' Create the new array we will return
  11.         Local dim
  12.         If testedObjectPresent Then dim = collidedObjects.length - 1 Else dim = collidedObjects.length
  13.         Local collidedObjectsReturned:Object[dim]
  14.         ' Remove the object from the collision list if it's present
  15.         Local i = 0
  16.         For Local collidedObject:Object = EachIn collidedObjects
  17.                 If collidedObject <> testedObject Then
  18.                         collidedObjectsReturned[i] = collidedObject
  19.                         i:+1
  20.                 EndIf
  21.         Next
  22.         Return collidedObjectsReturned
  23. End Function


Comments : none...

 

SimplePortal 2.3.6 © 2008-2014, SimplePortal