<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>canvas | ウダ2Blog</title>
	<atom:link href="https://uda2.com/blog/tag/canvas/feed/" rel="self" type="application/rss+xml" />
	<link>https://uda2.com/blog</link>
	<description>大阪でフリーランスとしてWEB制作している管理人が気になった技術をメモったり、作ったツールの紹介などを綴っているブログです。</description>
	<lastBuildDate>Sun, 26 Sep 2021 16:25:03 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
	<item>
		<title>イカよけダンスをぱくった「しらす[よけ]ゲーム」</title>
		<link>https://uda2.com/blog/shirasu/</link>
					<comments>https://uda2.com/blog/shirasu/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Mon, 20 Sep 2021 07:12:59 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[ゲーム]]></category>
		<guid isPermaLink="false">https://uda2.com/blog/?p=2516</guid>

					<description><![CDATA[<p>Julian Frostさんが作った日清食品のカップヌードル「イカよけダンス 篇」に衝撃を受けてスマホ用のWEBゲーム「しらす[よけ]ゲーム」を作りました。イカだと日清さんに怒られるのでしらすにしました。ゲーム内容は2本</p>
The post <a href="https://uda2.com/blog/shirasu/">イカよけダンスをぱくった「しらす[よけ]ゲーム」</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p></p>



<p><a href="http://julianfrost.co.nz/work/" target="_blank" rel="noreferrer noopener">Julian Frost</a>さんが作った日清食品の<a href="https://www.nissin.com/jp/products/cm/323" target="_blank" rel="noreferrer noopener">カップヌードル「イカよけダンス 篇」</a>に衝撃を受けてスマホ用のWEBゲーム<a href="https://shirasu.uda2.com" target="_blank" rel="noreferrer noopener">「しらす[よけ]ゲーム」</a>を作りました。<br>イカだと日清さんに怒られるのでしらすにしました。<br>ゲーム内容は2本指でしらすをよけつつ指の間に張られた網で捕獲し、一定数しらすを捕獲すると現れるレアもん（しらすと同じサイズの生物）を捕獲するとクリアになります。<br>しらすやちりめんじゃこに紛れる生物はチリメンモンスター（チリモン）とかいう名称があるそうなのですが一般的な名称でなく商標を取られてるので避けてレアもんとしてます。</p>



<span id="more-2516"></span>



<p>canvas（1000px×1400px）だと重くなりそうなので面倒だけどWEBGLとかの方がいいかなとも思ったのですが試してみるとiPhone12miniで60fps出てたので問題無かった。<br>当たり判定はしらすの目あたりにしてるのですが点と点の衝突はシンプルに点と点の距離で判断できるんだけど<br>今回は網なので右手の左手のなす線に対して魚の点で当たり判定をする必要があったので調べると高校でならったはずの「点と直線の距離の公式」というのが使えるらしい。<br>その公式に必要な直線の式を導き出すのに「2点を通る直線の方程式」なるものを併せて各座標を点A（右手）点B（左手）点C（魚）としてJavascriptで書くと下記の感じになる。</p>



<pre><code>Math.abs((By-Ay)(Cx-Ax) - (Bx-Ax)(Cy-Ay)) / Math.sqrt(Math.pow(Bx - Ax, 2) + Math.pow(By - Ay, 2)); </code></pre>



<p>ちなみに「Math.sqrt(Math.pow(Bx &#8211; Ax, 2) + Math.pow(By &#8211; Ay, 2))」は点Aと点Bの距離です。なぜ距離が関係するかは不明。</p>



<p>ただ、これだけだと網付近の魚しか捕獲できず激しい動きの際に網をすり抜けるので前のフレームでの右手の左手と今の右手の左手がなす四角形の内側かどうかの判定も付けた。<br>これはゲームでよく使うポリゴン内かを判定するアルゴリズム（Winding Number Algorighm）でなんとかした。</p>



<p>なおデータはクッキーに保存されサーバーには保存してません。</p>



<p>両手使うので脳トレにもなるかもしれません <a href="https://shirasu.uda2.com" target="_blank" rel="noreferrer noopener">「しらす[よけ]ゲーム」</a>を試してください。<br>私はこのゲームを作るにあたりだいぶと魚の稚魚に詳しくなりました。</p>The post <a href="https://uda2.com/blog/shirasu/">イカよけダンスをぱくった「しらす[よけ]ゲーム」</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/shirasu/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pixi.jsで千切りした画像を動かしてみる</title>
		<link>https://uda2.com/blog/pixi/</link>
					<comments>https://uda2.com/blog/pixi/#respond</comments>
		
		<dc:creator><![CDATA[uda2]]></dc:creator>
		<pubDate>Sun, 23 Nov 2014 13:02:30 +0000</pubDate>
				<category><![CDATA[制作日記]]></category>
		<category><![CDATA[canvas]]></category>
		<category><![CDATA[pixi]]></category>
		<guid isPermaLink="false">http://uda2.com/blog/?p=1526</guid>

					<description><![CDATA[<p>ブラウザでゲームとか作ったりアニメーションさせる時に便利なcanvas系のJavaScriptライブラリはいくつかあるが最速の描画JavaScriptライブラリは!? パフォーマンスの検証 &#8211; ICS LAB</p>
The post <a href="https://uda2.com/blog/pixi/">Pixi.jsで千切りした画像を動かしてみる</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></description>
										<content:encoded><![CDATA[<p><img fetchpriority="high" decoding="async" src="http://uda2.com/blog/wp-content/uploads/Pixi.jpg" alt="Pixi.js" width="450" height="194" class="alignnone size-full wp-image-1527" srcset="https://uda2.com/blog/wp-content/uploads/Pixi.jpg 450w, https://uda2.com/blog/wp-content/uploads/Pixi-300x129.jpg 300w" sizes="(max-width: 450px) 100vw, 450px" /><br />
ブラウザでゲームとか作ったりアニメーションさせる時に便利なcanvas系のJavaScriptライブラリはいくつかあるが<a href="http://ics-web.jp/lab/archives/201" target="_blank">最速の描画JavaScriptライブラリは!? パフォーマンスの検証 &#8211; ICS LAB</a>によると<a href="http://www.pixijs.com/" target="_blank">Pixi.js</a>はWebGLを使ってFlashよりも速いらしい。</p>
<p>以前揺れるキリンで高さ1pxの要素（li）の背景にしてjQueryで動かしてみたがとても遅かった。<br />
そこで、このpixi.jsを使えば早くなるかもと考えやってみた。<br />
<a href="http://uda2.com/pixi/" target="_blank">kirin wave by Pixi.js</a></p>
<p>前回同様、高さ1pxにスライスするが今回は要素では無くスプライトに貼り付ける感じだ。<br />
作ったはいいが、WebGLを有効にするとFirefoxでは動かず（参考にした<a href="http://liginc.co.jp/web/js/other-js/114087" target="_blank">Pixi.jsを初めて触って簡単にアニメーションを作成してみた話（その3） | 株式会社LIG</a>も動いてない）<br />
Google Chromeは動くけどWebGLを有効・無効にかかわらず以前より重くなってしまった。</p>
<p>720個のスプライトを描画させるのは難しいのかもしれない。</p>The post <a href="https://uda2.com/blog/pixi/">Pixi.jsで千切りした画像を動かしてみる</a> first appeared on <a href="https://uda2.com/blog">ウダ2Blog</a>.]]></content:encoded>
					
					<wfw:commentRss>https://uda2.com/blog/pixi/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
