9. Limited Sound Support
• Cannot play multiple sounds simultaneously
• iOS requires user input to play sound
• Slow downs the performance
Background music
Effect
15. 1. 2. 3. 4. 5. 6.
Both Canvas And CSS3 3D Transforms have to be
supported
16. Both Canvas And CSS3 3D Transforms have to be supported
Need to use different rendering methods depending
on the platform to get hardware acceleration
Hardware Accelerated Canvas Animation in iOS5
17. Both Canvas And CSS3 3D Transforms have to be supported
iOS4 did not have hardware acceleration support
Performance comparison between iOS4 and iOS5
18. Both Canvas And CSS3 3D Transforms have to be supported
iOS4 supports hardware acceleration when using
CSS 3D Transforms
Performance comparison between iOS4 and iOS5 with different rendering methods
19. Both Canvas And CSS3 3D Transforms have to be supported
"O, iOS4 is such an old platform, maybe my game
does not need to support it"
20. Both Canvas And CSS3 3D Transforms have to be supported
Renderings Used
iPhone iPhone Android Android
3GS or 4 4S 2.x 3 or higher
CSS 3D
(less than iOS5)
Canvas
Rendering Canvas or CSS 3D
DOM
Canvas
(iOS5 over)
21. Both Canvas And CSS3 3D Transforms have to be supported
"Well, most mobile devices support
CSS3 3D transforms, so I’ll just ditch Canvas totally
and go with DOM"
22. Both Canvas And CSS3 3D Transforms have to be supported
Performance Comparison between Canvas and
DOM in iOS5
FPS
60
50
40 Canvas
30
CSS3 3D Transforms
20
10
0
10 20 30 50 100 Objects
23. 2. 3. 4. 5. 6.
Need to find out the exact extent of an object
24. Need to find out the exact extent of an object
Must find out the exact extent of an object
25. Need to find out the exact extent of an object
How to find the exact extent of an object using
getImageData method in Canvas
var el = document.createElement("canvas");
el.width = 200;
el.height = 200;
var ctx = el.getContext("2d");
ctx.fillStyle = "red";
ctx.fillRect(10, 10, 100, 100);
var imageData = ctx.getImageData(20, 20, 1, 1);
if (
imageData.data[0] !== 0 ||
imageData.data[1] !== 0 ||
imageData.data[2] !== 0 ||
imageData.data[3] !== 0
) {
console.log("here it is!");
}
26. Need to find out the exact extent of an object
Security Issue with Canvas Element
• Information leakage can occur if scripts from
one origin can access information (e.g. read
pixels) from images from another origin (one that
isn't the same)
• The toDataURL(), toBlob(), and getImageData()
methods check the flag and will throw a
SecurityError exception rather than leak cross-
origin data
27. Need to find out the exact extent of an object
Predefining the area
[[126, 285],[104, 286],[101, 267],[105,
221],[101, 213],[88, 188],[85, 168],[81,
153],[94, 133],[97, 103],[94, 60],[95,
29],[103, 32],[109, 97],[143, 93],[147,
33],[151, 31],[152, 97],[161, 137],[166,
167],[165, 188],[169, 200],[165,
208],[160, 209],[159, 235],[159,
256],[159, 269],[162, 275],[162,
286],[138, 288],[130, 275],[132, 254]]
28. Need to find out the exact extent of an object
Performance comparison between
getImageData and PNPOLY
Operations
70000
60000
50000
40000
9,930%↑
operations/sec
30000
20000
10000
0
getImageData() PNPOLY Algorithm
http://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html
29. Need to find out the exact extent of an object
Graphic Designer
I'm a Graphic Designer
30. 3. 4. 5. 6.
Use a Bitmap Image Instead of Drawing
31. Use a Bitmap Image Instead of Drawing
Drawing Vectors is Slow
Performance comparison between vector drawing and using images
32. Use a Bitmap Image Instead of Drawing
Object Caching
Non Object Caching
Draw a vector
Use Object Caching
Draw a vector
Draw a bitmap
hidden canvas
visible canvas
33. Use a Bitmap Image Instead of Drawing
It’s better to use already pre-rotated images
rather than rotating them on the fly
34. Use a Bitmap Image Instead of Drawing
Shadow, filter and gradation are expensive
Performance enhanced by using prepared images
41. Android...
Declare Every Element In Animation As 3D
DIV -webkit- DIV -webkit-
transform:translate3d(0, 0, 0); - transform:translate3d(0, 0, 0); -
webkit-transform-style:preserve-3d webkit-transform-style:preserve-3d
ㄴ IMG no styles ㄴ IMG -webkit-
transform:translateZ(0)
42. Android...
A bug found while using CSS3 3D Transforms
and form element in Android
The Image Will Become Larger When Keyboard Shows Up
47. More Technical Points
Polishing logics inside a tick is very important
• 60 times in a second is 3600 times in a minute
• Even a simple “if statement” can be problem
Tick
16.667ms