Partial Sprite Collision

Previous topic - Next topic

bigtunacan

I'm trying to do sprite collision where the collision only occurs against a part of the sprite.

When I was doing straight up sprite to sprite collision everything was running smooth and fast, not it is running like a slow 3 legged dog.

I conditionally check if the one item begins at a lower position than the other or if it is possible they began in overlapping positions.  If they didn't start overlapping I use a prebuilt collision sprite; this is quite fast.  If they already overlap I build a disposable collision sprite that takes the y position into account for the collision sprite.  This is unacceptably slow once I move it over to the iPhone; the game practically freezes every time it hits this area. 

Any ideas on how I could this with better performance?

Code (glbasic) Select

IF lanes[i].cars[j].ent.locy < bullet.ymin%
    min_y%=(lanes[i].cars[j].ent.locy + lanes[i].cars[j].ent.height) - bullet.ymin%
    car_coll = init_disposable_collider(lanes[i].cars[j].ent.locx+10, bullet.ymin%,lanes[i].cars[j].ent.width-20, min_y%)
ELSE
    car_coll = get_collider(lanes[i].cars[j].ent.name$)
ENDIF



Code (glbasic) Select

FUNCTION init_disposable_collider AS COLLIDER: x, y, width%, height%, x_off=0, y_off=0
LOCAL txt_spr AS SPRITE
txt_spr = get_named_sprite("clouds")

CREATESCREEN 0, 5, width%, height% // TODO : 5 is the sprite ID this needs to be replaced with something else

USESCREEN 0
STARTPOLY 0,0 // Bitmap = No.0
  POLYVECTOR  0,    0,  txt_spr.tx1,  txt_spr.ty1, RGB(255, 0, 0)
  POLYVECTOR  0, height, txt_spr.tx1, txt_spr.ty2, RGB (255, 0, 0)
  POLYVECTOR  width, height, txt_spr.tx2, txt_spr.ty2, RGB(255, 0, 0)
  POLYVECTOR  width, 0, txt_spr.tx2, txt_spr.ty1, RGB(255, 0, 0)
ENDPOLY
USESCREEN -1



LOCAL _col AS COLLIDER
_col.x=x
_col.y=y
_col.sprite_id% = 5
_col.x_off = x_off
_col.y_off = y_off
RETURN _col
ENDFUNCTION

Falstaff

I'm assuming that it's your use of CREATESCREEN specifically that is slowing things down.

Maybe try moving it outside the function, like just call it once to initialize the sprite, then you can still use the USESCREEN commands you've got like they are.