suffering from slow col detection.

BlitzMax Forums/BlitzMax Programming/suffering from slow col detection.

Paul "Taiphoz"(Posted 2011) [#1]
currently my level is using a 800*600 image which is an alpha - black mask of the collision area, I then only need to check a hand full of ships against it.

The second I spawn 1 ship its ok, spawn 2 and its slow, and then exponentially slower after that, I have used large images for detection in the past without results as bad as this.

Using ImagesCollide2() between a small ship and the mask.

trying to think of another way of doing this, I had hoped that my game levels would be as simple as creating 1 image and then making it the collision image, but it looks like I might have to really split it up into lots of smaller sprites.

:(


skidracer(Posted 2011) [#2]
Just make sure you are not in Debug mode b4 doing anything rash.


xcessive(Posted 2011) [#3]
Split it up into small images then use a quadtree -- you'll be able to get 100s of ships that way.


H&K(Posted 2011) [#4]
You have messed it up in some way.
(On a "doh" level DONT have any scale or rotation (0,1,1) on the "screen" TImage input, if you need any then calculate it relatively and add it to each ship each collide query)
(Edit doh 2, make sure you aren't regrabing the TImage each check)

Last edited 2011


Paul "Taiphoz"(Posted 2011) [#5]
tracked it down.

	Method MovePlayer()
		
		For Local loop:Float = .4 To Self.speed Step .4

		
			If Self.life>0
				Self.VelX = Cos(Self.FAngle) * .4'Self.Speed
				Self.VelY = Sin(Self.FAngle) * .4'Self.Speed
				
				Self.PosX:+ Self.VelX
				Self.PosY:+ Self.VelY	
			End If
						
			'check for collisions.
			If ImagesCollide2(MaskSpaceStation , StationNode.PosX , StationNode.PosY , 0,StationNode.Angle,StationNode.scale,StationNode.scale , Self.Sprite , Self.PosX , Self.PosY , 0 , Self.FAngle,Self.scale,Self.scale) = 1
				Self.life = 0	
			End If
						
			If Self.life=0 Then Exit
			
		Next
		
		'REMOVED THIS FROM THE ABOVE LOOP
		'it dont need to be that accurate..

		If ImagesCollide2(levelmask,400,300,0,0,1,1,Self.Sprite , Self.PosX , Self.PosY , 0 , Self.FAngle,Self.scale,Self.scale) = 1
			Self.life = 0	
		End If
		
		
	End Method


it's still a little slower than I'd expect but I suspect that's just because the image is large, creating smaller chunks from it should help, just need to think of thr best of going about that.


Paul "Taiphoz"(Posted 2011) [#6]
Oh the LevelMask Image is 800*600 but it could be a lot larger as I plan some levels to be larger than the screen...

I could load the image as an animation strip, then when rendering them all out in the right place I just need to check if the image has any colour pixels, if so draw it, if not ignore it. could work.