Author Topic: imagecoll  (Read 1656 times)

Osgeld

  • Guest
imagecoll
« on: April 27, 2013, 07:36:37 pm »
how do you use it, I get image one and two but what do the xy cords do

Thanks

Cybermonkey

  • Administrator
  • *****
  • Posts: 0
Re: imagecoll
« Reply #1 on: April 27, 2013, 07:44:51 pm »
They are the x and y coordiantes of the images. See the example collisiontests.lua in the examples download.
Code: [Select]
  if imagecoll (rec2.image, rec2.x, rec2.y, rec1.image, rec1.x, rec1.y) then
drawtext (0,0,"Imagecoll detected")
end
Here is the complete example which shows the different collision types:
Code: [Select]
screen (800,600,0,"Collision Test")
rec1={}
rec2={}

rec1.image = createimage (128,32)
rec2.image = createimage (16,64)

startimagedraw (rec1.image)
  backcolor (255,0,0)
  cls()
stopimagedraw()

startimagedraw (rec2.image)
  backcolor (255,255,0)
  cls()
stopimagedraw()

rec1.x=450
rec1.y=300

backcolor (0,0,0)
grabmouse()

repeat
  cls()
  key=getkey()
  rec2.x = mousex()
  rec2.y = mousey()
  putimage (rec1.x,rec1.y,rec1.image)
  alphachannel (200)
  putimage (rec2.x,rec2.y,rec2.image)
  alphachannel (255)
  if imagecoll (rec2.image, rec2.x, rec2.y, rec1.image, rec1.x, rec1.y) then
drawtext (0,0,"Imagecoll detected")
end

  if boxcoll (rec2.x,rec2.y,imagewidth (rec2.image), imageheight (rec2.image), rec1.x, rec1.y, imagewidth (rec1.image), imageheight (rec1.image)) then
        drawtext (0,10,"Boxcoll detected")
end

  if pixelcoll (rec2.image, rec2.x, rec2.y, rec1.image, rec1.x, rec1.y, 2) then
drawtext (0,20,"Pixelcoll detected")
end

side = sidecoll (rec2.x,rec2.y,imagewidth (rec2.image),imageheight (rec2.image),1,0,rec1.x,rec1.y,imagewidth (rec1.image),imageheight (rec1.image))
        if side ~= "none" then
        drawtext (0,30,side)
        end
        side = sidecoll (rec2.x,rec2.y,imagewidth (rec2.image),imageheight (rec2.image),0,1,rec1.x,rec1.y,imagewidth (rec1.image),imageheight (rec1.image))
        if side ~= "none" then
        drawtext (0,40,side)
        end
        side = sidecoll (rec2.x,rec2.y,imagewidth (rec2.image),imageheight (rec2.image),-1,0,rec1.x,rec1.y,imagewidth (rec1.image),imageheight (rec1.image))
        if side ~= "none" then
        drawtext (0,50,side)
        end
side = sidecoll (rec2.x,rec2.y,imagewidth (rec2.image),imageheight (rec2.image),0,-1,rec1.x,rec1.y,imagewidth (rec1.image),imageheight (rec1.image))
        if side ~= "none" then
        drawtext (0,60,side)
        end


  sync()
until key==27
closewindow()

Osgeld

  • Guest
Re: imagecoll
« Reply #2 on: April 27, 2013, 07:49:09 pm »
thank you very much!