如何在画布上优化动画?(How to optimize animation on canvas? HTML 5)
我面临着一个问题,即减慢画布上的动画,因为各种图片向左,向右,向上和向下移动。 我需要有关如何优化动画的建议。
动画适用于所有主要浏览器,尤其是Chrome,Firefox和Internet Explorer。
是否可以优化动画? 也许拖延绘图? 先谢谢你。
I am faced with a problem that slows down animation on a canvas, as various pictures move left, right, up and down. I need advice on how to optimize the animation.
It is important that the animation works on all main browsers, in particular: Chrome, Firefox and Internet Explorer.
Is it possible to optimize the animation? Maybe put a delay on the drawing? Thank you in advance.
原文:https://stackoverflow.com/questions/7394136
最满意答案
事情是,红宝石中的这种方法可以带或不带圆括号运行。 例如,你可以运行
Array.new 1,2
,Ruby知道它接收到空格后的参数。 你也可以运行Array.new(1,2)
,ruby知道参数在括号内。但是,当你运行
Array.new (1,2)
,ruby认为它会在空间后接收参数,但实际上它会接收一个元组(1,2)
,基本上它和Array.new((1,2))
所以底线:
Array.new (1,2)
==Array.new((1,2))
,这是一个语法错误,因为(1, 2)
文字不是有效的the thing is, that method in ruby can be run with or without parentheses. for example, you can run
Array.new 1,2
and ruby knows that it receives the arguments after the space. and you can also runArray.new(1,2)
and ruby knows the args are inside the parentheses.but, when you run
Array.new (1,2)
, ruby thinks it will receive arguments after the space but actually it receives a tuple(1,2)
, and basicaly its exactly the same asArray.new((1,2))
so bottom line:
Array.new (1,2)
==Array.new((1,2))
and thats a syntax error because(1, 2)
literal is not a valid one
相关问答
更多-
不,因为text-indent与元素的第一行相关,而换行生成的换行不会创建元素。 因此,您需要使用一些内容标记,而不仅仅是HTML源代码中的换行符。 No, because text-indent relates to the first line of an element, and newlines generated by line wrapping do not create elements. So instead of just newlines in HTML source, you need ...
-
不知道为什么REXML库没有为你提供这个选项,因为它肯定可以在内部支持它,但你可以只使用自己的格式化程序: module REXML module Formatters class Prettier < Pretty attr_accessor :style def initialize(indentation = 2, indent_style =" ", ie_hack=false) @style = indent_style ...
-
覆盖方法本身不会影响性能,但方法的实现很重要。 你的方法很糟糕,因为它有多余的东西。 它可以更好地写为: def eql?(other) url = self.url and other and url == other.url end url = self.url是url = self.url 。 你最初有五个条件来实现它: 不是其他==假 不是网址==无 不是其他==无 不是other.url == nil url == other.url 其中, 通过将url置于条件中可以将No1和No3放在一 ...
-
HTML会影响ajax调用(Do HTML affect ajax calls)[2023-12-26]
我觉得问题是用submit按钮类型添加form提交。 只需添加一行代码即e.preventDefault()以防止submitting the form按钮的默认操作,以便它不会提交form $("button").click(function(e) { e.preventDefault() var url = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=allpages&aplimit=5&apfrom=Man ... -
事情是,红宝石中的这种方法可以带或不带圆括号运行。 例如,你可以运行Array.new 1,2 ,Ruby知道它接收到空格后的参数。 你也可以运行Array.new(1,2) ,ruby知道参数在括号内。 但是,当你运行Array.new (1,2) ,ruby认为它会在空间后接收参数,但实际上它会接收一个元组(1,2) ,基本上它和Array.new((1,2)) 所以底线: Array.new (1,2) == Array.new((1,2)) ,这是一个语法错误,因为(1, 2)文字不是有效的 the ...
-
如果您要使用方法调用括号,则必须避免在方法名称和左括号之间放置一个空格: if "string".start_with?(*hash.keys) puts "ok" else puts "ng" end 而且, then是相当陈旧的,所以我们假装从来没有。 如果方法名称和左括号之间有空格,则括号将被解释为表达式分组括号,这就是语法错误的来源。 一旦你添加了方法调用括号,你就删除了任何可能的含糊不清的暗示,你的*应该是什么意思,警告应该消失。 顺便说一下,你在这种情况下得到的警告相当,嗯,愚蠢。 第 ...
-
在Sublime Text 3中为ruby函数调用突出显示语法(Syntax highlighting for ruby function calls in Sublime Text 3)[2021-12-02]
我通过在Sublime中添加对rails的支持找到了一个可行的解决方案,它将某些方法的范围更改为source.rails.controller.actions I found a working solution by adding support for rails in Sublime, which changes the scope of certain methods to source.rails.controller.actions -
你需要的是获取输入并将其字符映射到morse_code哈希中的相应值,然后将其与空格连接: code = 'abb' code.each_char.map { |letter| morse_code[letter] }.join(' ') #=> ".- -... -..." 参考: String# each_char 可枚举的#map 数组join 编辑: 要使你的初始代码工作,你唯一缺少的是一个空间,这很容易使用插值添加: code = 'abab' morse_code.each do |morse ...
-
简短回答: extern VALUE rb_vm_top_self(void); /* Assumes 1.9. Under 1.8, use the global * VALUE ruby_top_self */ ... rb_funcall(rb_vm_top_self(), /* irb> RubyFunction() ...
-
显然,在父元素上将font-size设置为0,然后在元素本身上恢复它应该可以解决问题。 解决方案来自:这里如何删除内联块元素之间的空间? Apparently, setting the font-size to 0 on a parent element, and then restoring it on the elements themselves, should fix the problem. Solution from here: How to remove the space between i ...