2016-06-29 7 views
0

私は現在プロジェクトを進めていますが、画像を拡大縮小しようとしています。 次のコードでヒットボックスが決定しました。0より小さいVector2で画像を拡大する

public Rectangle bound 
    { 
     get 
     { 
      return new Rectangle((int)position.X, (int)position.Y, 
       texture.Width * (int)scale.X, 
       texture.Height * (int)scale.Y); 
     } 
    } 

これは、スケールが1つ以上であることを前提としています。しかし、1つよりも小さいスケール値を入力すると、衝突は機能せず、Console.WriteLine()関数は{X:300 Y:300幅:0高さ:0}を返します。 私が間違っていることはありますか?

+1

'int'へのキャストは切り詰めるので、' 0.9 'は '0'になります。代わりに*を乗算してみてください。 '(int)(texture.Width * scale.X)' – Blorgbeard

+0

あなたのコメントを見た直前にそれを見ました。ありがとう。 –

答えて

1

まあ、私は愚かな気がしません。

public Rectangle bound 
    { 
     get 
     { 
      return texture == null ? new Rectangle(0,0,0,0) : new Rectangle((int)position.X, (int)position.Y, 
       (int)(texture.Width * scale.X), (int)(texture.Height * scale.Y)); 
     } 
    } 

矩形の寸法が浮動小数点の場合は、ゼロを返します。

関連する問題