Error View does not implement interface member

I'm making a game of bat and ball. I have a problem in implementing the View and I do not know why. Can you help me please?

Error:

Activity2.cs

using Android.App;
using Android.OS;
using Android.Views;

namespace Proyecto_v1
{
    [Activity (Label = "Activity2", MainLauncher = true)]           
    public class Activity2 : Activity
    {
        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);
            SetContentView(new JuegoView(this));

        }
    }
}

JuegoView.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;

//Graphic
using Android.Graphics;
using Android.Graphics.Drawables;
using Android.Graphics.Drawables.Shapes;

//Timer
using System.Timers;

//On drag

namespace Proyecto_v1
{
    public class JuegoView : View, View.IOnTouchListener
    {
        //DECLARAR VARIABLES

        private Paint paint=null; //Paint - Herramienta para dibujar
        private Canvas canvas;
        private ShapeDrawable _pala=null,_pelota=null;


        //Raqueta 
        private Rect dst;
        private float wr, hr, xr, yr;
        private int deltaX, deltaY;

        //Pelota
        private Bitmap pelota_bmp; //imagenes Bitmap
        private float stepX=3, stepY=6; //avance de la pelota
        private float sentidoX=-1, sentidoY=-1; //sentido pelota
        private float xPelota, yPelota;

        //Vidas,Puntos
        private bool game_over=false;
        private int vidas=3;
        private String txt_vidas="X X X ";
        private int puntos=0;
        private int nivel=1;

        //Window size
        private int wScreen,hScreen;

        //Movimiento onDrag
        private bool tocar_raqueta = false;
        private Color color_pulsador = Color.Gray;
        private int _X,_Y;

        //Timer
        private Timer t1;

        private View gview;

        public JuegoView (Context context) : base (context)
        {
            paint = new Paint();

            timer();

            //Referencias
            pelota_bmp = BitmapFactory.DecodeResource (Resources, Resource.Drawable.pelota);

            this.gview=this;
            gview.SetOnTouchListener(this); //para el onDrag

            Initialize ();
        }

        public bool onTouch(View v, MotionEvent ev) {
            // TODO Auto-generated method stub

            _X = (int)ev.RawX;
            _Y = (int)ev.RawY;

            switch (ev.Action & MotionEventActions.Mask) {
            //Al tocar la pantalla
            case MotionEventActions.Down:

                //Detectar Raqueta Y (xr = centro de la raqueta, por eso -wr/2 y +wr/2)
                if(
                    (_Y  >= yr )
                    &&

                    (_X  >= xr-wr/2)
                    &&
                    (_X  <= xr+wr/2)
                ) 
                {
                    tocar_raqueta = true;
                    color_pulsador= Color.DarkGray;
                }else tocar_raqueta=false;

                break;

            case MotionEventActions.Up:
                //Al levantar el dedo simplemento mostramos un mensaje
                //Toast.makeText(this, "Soltamos", Toast.LENGTH_LONG).show();
                color_pulsador= Color.Gray;
                break;

            case  MotionEventActions.PointerDown:
                //No hace falta utilizarlo
                break;

            case  MotionEventActions.PointerUp:
                //No hace falta utilizarlo
                break;

            case  MotionEventActions.Move:
                if(tocar_raqueta)xr = _X;
                break;
            }


            //Evitar traspasar laterales raqueta 
            if(xr-wr/2 <= 0) xr = 0 + wr/2 + 5;
            if(xr+wr/2 > wScreen) xr = wScreen-wr/2 - 5;

            //Si tocamos la pantalla cuando te quitaron una vida, continuará el juego
            if(vidas >= 0 && t1.Enabled)
            {
                t1.Start();
                sentidoY =-1;
                sentidoX =-1;

                if(game_over) {
                    game_over=false;
                    vidas=3;
                    txt_vidas="X X X ";
                    puntos=0;
                    nivel=1;

                    stepX=3;
                    stepY=6;
                }

            }

            this.Invalidate();
            return true;
        }




        void Initialize ()
        {

            var metrics = Resources.DisplayMetrics;
            var _wScreen = metrics.WidthPixels;
            var _hScreen = metrics.HeightPixels;

            //Asignar resolucion del window a las variables
            wScreen = _wScreen;
            hScreen = _hScreen;

            //PELOTA en el centro del canvas
                xPelota=wScreen/2; 
                yPelota=hScreen/2; 


            //RAQUETA
                //Tamaño raqueta
                wr=wScreen/3; //width raqueta = width canvas/4 (60px)
                hr=hScreen/20; //height raqueta = height canvas/35

                //Posicion raqueta inicial
                xr=wScreen/2;
                yr=hScreen- hScreen/15;

                deltaX=(int)(xr-wr/2);  //x de la raqueta
                deltaY=(int)(yr-hr/2); //y de la raqueta
                //dst= new Rect(deltaX,deltaY,(int)wr+deltaX,(int)hr+deltaY);

                dst= new Rect(deltaX,deltaY,(int)wr+deltaX,(int)hr+deltaY);
        }


