Quantcast
Channel: 2D Latest Topics
Viewing all articles
Browse latest Browse all 623

[Canvas] Rendering images using atlas vs individual elements

$
0
0

Hello, I would like to know if there is any difference (in performenc etc.)  when using atlas over the individual images to draw on canvas. 

In code example are shown these two approaches. 

Thank you!

// Example1 - individual images
let framePointer = 0
const animationFrames = [frame, frame2, frame3,...] // images are HTMLImageElements

//rendering
ctx.drawImage(animationFrames[framePointer], 0,0)
framePointer ++


// Example2 atlas
let atlasPointer = 0
const atlas = new Image()
atlas.src = 'atlas.png'
const atlasMap = [{x,y,width,heigth},...]

//rendering
let frameInfo = atlasMap[atlasPointer]
ctx.drawImage(
atlas,                 // HTMLImageElement
frameInfo.x,           //source x       
frameInfo.y,           //source y
frameInfo.width,       //source width
frameInfo,height,      //source height
0,                     //destination x
0,                     //destination y
frameInfo.width,       //destination width
frameInfo,height,      //destination heigth
)
atlasPointer ++

 


Viewing all articles
Browse latest Browse all 623

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>