Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
enchant.jsをRails上で動かした話
Search
ryonext
May 15, 2013
Programming
7.3k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
enchant.jsをRails上で動かした話
2013/05/15 Shibuya.rbにて
ryonext
May 15, 2013
More Decks by ryonext
See All by ryonext
AWS Lambda の Ruby 対応
ryonext
0
270
TwitterのList編集しやすいやつ作った
ryonext
0
1.8k
validationについて
ryonext
1
840
AWS Lambda と API GatewayでRails使わずに済んだ話
ryonext
8
4.4k
capistrano-bundle_rsync使ったらオートスケールが高速化した話
ryonext
8
2.6k
PumaとUnicornで最近自分が理解したこと
ryonext
13
9.6k
Hubot事例
ryonext
1
1.7k
Redisでバッチ処理を冗長化しつつ排他制御
ryonext
0
2.1k
CircleCIとwercker
ryonext
3
1.3k
Other Decks in Programming
See All in Programming
不変条件と整合性境界—ビジネスが決める設計判断と実現パターン / Invariants and Consistency Boundaries
nrslib
13
3.5k
Spring Security 実践 ─ GraphQL APIで実務に役立つ 認証・認可 を学ぶ
wagyu
0
200
DynamoDBには集計系のクエリがないけどなんとかしたい
musan
1
130
Signal Forms: Beyond the Basics @ngBaguette 2026 in Paris
manfredsteyer
PRO
0
230
Vite+ Unified Toolchain for the Web
naokihaba
0
140
ふつうのFeature Flag実践入門
irof
7
3.6k
技術記事、AIに書かせるか、自分で書くか? 〜それでも私が自分の手で書く理由〜 / #QiitaConference
jnchito
2
1.3k
CSC307 Lecture 17
javiergs
PRO
0
320
Inside Stream API
skrb
1
660
Lessons from Spec-Driven Development
simas
PRO
0
150
AIエージェントの隔離技術の徹底比較
kawayu
0
470
AI 時代のソフトウェア設計の学び方
masuda220
PRO
29
12k
Featured
See All Featured
More Than Pixels: Becoming A User Experience Designer
marktimemedia
3
430
What does AI have to do with Human Rights?
axbom
PRO
1
2.2k
We Are The Robots
honzajavorek
0
240
Amusing Abliteration
ianozsvald
1
200
Google's AI Overviews - The New Search
badams
0
1k
Building Applications with DynamoDB
mza
96
7.1k
Code Reviewing Like a Champion
maltzj
528
40k
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
140
Technical Leadership for Architectural Decision Making
baasie
3
400
Exploring anti-patterns in Rails
aemeredith
3
400
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
360
The Curious Case for Waylosing
cassininazir
1
380
Transcript
enchant.jsΛRails্Ͱ ಈ͔ͨ͠ @ryonext 135݄15ਫ༵
ࣗݾհ • Twitter ID: ryonext • ࣄͰRailsͬͯ·͢ɻ 135݄15ਫ༵
͜Εʹ͍ͭͯ͠·͢ http://bearsheaven.herokuapp.com/ 135݄15ਫ༵
enchant.js • ήʔϜ࡞Γʹ͍ͨjsϑϨʔϜϫʔΫ • http://enchantjs.com/ja/ 135݄15ਫ༵
jsdo.it http://jsdo.it/ 135݄15ਫ༵
ڈ࡞ͬͨήʔϜ 135݄15ਫ༵
Rails্Ͱಈ͔ͯ͠είΞอ ଘͱ͔ͯ͠ΈΑ͏ͱࢥͬͨ 135݄15ਫ༵
• enchant.jsͷίʔυ͔Βී௨ͷjsDOMཁૉ ͷૢ࡞͕Ͱ͖ΔͷͰՄೳ ࣮ࡍͰ͖Δͷ͔ʁ 135݄15ਫ༵
109 # ήʔϜຖϑϨʔϜͷॲཧ 110 game.rootScene.addEventListener Event.ENTER_FRAME, -> 111 #ϠϥϨνϟολʁ 112
if player.status is STATUS_CRY 113 if player.y > CHARACTER_Y && gameOver is false 114 gameOver = true 115 sendScore(game.score, difficult.text, game.max_magnification) ࢮΜͩͱ͖ͷॲཧ͜ͷลͰɺ enchant.jsͱؔͳ͍jsॲཧ͕ී௨ʹͰ͖Δ 135݄15ਫ༵
• είΞొͷControllerͱModelΛ࡞ͬͯɺjs ͔ΒݺΜͰ͋͛ΕOK 135݄15ਫ༵
JSଆ 13 postScore = (score, difficulty, name, magnification) -> 14
$.ajax 15 url: "/games", 16 type: 'POST', 17 dataType: 'json', 18 timeout: 1000, 19 data: { 20 score: { 21 name: name, 22 point: score, 23 difficulty: difficulty, 24 magnification: magnification 25 } 26 } 27 success: -> 28 $.notifyBar 29 html: "success!", 30 delay: 2000, 31 animationSpeed: "normal" 135݄15ਫ༵
Railsଆ 1 class GamesController < ApplicationController 2 def new 3
render :layout => false 4 end 5 6 def create 7 score = Score.new(params[:score]) 8 score.save! 9 render json: {status: true} 10 end 11 12 def index 13 @scores = Score.order("point desc").limit(10) 14 end 15 end ͜ΕݺΜͰΔ 135݄15ਫ༵
ଞʹͬͨ͜ͱ • CoffeeScriptԽ • assets pipelineରԠ 135݄15ਫ༵
CoffeeScriptԽ • js ⇔ coffeeͷ૬ޓมαΠτΛར༻ • http://js2coffee.org/ • ͨͩ͠ɺذͷҰ෦Λਖ਼͘͠มͯ͘͠Εͳ ͔ͬͨͨΊॻ͖ͳ͓͢ඞཁ͕͋ͬͨɻ
135݄15ਫ༵
assets pipelineରԠ • enchant.jsͱui.enchantjsΛϓϩδΣΫτʹೖ Εͯɺapplication.jsʹهೖ • //= require enchant //=
require ui.enchant 135݄15ਫ༵
assets pipelineམͱ݀͠ • ui.enchant.jsͷը૾͕ <IPTUOBNF><DVSSFOU@QBUI>ʹ ͋Δ͜ͱΛظ͍ͯ͠ΔͨΊɺ<IPTUOBNF>BTTFUT ʹը૾Λஔ͢Δassets pipelineͰಈ͔ͳ͔ ͬͨ •
ͱΓ͋͑ͣpublic/ ʹը૾Λஔ͍ͯରॲ • CSSͷURLࢦఆΛimage-urlʹ͠ͳ͍ͱ͍͚ ͳ͍ɺ͔ͳɾɾɾʢʁʣ 135݄15ਫ༵
assets pipelineམͱ݀͠2 • enchant.jsಡΈࠐΉͱήʔϜ͕࢝Ίͬͯ͠ ·͏ͨΊɺήʔϜΛݟ͍ͤͨϖʔδͰͷΈಡ ΈࠐΈ͍ͨ(assets piplineΛ͚Δʣ • config/environments/production.rb •
config.assets.precompile += %w( games.js ) 135݄15ਫ༵
ͦͷ΄͔ • tutorialϖʔδͷ࡞ • ੩తཁૉ͔͠ͳ͍͚Ͳͦͷ··RailsͰ࡞ • ຊޠΘͳ͍Α͏ʹͯ͠Έͨ 135݄15ਫ༵
੩తϖʔδ • ࣄͷίʔυ͕haml͚ͬͨͲ naoya ͞Μ ͷهࣄͰslimͬͯΔࣄ͕ॻ͍ͯ͋ͬͨΜ ͰझຯͷίʔυͳΒͬͺΓslimͰ͍͍͔ ͳɺͱࢥͬͨΓɻ • ࡢࠓͷࣗ༻WebΞϓϦέʔγϣϯͻͳܗ
- naoyaͷͯͳμΠΞϦʔ http:// d.hatena.ne.jp/naoya/20130503/1367581629 135݄15ਫ༵
webfont • είΞͷϑΥϯτɺWebϑΥϯτͰ͜ͷϑΝ ϛίϯͬΆ͍ϑΥϯτ↓͍͔͚ͨͬͨͲ WebͰ͏ʹॏ͍(1M over)ͷͰஅ೦ • 8×8υοτຊޠϑΥϯτʮඒ࡙ϑΥϯτʯ http://www.geocities.jp/littlimi/misaki.htm 135݄15ਫ༵
jQueryϥΠϒϥϦ • είΞૹ৴ͷμΠΞϩά • jQuery UI ͷdialog • είΞૹ৴ޙͷ௨ •
jQuery-Notify-bar • https://github.com/dknight/jQuery-Notify- bar 135݄15ਫ༵
Εͯͳ͍͜ͱ • ηΩϡϦςΟपΓͳʹͯ͠ͳ͍ͷͰ࣮ε ίΞͷPOSTͷURLʹ͋Ε͢Εɾɾɾ • ςετॻ͍ͯͳ͍ • jsͰॻ͍ͨίʔυ͕ͦͦςετॻ͚Δ Α͏ͳઃܭʹͳͬͯͳ͍ •
WiiUରԠ 135݄15ਫ༵
Ҏ্ 135݄15ਫ༵