        protected override void OnDraw(Canvas canvas)
        {
            this.canvas = canvas;
            paint.Color = Color.Blue;

            //canvas.DrawText("X: " + xPelota.ToString(), 10,10, paint);
            //canvas.DrawText("Y: " + yPelota.ToString(), 10,30, paint);

            dibujar();


            paint.Color = Color.White;

            paint.TextSize = 25;
            canvas.DrawText(txt_vidas, wScreen-65,28, paint);

            paint.TextSize = 16;
            canvas.DrawText("Nivel: " + nivel, wScreen/35,25, paint);
            canvas.DrawText("Puntos: " + puntos, wScreen/35,45, paint);

            //MENSAJE GAME OVER 
            if(vidas <= 0)
            {
                game_over=true;
                paint.TextSize = 40;
                canvas.DrawText("GAME OVER", wScreen/2-(113),hScreen/2-(50), paint);
            }

            this.Invalidate ();
        }

        public void dibujar(){
            float left, top;

            xPelota  = xPelota + (int)stepX * sentidoX; //Direccion X
            yPelota  = yPelota + (int)stepY * sentidoY; //Direccion Y

            //Horizontal
            if(xPelota >= wScreen- pelota_bmp.Width / 2  ) {sentidoX=-1;}
            if(xPelota <= 0 + pelota_bmp.Height / 2   ) {sentidoX= 1;}

            //Vertical
            if(yPelota < pelota_bmp.Height / 2 ) {sentidoY = 1;}
            if (yPelota > hScreen + pelota_bmp.Height + 30)
            {
                sentidoY=0;
                sentidoX=0;

                txt_vidas = txt_vidas.Substring(0, txt_vidas.Length-2);
                vidas--;

                //Aparece la pelota en el centro del canvas
                xPelota=wScreen/2; 
                yPelota=hScreen/2; 

                //Posicion raqueta inicial
                xr=wScreen/2;
                yr=hScreen - hScreen/5;

                t1.Stop ();

            }

            //Detectar Raqueta Y (xr = centro de la raqueta, por eso -wr/2 y +wr/2)
            if(
                (yPelota  >= yr-pelota_bmp.Height/2 )
                &&
                (yPelota  <= yr+hr/2) 
                &&
                (xPelota  >= xr-wr/2 - pelota_bmp.Width/3)
                &&
                (xPelota  <= xr+wr/2 + pelota_bmp.Width/3)
            ) 
            {
                sentidoY=-1; 
                //rebote_r.start(); //suena sonido

                //PUNTOS DEL JUEGO
                puntos += 20;
                if(puntos % 100 == 0 && nivel <= 10)
                {
                    nivel++;

                    if(nivel % 2 == 0)
                    {
                        //avance de la pelota
                        stepX ++;
                        stepY ++; 
                    }
                }
            }

            //Dibujar raqueta
            canvas.DrawRect (dst, paint);

            //Dibujar imagen de la pelota (/2 para que sea el centro)
            left = xPelota - pelota_bmp.Width / 2;
            top = yPelota-pelota_bmp.Height / 2;
            canvas.DrawBitmap(pelota_bmp, left, top, null);

            //Dibujar cuadrado pulsador
            paint.Color = color_pulsador;
            canvas.DrawRect(deltaX, (int)hr+deltaY+8, (int)wr+deltaX, hScreen-5, paint);
            //canvas.drawRect(deltaX, (int)hr+deltaY+8, (int)wr+deltaX, he-5, paint);

        }


        //TIMER -----------------------------------------------------------------------------------------
        void timer()
        {
            t1 = new System.Timers.Timer(5000);
            t1.Elapsed += new ElapsedEventHandler(OnTimeEvent);
            t1.Interval = 30;
            t1.Enabled = true;
            t1.Start();
        }

        private void OnTimeEvent(object source, ElapsedEventArgs e)
        {
            //Lo que quieres que haga el timer
        }
    }
}

Posts

  • SebastianSeidel.9226SebastianSeidel.9226 DEInsider, University ✭✭✭✭

    Rename public bool onTouch(View v, MotionEvent ev) to public bool OnTouch(View v, MotionEvent ev)

Sign In or Register to comment.