0

Xamarin Sprite Animation Within a Sub-View

I am attempting to use Xamarin, not MonoGame, to render a sprite. I want to describe my situation in its entirety to help give my question some background. I want to use a UIViewController to display two UIView(s) on the Window. One UIView, UIView A, will be positioned directly above the second, UIView B, on the screen, rather than overlaying it. The UIView B will force an event that will render a sprite on UIView A. At the moment I have this event being caught by the UIViewController and the Controller throws the Event into UIView A. I am left without the knowledge of how to render the sprite in the UIView A. I’ve done a good amount of research and come up with a few solutions, none of which I have been able to get working successfuly. I will list the solutions I have found. I placed them in order of which I would prefer to try.

Solution #1: GLKView I found that many people have issues with animation lag using CoreAnimation. In Objective-C, on iOS, the recommendation is to use GLKView. I can’t find how this would work in Xamarin. I have found Objective-C examples, none very detailed, of how to launch a GLKView in a UIViewController. None explicitly say how to set up the Delegate Function to handle the screen draw. This also does not explain how to handle pulling images from a sprite sheet.

Solution #2: Cocos2D I found that many 2D games for iOS are built using Cocos2D due to its ability to render sprites easily. I found that in Objective-C, on iOS, you can load a UIView that is a Cocos2D View. I know people have built Cocos2D games using Xamarin. However, I have yet to find a solid example of how to do this in Xamarin.

Solution #3: UIImageView I have found examples of how to accomplish simple sprite animations using UIImageView, located here: http://docs.xamarin.com/recipes/ios/standard_controls/image_view/animate_an_imageview. However the example loads multiple unique images and not images being pulled from a single sprite sheet. I attempted to find an Objective-C example and all examples using a GCImageRef Class that does not exist in Xamarin. The example is located here: How to cut a large sprite png into smaller UIImages?.

I’m sure other solutions may exist that I have yet to find, but I would like some input and examples on what solution I should take.

Thanks, Robert

Community
  • 1
  • 1
CubanAzcuy
  • 125
  • 1
  • 13
  • my advice: if you need examples to do any of this you may be better off not using xamarin and instead use native technologies. There are a lot more examples available for these compared to a niche solution like xamarin/monotouch. Regarding spritesheets cocos2d (or sparrow) are the easiest solution, the other don't have builtin support for texture atlases. – CodeSmile Jun 26 '13 at 08:55

1 Answers1

0

I cannot speak to the specifics of your question, but I can point you towards reasorces that I have found very useful in getting familiar with using Xamarin and SpriteKit:

Basic walkthrough: http://blog.xamarin.com/make-games-with-xamarin.ios-and-sprite-kit/

How to write a sprikeKit game (For iOS, but useful to read through sinc the sequence and events would be similiar): http://www.raywenderlich.com/42699/spritekit-tutorial-for-beginners <-- write a spritekit game

Most useful: The official SpriteKit examples directly from Xamarin, http://docs.xamarin.com/samples/ios/SpriteKit/

I hope this helps you or others in your situation!

woody121
  • 358
  • 3
  • 14