首页 \ 问答 \ 无法让Phaser工作(Can't Get Phaser To Work)

无法让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
更新时间:2023-11-28 11:11

最满意答案

得到它了!

问题在于导入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!

相关问答

更多

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)