コンテンツにスキップ
メインメニュー
メインメニュー
サイドバーに移動
非表示
案内
メインページ
最近の更新
未作成ページ
おまかせ表示
ヘルプ
MonoBook
検索
検索
ログイン
個人用ツール
ログイン
ログアウトした編集者のページ
もっと詳しく
投稿記録
トーク
「
MonoGameでSkiaSharpを使う
」を編集中 (節単位)
ページ
議論
日本語
閲覧
編集
ソースを編集
履歴表示
ツール
ツール
サイドバーに移動
非表示
操作
閲覧
編集
ソースを編集
履歴表示
全般
リンク元
関連ページの更新状況
特別ページ
ページ情報
警告:
ログインしていません。編集を行うと、あなたの IP アドレスが公開されます。
ログイン
または
アカウントを作成
すれば、あなたの編集はその利用者名とともに表示されるほか、その他の利点もあります。
スパム攻撃防止用のチェックです。 けっして、ここには、値の入力は
しない
でください!
==環境構築== 基本的にMonoGameプロジェクトにNuGetでSkiaSharpを突っ込むだけで利用できる。 ただしMonoGameプロジェクトのターゲットフレームワークは初期状態で「Mono / .NET 4.5」となっているが、 このままだとSkiaSharpがWindowsと勘違いしてDLLを開こうとして落ちる。 このためターゲットフレームワークを「Xamarin.* Mobile Framework」に変更するか、 packages.configを書き換える必要がある。この点には注意する必要がある。 あとはSkiaSharpのSKBitmapをMonoGameのTexture2Dに変換できれば楽勝だ。 <source lang="csharp"> using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using SkiaSharp; public static class MonoGameExtensions { public static Texture2D ToTexture2D(this SKBitmap skbitmap, GraphicsDevice graphicsDevice) { var texture = new Texture2D(graphicsDevice, skbitmap.Width, skbitmap.Height, mipmap: false, format:SurfaceFormat.Color); texture.SetData(skbitmap.Bytes); return texture; } } </source> 試しに虹色グラデーションな円を描いてみる。 <source lang="csharp"> using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Input; using SkiaSharp; namespace MonoGameSkia { public class Game1 : Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch; Texture2D texture; public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; } protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); //TODO: use this.Content to load your game content here var w = 500; var h = 500; using (var bitmap = new SKBitmap(w, h)) using (var canvas = new SKCanvas(bitmap)) { // 透明色で塗りつぶす canvas.Clear(SKColors.Transparent); // 虹色グラデーションシェーダー var shader = SKShader.CreateSweepGradient( new SKPoint(w/2, h/2), new[] { new SKColor(0x00,0x00,0xff), new SKColor(0x00,0xdb,0xff), new SKColor(0x00,0xff,0x49), new SKColor(0x91,0xff,0x00), new SKColor(0xff,0x93,0x00), new SKColor(0xff,0x00,0x47), new SKColor(0xdd,0x00,0xff), }, null); var paint = new SKPaint { Shader = shader, StrokeWidth = 50, IsStroke = true, }; // 円を描く canvas.DrawCircle(w/2, h/2, w/4, paint); // 描画コマンド実行 canvas.Flush(); // SKBitmapをTexture2Dに変換 texture = bitmap.ToTexture2D(graphics.GraphicsDevice); } } protected override void Update(GameTime gameTime) { #if !__IOS__ && !__TVOS__ if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) Exit(); #endif base.Update(gameTime); } protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.Clear(Color.CornflowerBlue); spriteBatch.Begin(); spriteBatch.Draw(texture, new Vector2(0, 0), Color.White); spriteBatch.End(); base.Draw(gameTime); } } } </source>
編集内容の要約:
MonoBookへの投稿はすべて、他の投稿者によって編集、変更、除去される場合があります。 自分が書いたものが他の人に容赦なく編集されるのを望まない場合は、ここに投稿しないでください。
また、投稿するのは、自分で書いたものか、パブリック ドメインまたはそれに類するフリーな資料からの複製であることを約束してください(詳細は
MonoBook:著作権
を参照)。
著作権保護されている作品は、許諾なしに投稿しないでください!
このページを編集するには、下記の確認用の質問に回答してください (
詳細
):
1たす1は?(全角で入力してください)
キャンセル
編集の仕方
(新しいウィンドウで開きます)
本文の横幅制限を有効化/無効化