これが重複していて、私のgoogle-fuが弱い場合はお詫びします。
コードのメソッドルーティングには2つのオプションがあります。
一連のオブジェクト属性を呼び出すローカルメソッドを使用します。
/* public class Manager */
public void onTouchEvent( Event event )
{
Vec2 touch = new Vec2( event.getX(), event.getY() );
for( GameObject o : mGameObjectList )
{
if ( isColliding( touch, o ) )
o.onTouchEvent(event);
}
}
public boolean isColliding( Vec2 touch, GameObject obj )
{
if ( ( obj.mPosition[ 0 ] - obj.mScale[ 0 ] ) < touch.x && touch.x < ( obj.mPosition[ 0 ] + obj.mScale[ 0 ] ) )
{
if ( ( obj.mPosition[ 1 ] - obj.mScale[ 1 ] ) < touch.y && touch.y < ( obj.mPosition[ 1 ] + obj.mScale[ 1 ] ) )
{
return true;
}
}
return false;
}
次にローカル属性を使用するオブジェクトメソッドを呼び出します。
/* public class Manager */
public void onTouchEvent( Event event )
{
for( GameObject o : mGameObjectList )
{
o.isColliding(event);
}
}
/* public class GameObject */
public boolean isColliding( Event event )
{
// code here to get touch from event ( or maybe pass in touch? )
if ( ( mPosition[ 0 ] - mScale[ 0 ] ) < touch.x && touch.x < mPosition[ 0 ] + ( mScale[ 0 ] ) )
{
if ( ( mPosition[ 1 ] - mScale[ 1 ] ) < touch.y && touch.y < mPosition[ 1 ] + ( mScale[ 1 ] ) )
{
onTouchEvent(event)
}
}
return false;
}
プログラム的に優れている方法のセットはどれですか(最適、エレガント、シンプルなど)?
更新:コードセクションを修正しました。申し訳ありません。