Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Drawing;
- using MonoTouch.CoreFoundation;
- using MonoTouch.UIKit;
- using MonoTouch.Foundation;
- using MonoTouch.GLKit;
- using MonoTouch.OpenGLES;
- using OpenTK.Graphics.ES20;
- using OpenTK;
- namespace XamarinSpriteAnimation.ViewControllers
- {
- [Register("AnimationViewController")]
- public class AnimationViewController : GLKViewController
- {
- UIButton btnAnimation0;
- UIButton btnAnimation1;
- UIButton btnAnimation2;
- UIButton btnAnimation3;
- UIView buttonView;
- GLKView animationView;
- EAGLContext context;
- Sprite player;
- GLKBaseEffect effect;
- public AnimationViewController()
- {
- }
- public override void DidReceiveMemoryWarning()
- {
- // Releases the view if it doesn't have a superview.
- base.DidReceiveMemoryWarning();
- // Release any cached data, images, etc that aren't in use.
- }
- public override void ViewDidLoad()
- {
- base.ViewDidLoad();
- View = new UIView();
- View.Frame = new RectangleF(0, 0, UIScreen.MainScreen.Bounds.Width, UIScreen.MainScreen.Bounds.Height);
- #region Create GLKView
- context = new EAGLContext(EAGLRenderingAPI.OpenGLES2);
- if (context == null)
- Console.WriteLine("Failed to create ES context...");
- animationView = new GLKView(new RectangleF(UIScreen.MainScreen.Bounds.Width * 0.05f,
- UIScreen.MainScreen.Bounds.Height * 0.05f,
- UIScreen.MainScreen.Bounds.Width * 0.9f,
- UIScreen.MainScreen.Bounds.Height * 0.75f), context);
- EAGLContext.SetCurrentContext(context);
- animationView.DrawInRect += new EventHandler<GLKViewDrawEventArgs>(animationView_DrawInRect);
- View.AddSubview(animationView);
- #endregion
- #region Create Buttons & Button View
- buttonView = new UIView();
- buttonView.Frame = new RectangleF(UIScreen.MainScreen.Bounds.Width * 0.05f,
- UIScreen.MainScreen.Bounds.Height * 0.85f,
- UIScreen.MainScreen.Bounds.Width * 0.9f,
- UIScreen.MainScreen.Bounds.Height * 0.1f);
- btnAnimation0 = UIButton.FromType(UIButtonType.RoundedRect);
- btnAnimation0.Frame = new RectangleF(buttonView.Frame.Width * 0.0f,
- buttonView.Frame.Height * 0.0f,
- buttonView.Frame.Width * 0.25f,
- buttonView.Frame.Height * 1.0f);
- btnAnimation0.SetTitle("One", UIControlState.Normal);
- btnAnimation0.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin |
- UIViewAutoresizing.FlexibleBottomMargin;
- buttonView.AddSubview(btnAnimation0);
- btnAnimation1 = UIButton.FromType(UIButtonType.RoundedRect);
- btnAnimation1.Frame = new RectangleF(buttonView.Frame.Width * 0.25f,
- buttonView.Frame.Height * 0.0f,
- buttonView.Frame.Width * 0.25f,
- buttonView.Frame.Height * 1.0f);
- btnAnimation1.SetTitle("Two", UIControlState.Normal);
- btnAnimation1.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin |
- UIViewAutoresizing.FlexibleBottomMargin;
- buttonView.AddSubview(btnAnimation1);
- btnAnimation2 = UIButton.FromType(UIButtonType.RoundedRect);
- btnAnimation2.Frame = new RectangleF(buttonView.Frame.Width * 0.5f,
- buttonView.Frame.Height * 0.0f,
- buttonView.Frame.Width * 0.25f,
- buttonView.Frame.Height * 1.0f);
- btnAnimation2.SetTitle("Three", UIControlState.Normal);
- btnAnimation2.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin |
- UIViewAutoresizing.FlexibleBottomMargin;
- buttonView.AddSubview(btnAnimation2);
- btnAnimation3 = UIButton.FromType(UIButtonType.RoundedRect);
- btnAnimation3.Frame = new RectangleF(buttonView.Frame.Width * 0.75f,
- buttonView.Frame.Height * 0.0f,
- buttonView.Frame.Width * 0.25f,
- buttonView.Frame.Height * 1.0f);
- btnAnimation3.SetTitle("Four", UIControlState.Normal);
- btnAnimation3.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin |
- UIViewAutoresizing.FlexibleBottomMargin;
- buttonView.AddSubview(btnAnimation3);
- View.AddSubview(buttonView);
- #endregion
- #region Create Player
- effect = new GLKBaseEffect();
- Matrix4 projectionMatrix = Matrix4.CreateOrthographicOffCenter(0, animationView.Frame.Width, 0, animationView.Frame.Height, -1024, 1024);
- effect.Transform.ProjectionMatrix = projectionMatrix;
- player = new Sprite(@"Player.png", effect);
- #endregion
- }
- void animationView_DrawInRect(object sender, GLKViewDrawEventArgs e)
- {
- GL.ClearColor(0.98f, 0.98f, 0.98f, 1.0f);
- //GL.Clear((uint)(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit));
- GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
- GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
- GL.Enable(EnableCap.Blend);
- player.Render();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement