Hi,
I'm building a game which requires pixel perfect sprite collision so I bought the eXtends plugin which comes with commands to deal with this. However so far, I've been unable to achieve anything other than normal area sprite collision results.
I started trying to use png files with their own transparency but from the advise other similar threads of this forum, I've reverted to using bmp files with the transparency achieved through the set image colorkey command. None of the sprites being checked for collision have been rotated and the origin is set to 0,0.
Below is the code in my main loop which is supposed to deal with this. The first loop updates the logical position of each sprite in turn. The next loop updates the actual position of each sprite and then prepares of for collision checking. The third loop goes through all the sprites and checks whether they collide with any relevant sprites. If they do, the sprite is destroyed. All the words in capitals are constants.
` Move objects
play sprite gnSpriteNos(PORT3,SPRITENO),1,2,500
for c = 1 to array count(Objects(0))
if TimeSince(nLastStep) > 39
nLastStep = timer()
Objects(c).nX = Objects(c).nX + gVectors(Objects(c).nVectorNo).fX
Objects(c).nY = Objects(c).nY + gVectors(Objects(c).nVectorNo).fY
endif
next c
` Collision handling
dim nOldVals(array count(Objects(0)),1) as integer
for c = 1 to array count(Objects(0))
nOldVals(c,0) = sprite x(Objects(c).nSpriteNo)
nOldVals(c,1) = sprite y(Objects(c).nSpriteNo)
sprite Objects(c).nSpriteNo,Objects(c).nX,Objects(c).nY,Objects(c).nImageNo
spr prepare collision Objects(c).nSpriteNo
next c
for c = 1 to array count(Objects(0))
if spr get collision(Objects(c).nSpriteNo,gnSpriteNos(ISLAND,SPRITENO),0) = 1 or spr get collision(Objects(c).nSpriteNo,gnSpriteNos(ROCK1,SPRITENO),0) = 1 or spr get collision(Objects(c).nSpriteNo,gnSpriteNos(ROCK2,SPRITENO),0) = 1 or spr get collision(Objects(c).nSpriteNo,gnSpriteNos(ROCK3,SPRITENO),0) = 1
if Objects(c).nType = WATERMINE or Objects(c).nType = RAMMINGSUB or Objects(c).nType = TORPEDOSUB or Objects(c).nType = RAMMINGBATTLESHIP or Objects(c).nType = FIRINGBATTLESHIP or Objects(c).nType = AIRCRAFTCARIER or Objects(c).nType = TRANSPORTSHIP
RemoveObject(c)
endif
endif
next c
The result of this code is that a collision is detected as soon as the two box perimeters of the sprites come into contact rather than when visible pixels overlap. Any help on how I can change this to achieve pixel perfect sprite collision would be greatly appreciated.
Obviously, if there is any further information you need, don't hesitate to ask and I will post it here. Thanks in advance.