问题描述
有一点困惑,欣赏任何帮助。
我在做一个应用程序,使用画布来渲染游戏板。
我遇到一个问题,它不是最优的,为每一个小的变化渲染画布。
现在的结构是:
function renderCanvas(){
//调用每一行
}
function renderRow ){
//调用每个单元格
}
function renderCell(){
//这里我使用FillRect和StrokeRect两个
}
函数与传递上下文相互配合。
现在它渲染每个单元格。并且使用beginPath似乎只处理笔画。
我想知道我是否可以在renderCanvas函数中使用startPath(像beginPath),在所有上下文操作完成后 -
你只能对每个beginPath做一个样式...所以如果你的单元格需要不同的颜色,字体,不透明度,那么你必须为每个不同的样式做一个beginPath(但你可以将相同的样式组合成一个beginPath) p>
A little confused with one moment, appreciate any help.
I'm making an app, that uses canvas for rendering game board.And I faced a problem that its not optimal, rendering canvas for each little change.
Here's what the structure is at the moment:
function renderCanvas() {
// calling for each row
}
function renderRow() {
// calling for each cell
}
function renderCell() {
// Here i use FillRect and StrokeRect both
}
Functions cooperate with passing context to each other.
Now it renders each cell. And using beginPath appears to deal only with stroke.
I wonder if i can startPath (like beginPath) somehow in renderCanvas function and after all operations with context are done - i could render that all once?
You can only do one styling per beginPath...
So if your cells require different colors, fonts, opacities then you must do a beginPath for each different style (but you can group same-styles together into one beginPath).
这篇关于画布渲染一次,所有操作后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!