2016-11-30 38 views
2

私はあなたの指の後ろに目を向けてアプリケーションを作ろうとしています。 しかし、私のアプリケーションを読み込むと、図面が表示されません。 紫色の背景がうまくロードされますが、そこでは停止しているようです。 これはなぜ起こっているのですか?C#描画が描画されない

using Android.App; 
using Android.Widget; 
using Android.OS; 
using Android.Graphics; 
using Android.Views; 
using Android.Content; 
using Android.Content.PM; 
using System; 


namespace BewegendeOgen 
{ 
[Activity(Label = "BewegendeOgen", MainLauncher = true, Icon = "@drawable/icon", ScreenOrientation = ScreenOrientation.Landscape)] 
public class MainActivity : Activity 
{ 
    OgenView ogen; 


    protected override void OnCreate(Bundle bundle) 
    { 
     base.OnCreate(bundle); 
     ogen = new OgenView(this); 


     this.SetContentView(ogen); 
    } 
} 

public class OgenView : View 

{ 
    public OgenView(Context c) : base(c) 
    { this.Touch += RaakAan; 
     this.SetBackgroundColor(Color.Purple); 

    } 

    PointF punt; 
    public void RaakAan(object o, TouchEventArgs tea) 
    { 
    float xas = tea.Event.GetX(); 
    float yas = tea.Event.GetY(); 
     this.punt = new PointF(xas, yas); 
     this.Invalidate(); 

     this.Invalidate(); 
    } 


protected override void OnDraw(Canvas canvas) 
    { 
     base.OnDraw(canvas); 

     this.tekenoog(canvas, 200); 
     this.tekenoog(canvas, -200); 


    } 

    public void tekenoog(Canvas canvas, int a) 
    { //this is the drawing 
     base.OnDraw(canvas); 
     float radius, x1, x2, y; 
     radius = 200; 
     x1 = this.Width/3; 
     y = this.Height/2; 
     x2 = x1 * 2; 

     Paint verf; 
     verf = new Paint(); 

     verf.Color = Color.White; 
     canvas.DrawCircle(x1 + a, y, radius, verf); 


     float dx, g, e, f, d, ex, ey, radiusiris, irisx1, irisy1; 
     dx = punt.X - x1; 
     g = punt.Y - y; 
     radiusiris = 20; 
     e = radius - radiusiris; 
     f = (float)Math.Sqrt(dx * dx + g * g); 
     d = f - e; 
     ex = dx * e/d; 
     ey = (float)Math.Sqrt(e * e - ex * ex); 
     irisx1 = x1 + ex; 
     irisy1 = y - ey; 

     verf.Color = Color.CornflowerBlue; 
     canvas.DrawCircle(irisx1, irisy1, radiusiris, verf); 
    } 
} 
} 
+0

これはxamarinを使用していますか?もしそうなら、それを反映するために質問とタグを更新してください。 – pulekies

答えて

0

それは最初tekenoogでそれにアクセスしようとしたとき、それは例外をスローしていますので、あなたは、puntを初期化することはありません。

私は私のマシン上でこれを試してみました私はpunt宣言を修正した後、それが働いた:

private PointF punt = new PointF(); 

・ホープ、このことができます!

enter image description here

関連する問題