venerdì 9 maggio 2014

Muovere e rilevare la collisione degli oggetti

Se volete creare dei giochi o dei controlli sofisticati dovete potere trascinare degli oggetti e verificare se toccano altri oggetti.
Per poter trascinare un oggetto basta mettere "grab me" nel codice di un oggetto:


on mouseDown
   grab me
end mouseDown

Per poi poter rilevare le collisioni basta usare la funzione  intersect(), ecco tutto il codice dell'esempio nel video:

on mouseDown
   grab me
end mouseDown

On Mousemove
   if intersect(image image1,image image2) then
      set the text of field field1 to "SI INTERSECANO"
      set the backgroundcolor of field field1 to 255,0,0
   else
      set the text of field field1 to "NON SI INTERSECANO"
      set the backgroundcolor of field field1 to 0,255,0
   end if   
end Mousemove


Nessun commento:

Posta un commento