无法让Phaser工作(Can't Get Phaser To Work)
在过去的几天里,我一直无法让移动工作:只是想测试一个hello world程序。 我完全按照Phaser网站上的指示,它仍然不适合我。
我正在使用node.js.
这里是index.html:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Hello World</title> <style> #game_div { width: 500px; margin: auto; margin-top: 50px; } </style> <script type="text/javascript" src="phaser.min.js"></script> <script type="text/javascript" src="main.js"></script> </head> <body> <div id="game_div"> </div> </body> </html>
这里是main.js:
/*jslint node: true */ "use strict"; var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div'); var main_state = { preload: function () { game.load.image('hello', 'assets/hello.png'); }, create: function () { this.hello_sprite = game.add.sprite(200, 245, 'hello'); }, update: function () { this.hello_sprite.angle += 1; } } game.state.add('main', main_state); game.state.start('main');
它给我的错误是:
“Phaser”在被定义之前就被使用了。
var game = new Phaser.Game(400,490,Phaser.AUTO,'game_div');我真的试图寻找解决方案,但我找不到任何错误。 我对JavaScript和phaser很新。
For the past few days, I have been unable to get phaser to work: just trying to test a hello world program. I've followed the directions on phaser's site exactly, and it still isn't working for me.
I am using node.js.
Here is index.html:
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>Hello World</title> <style> #game_div { width: 500px; margin: auto; margin-top: 50px; } </style> <script type="text/javascript" src="phaser.min.js"></script> <script type="text/javascript" src="main.js"></script> </head> <body> <div id="game_div"> </div> </body> </html>
Here is main.js:
/*jslint node: true */ "use strict"; var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div'); var main_state = { preload: function () { game.load.image('hello', 'assets/hello.png'); }, create: function () { this.hello_sprite = game.add.sprite(200, 245, 'hello'); }, update: function () { this.hello_sprite.angle += 1; } } game.state.add('main', main_state); game.state.start('main');
The error it gives me is:
'Phaser' was used before it was defined.
var game = new Phaser.Game(400, 490, Phaser.AUTO, 'game_div');I've really tried looking for solutions to this, but I can't find anything wrong. I'm pretty new to JavaScript and phaser.
原文:https://stackoverflow.com/questions/22999849
最满意答案
得到它了!
问题在于导入SonarQube的依赖关系。 我在我的pom.xml中添加了很多Android依赖项,并在更改后进行测试。 在此之后,仍然没有工作。 在一些搜索中,我发现负责解释类的负责人是android-maven-plugin。 当我通过Eclipse的pom接口导入时,总会出现一些错误,说明缺少一些arctifa。 发生此问题是因为远程依赖项已损坏或不存在,因此我从依赖项下载了该jar文件并创建了一个文件
target/test-jars
。 有了这个,maven识别了外部依赖关系,并继续进行JUnit的测试。为了验证这些信息,我在规则中打印了类的属性检查文件:
package org.sonar.template.java.checks; import com.google.common.collect.ImmutableList; import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.semantic.Symbol; import org.sonar.plugins.java.api.semantic.Symbol.TypeSymbol; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.*; import org.sonar.plugins.java.api.tree.Tree.Kind; import java.util.List; @Rule( key = "SharedPreferencesRule", name = "Utilização de SharedPreferences no código", description = "Para cada utilização de SharedPreferences, é feito um alerta para revisar o que está sendo armazenado.", priority = Priority.CRITICAL, tags = {"attention point", "security"}) public class SharedPreferencesCheck extends IssuableSubscriptionVisitor { @Override public List<Kind> nodesToVisit() { return ImmutableList.of(Kind.METHOD_INVOCATION); } @Override public void visitNode(Tree tree){ System.out.println("====================== Kind Finded ======================"); MethodInvocationTree kindTree = (MethodInvocationTree) tree; Symbol symbol = (Symbol) kindTree.symbol(); TypeSymbol classe = symbol.owner().enclosingClass(); System.out.println("Name >>>>>>>>>>>>> " + symbol.name()); System.out.println("Enclosing >>>>>>>>>>>>> " + classe); if (classe != null && classe.equals("SharedPreferences")){ reportIssue(kindTree.firstToken(), "SharedPreferences sendo utilizado no código. Analisar!!"); } } }
我希望它能帮助正在经历相同或类似问题的人。
如果任何人都可以给出更好的解释,那真的很有帮助。
非常感谢!
Got it!
The problem was on the import of dependencies of SonarQube. I've added a lot of Android dependencies on my pom.xml and test after the alterations. After this, still not working. In some searches I've discovered that the responsable for do the interpretation of the classes was the android-maven-plugin. When I've imported by the pom interface of Eclipse, always get some error saying that some arctifacts was missing. This problem occurred because the remote dependency was corrupted or doesn't exist, so I downloaded the jar file from dependency and create a file
target/test-jars
. With this, the maven identify the external dependencies and proceed with the test by JUnit.To validate the informations, I've printed the attributes of the classes on my rule Check file:
package org.sonar.template.java.checks; import com.google.common.collect.ImmutableList; import org.sonar.check.Priority; import org.sonar.check.Rule; import org.sonar.plugins.java.api.semantic.Symbol; import org.sonar.plugins.java.api.semantic.Symbol.TypeSymbol; import org.sonar.plugins.java.api.IssuableSubscriptionVisitor; import org.sonar.plugins.java.api.tree.*; import org.sonar.plugins.java.api.tree.Tree.Kind; import java.util.List; @Rule( key = "SharedPreferencesRule", name = "Utilização de SharedPreferences no código", description = "Para cada utilização de SharedPreferences, é feito um alerta para revisar o que está sendo armazenado.", priority = Priority.CRITICAL, tags = {"attention point", "security"}) public class SharedPreferencesCheck extends IssuableSubscriptionVisitor { @Override public List<Kind> nodesToVisit() { return ImmutableList.of(Kind.METHOD_INVOCATION); } @Override public void visitNode(Tree tree){ System.out.println("====================== Kind Finded ======================"); MethodInvocationTree kindTree = (MethodInvocationTree) tree; Symbol symbol = (Symbol) kindTree.symbol(); TypeSymbol classe = symbol.owner().enclosingClass(); System.out.println("Name >>>>>>>>>>>>> " + symbol.name()); System.out.println("Enclosing >>>>>>>>>>>>> " + classe); if (classe != null && classe.equals("SharedPreferences")){ reportIssue(kindTree.firstToken(), "SharedPreferences sendo utilizado no código. Analisar!!"); } } }
I hope that it could help someone who is going throught the same or an similar problem.
If anyone can give a better explanation, would be really helpfull.
Thanks a lot!
相关问答
更多-
没有这样的功能,您的自定义规则负责计算所需的内容。 你可以找到一些实用的方法,比如context.getComplexityNodes(methodTree); 但那是一种极端情况。 No there is no such feature, it's the responsibility of your custom rules to compute what is required. You can find some utility methods like context.getComplexityN ...
-
在SonarQube分析期间分析另一个文件(自定义规则)(Analyze another file during SonarQube analysis (custom rule))[2023-02-14]
您可以使用语义模型来获取有关项目中定义的符号(类,方法,...)的信息。 分析类时,您可以访问ClassTree ,因此您可以测试其超类是否存在这样的注释 ClassTree classTree = (ClassTree) tree; Symbol.TypeSymbol classSymbol = classTree.symbol(); Type superClass = classSymbol.superClass(); SymbolMetadata superClassMetadata = superC ... -
SonarQube:创建自定义规则以在类中获取自定义注释(SonarQube: Create custom rules to get custom annotations in a class)[2023-01-18]
我假设您正在遵循本指南并在测试中运行检查https://docs.sonarqube.org/display/PLUG/Writing+Custom+Java+Rules+101 。 要为测试提供依赖关系,您也可以 将jar放在target/test-jars目录中(请参阅https://github.com/SonarSource/sonar-custom-rules-examples/blob/master/java-custom-rules/pom,了解如何使用maven依赖插件。 xml#L147 ... -
简而言之:SonarJava不支持自定义检查POM文件(即自定义PomCheck )。 更多细节 根据Java自定义规则教程 ,必须通过将它们提供给getJavaChecks (针对源文件进行检查)或getJavaTestChecks (针对测试文件进行检查)来激活自定义规则。 问题是pom.xml文件不属于这两个类别中的任何一个,它们属于“XML文件桶”,对其进行了特定的规则检查。 可视化的一个好方法是浏览SonarJava的CheckList.java,注意专用的getXmlChecks和getMave ...
-
SonarQube没有显示违规的原因是因为sonar-pmd-plugin中的违规记录器通过其密钥搜索规则。 因此, pmd-extensions.xml文件中的key属性必须等于custom_rules.xml规则的name属性 通过将pmd-extensions.xml内容更改为以下内容来修复提供的示例:
RuleJavaAssert Avoid assert in production ... -
在SonarQube 6.3中将自定义规则类型声明为漏洞(Declare custom rule type as Vulnerability in SonarQube 6.3)[2023-03-23]
有一种方法可以使用一些特殊标记来设置规则类型。 标签“bug”表示输入“bug” 标记“安全”表示键入“漏洞” 所以试试例子: tags = {"suspicious", "bug"} 注意:这在API Javadoc中有记录(但很难找到我承认) There is a way to set the rule type using some special tags. Tag "bug" means type "bug" Tag "security" means type "vulnerability" S ... -
得到它了! 问题在于导入SonarQube的依赖关系。 我在我的pom.xml中添加了很多Android依赖项,并在更改后进行测试。 在此之后,仍然没有工作。 在一些搜索中,我发现负责解释类的负责人是android-maven-plugin。 当我通过Eclipse的pom接口导入时,总会出现一些错误,说明缺少一些arctifa。 发生此问题是因为远程依赖项已损坏或不存在,因此我从依赖项下载了该jar文件并创建了一个文件target/test-jars 。 有了这个,maven识别了外部依赖关系,并继续进行 ...
-
如何在SonarQube 4.5的插件中注册自定义规则?(How to register custom rules in a plugin for SonarQube 4.5?)[2022-05-18]
对于使用最新API的SonarQube插件,还有其他的例子吗? 不,我今天遇到了完全相同的问题,找不到任何问题。 但这里是解决方案: 创建一个实现RulesDefinition的类 - >它是一个ServerExtension它的唯一目的是让你的自定义规则出现在SonarQube的用户界面中,如果你明确提供了一个定义(以编程方式,或在XML文件中,或通过注释)。 该扩展在服务器启动时加载。 创建一个实现BatchExtension和JavaFileScannersFactory的类 - >其目的是通过返回规 ... -
GUI仅适用于XPATH,不能与java规则一起使用。 要为正则表达式模式匹配添加自定义规则,必须创建新的插件jar。 The GUI is only for XPATH and could not be used with a java rule. To add a custom rule for regex pattern matching, new plugin jar has to be created.
-
您正在寻找SONAR-5366令人遗憾的是,可以备份和恢复尚未实现的规则自定义 。 You're looking for SONAR-5366 Make it possible to back up and restore customizations of rules, which is not yet implemented, unfortunately.