- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是最新的 phaser.io 版本,但我收到一个可能与这些行有关的错误:
Phaser.Rectangle.contains(e.body, game.input.activePointer.x, game.input.activePointer.y);
和
shapesprite.body.setSize(30, 30, 0, 0);
我已经注释掉了上面的行,它有点起作用,但后来我得到了这个错误:
Game.js:195 Uncaught TypeError: Cannot read property 'setSize' of null
我想我的 sprite 有 18 个部分要通读。
我的代码:
gameObj.Game = function (game) {
//step 1
var myTime;
var gameSeconds; //total game seconds
var timerSeconds = "0"; //current timer in seconds
var secondsLeft; //total game seconds - current timer second
var points;
var pointsShow;
};
var tile_size = 69;
gameObj.Game.prototype = {
create: function () {
var border = this.add.sprite(this.world.centerX, this.world.centerY, 'border');
border.anchor.setTo(0.5, 0.5);
var stroke = this.add.sprite(this.world.centerX + 30, this.world.centerX - 450, 'stroke');
points = 0;
gameObj.finalScore = points;
var currentTarg = this.add.sprite(this.world.centerX + 200, this.world.centerX - 125, 'currenttarget');
this.shapes = this.add.group();
this.shapes.createMultiple(36, 'shapesprite');
this.shapes.setAll('inputEnabled', true);
this.shapes.setAll('input.useHandCursor', true);
var progressbackground = this.add.sprite(this.world.centerX + 90, this.world.centerX - 380, 'progressbg');
var myPercentStyle = {
font: "400 24px Architects Daughter",
fill: "#000",
align: "center"
};
pointsShow = this.add.text(this.world.centerX + 195, this.world.centerX - 300, points + '%', myPercentStyle);
var myProgress = "Progress of \nShape Painting"
var myProgressStyle = {
font: "400 18px Architects Daughter",
fill: "#000",
align: "center"
};
var myProgressShow = this.add.text(this.world.centerX + 160, this.world.centerX - 360, myProgress, myProgressStyle);
var currentTargText = "Mix colors and make a:"
var currentTargStyle = {
font: "400 18px Architects Daughter",
fill: "#000",
align: "center"
};
var currentTargShow = this.add.text(this.world.centerX + 135, this.world.centerX - 220, currentTargText, currentTargStyle);
var targetBg = this.add.sprite(this.world.centerX + 140, this.world.centerX - 190, 'targetbg');
var timerbackground = this.add.sprite(this.world.centerX + 90, this.world.centerY + 120, 'timerbg');
var myTimeText = "Time until Art Show:";
var myTimeTextStyle = {
font: "400 24px Architects Daughter",
fill: "#000",
align: "center"
};
var myTimeShow = this.add.text(this.world.centerX + 110, this.world.centerX + 35, myTimeText, myTimeTextStyle);
var myTime = "2:00"
var myTimeStyle = {
font: "400 35px Architects Daughter",
fill: "#000",
align: "center"
};
myTimerShow = this.add.text(this.world.centerX + 190, this.world.centerX + 70, myTime, myTimeStyle);
tmpWinnerBtn = this.add.button(100, 200, 'btn_winner', this.winnerFun, this, 1, 0, 2);
tmpWinnerBtn.anchor.setTo(0.5, 0.5);
tmpLoserBtn = this.add.button(200, 200, 'btn_loser', this.loserFun, this, 1, 0, 2);
tmpLoserBtn.anchor.setTo(0.5, 0.5);
//timevars
tmpPointsBtn = this.add.button(300, 100, 'points_btn', this.pointsIncrease, this, 1, 0, 2);
gameSeconds = 120;
timerSeconds = 0;
secondsLeft = 0;
//create timer object
timerObj = this.game.time.create(false);
//set a timer event to occur every 1 second
timerObj.loop(1000, this.updateTimer, this);
//start the timer running
timerObj.start();
// this.combo_s = this.game.add.audio('combo');
this.clicked = false;
this.count = 0;
this.moves = 0;
this.type = -1;
this.deleted_shapes = [];
this.pos_i = -1;
this.pos_j = -1;
this.offset_x = 120;
this.offset_y = 150;
this.next_time = 0;
score = 0;
//this.width=69;
this.build_world();
},
update: function () {
this.shapes.forEachAlive(function (e) {
if (e.scale.x == 2) e.kill();
}, this);
if (game.input.activePointer.isDown && game.time.now > this.next_time) {
this.clicked = true;
this.try_select_a_shapesp();
}
if (game.input.activePointer.isUp && this.clicked) {
if (this.count > 1) {
this.remove_selected_shapes();
this.move_shapes_down();
this.add_missing_shapes();
} else
this.unselect_all_shapes();
//this.next_time = game.time.now + 300;
this.count = 0;
this.clicked = false;
this.type = -1;
this.pos_i = -1;
this.pos_j = -1;
}
},
build_world: function () {
for (var i = 0; i < 6; i++)
for (var j = 0; j < 6; j++)
this.add_shapesp(i, j, true);
},
add_shapesp: function (i, j, type) {
var shapesprite = this.shapes.getFirstExists(false);
var r = rand(3);
if (r == 1) shapesprite.frame = 2;
else if (r == 3) shapesprite.frame = 6;
else if (r == 2) shapesprite.frame = 4;
// else if (r == 2) shapesprite.frame = 4;
// else if (r == 3) shapesprite.frame = 6;
// else if (r == 4) shapesprite.frame = 8;
// else if (r == 5) shapesprite.frame = 10;
// // else if (r == 6) shapesprite.frame = 12;
// else if (r == 7) shapesprite.frame = 14;
// // else if (r == 8) shapesprite.frame = 16;
// else if (r == 9) shapesprite.frame = 18;
// // else if (r == 10) shapesprite.frame = 20;
// else if (r == 11) shapesprite.frame = 22;
// // else if (r == 12) shapesprite.frame = 24;
// else if (r == 13) shapesprite.frame = 26;
// else if (r == 14) shapesprite.frame = 28;
// // else if (r == 15) shapesprite.frame = 30;
// else if (r == 16) shapesprite.frame = 32;
// else if (r == 17) shapesprite.frame = 34;
// else if (r == 18) shapesprite.frame = 36;
shapesprite.anchor.setTo(0.5, 0.5);
shapesprite.selected = false;
shapesprite.pos_i = i;
shapesprite.pos_j = j;
shapesprite.move_y = 0;
shapesprite.move_x = 1;
shapesprite.body.setSize(30, 30, 0, 0);
shapesprite.alpha = 1;
shapesprite.scale.setTo(5, 1);
shapesprite.alive2 = true;
shapesprite.reset(this.offset_x + j * tile_size, this.offset_y + i * tile_size);
if (type)
this.game.add.tween(shapesprite.scale).delay(j * 100 + 1).to({
x: 1,
y: 1
}, 400).start();
else
this.game.add.tween(shapesprite.scale).delay(400).to({
x: 1,
y: 1
}, 400).start();
},
try_select_a_shapesp: function (e) {
this.shapes.forEachAlive(function (e) {
var bool = Phaser.Rectangle.contains(e.body, game.input.activePointer.x, game.input.activePointer.y);
if (e.selected || !bool) {
//console.log('hi');
return;
}
if (this.type == -1)
this.type = e.frame;
if (this.type == e.frame && this.in_range(e))
this.select_a_shapesp(e);
else
this.unselect_all_shapes();
}, this);
},
select_a_shapesp: function (e) {
e.selected = true;
e.frame += 1;
this.count += 1;
this.pos_j = e.pos_j;
this.pos_i = e.pos_i;
// this.increase_bar();
},
remove_selected_shapes: function (e) {
this.shapes.forEachAlive(function (e) {
if (!e.selected)
return;
this.game.add.tween(e.scale).to({
x: 2,
y: 2
}, 300).start();
this.game.add.tween(e).to({
alpha: 0
}, 300).start();
this.deleted_shapes.push({
i: e.pos_i,
j: e.pos_j
});
e.alive2 = false;
}, this);
},
unselect_all_shapes: function () {
this.count = 0;
this.shapes.forEachAlive(function (e) {
if (e.selected) {
e.selected = false;
e.frame -= 1;
}
}, this);
this.clear_bar();
},
move_shapes_down: function () {
for (var i = 0; i < this.deleted_shapes.length; i++) {
var tmp_i = this.deleted_shapes[i].i;
var tmp_j = this.deleted_shapes[i].j;
this.shapes.forEachAlive(function (e) {
if (!e.selected && e.pos_j == tmp_j && e.pos_i < tmp_i)
e.move_y += tile_size;
}, this);
}
this.shapes.forEachAlive(function (e) {
if (e.move_y == 0)
return;
var coef = e.move_y / tile_size;
e.pos_i += coef;
this.add.tween(e).delay(100).to({
y: e.y + e.move_y
}, 100 * coef).start();
e.move_y = 0;
}, this);
this.deleted_shapes = [];
},
add_missing_shapes: function () {
var min = [6, 6, 6, 6, 6, 6];
this.shapes.forEachAlive(function (e) {
if (e.pos_i < min[e.pos_j] && e.alive2)
min[e.pos_j] = e.pos_i;
}, this);
for (var i = 0; i < 6; i++)
for (var j = 0; j < min[i]; j++)
this.add_shapesp(j, i, false);
},
update_score_and_labels: function () {
this.clear_bar();
this.game.state.start('End');
},
in_range: function (d) {
if (this.pos_j == -1) return true;
return (this.pos_j - 1 == d.pos_j && this.pos_i == d.pos_i) ||
(this.pos_j + 1 == d.pos_j && this.pos_i == d.pos_i) ||
(this.pos_j == d.pos_j && this.pos_i - 1 == d.pos_i) ||
(this.pos_j == d.pos_j && this.pos_i + 1 == d.pos_i);
},
clear_bar: function () {
this.game.add.tween(this.progress).to({
}, 300).start();
},
add_tuto: function () {
this.tuto = this.game.add.button(0, 0, 'tuto', this.remove_tuto, this);
},
updateTimer: function () {
//console.log('hola');
timerSeconds++;
if (timerSeconds <= gameSeconds) {
secondsLeft = gameSeconds - timerSeconds;
//
displayMin = Math.floor(secondsLeft / 60) % 60;
displaySec = Math.floor(secondsLeft) % 60;
//
if (displayMin < 10) {
displayMin = "" + displayMin;
}
if (displaySec < 10) {
displaySec = "0" + displaySec;
}
myTimerShow.setText(displayMin + ":" + displaySec);
} else {
timerSeconds = 0;
this.loserFun();
}
},
pointsIncrease: function () {
//console.log("increase");
gameObj.finalScore += 10;
points = gameObj.finalScore;
pointsShow.setText(points + "%");
if (points == 100) {
this.game.state.start('Winner');
}
},
winnerFun: function () {
gameObj.finalTime = timerSeconds;
this.state.start('Winner');
},
loserFun: function () {
gameObj.finalTime = timerSeconds;
this.state.start('Loser');
}
};
最佳答案
在您的代码中,您没有在shapesprite
上启用物理。在您首先执行此操作之前,他们不会有您可以访问的机构:
这是一种方法:http://phaser.io/examples/v2/arcade-physics/group-vs-self
关于javascript - Phaser.io 中的 setSize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39183740/
我想做的是让 JTextPane 在 JPanel 中占用尽可能多的空间。对于我使用的 UpdateInfoPanel: public class UpdateInfoPanel extends JP
我在 JPanel 中有一个 JTextArea,我想将其与 JScrollPane 一起使用。我正在使用 GridBagLayout。当我运行它时,框架似乎为 JScrollPane 腾出了空间,但
我想在 xcode 中实现以下功能。 我有一个 View Controller 。在这个 UIViewController 中,我有一个 UITabBar。它们下面是一个 UIView。将 UITab
有谁知道Firebird 2.5有没有类似于SQL中“STUFF”函数的功能? 我有一个包含父用户记录的表,另一个表包含与父相关的子用户记录。我希望能够提取用户拥有的“ROLES”的逗号分隔字符串,而
我想使用 JSON 作为 mirth channel 的输入和输出,例如详细信息保存在数据库中或创建 HL7 消息。 简而言之,输入为 JSON 解析它并输出为任何格式。 最佳答案 var objec
通常我会使用 R 并执行 merge.by,但这个文件似乎太大了,部门中的任何一台计算机都无法处理它! (任何从事遗传学工作的人的附加信息)本质上,插补似乎删除了 snp ID 的 rs 数字,我只剩
我有一个以前可能被问过的问题,但我很难找到正确的描述。我希望有人能帮助我。 在下面的代码中,我设置了varprice,我想添加javascript变量accu_id以通过rails在我的数据库中查找记
我有一个简单的 SVG 文件,在 Firefox 中可以正常查看 - 它的一些包装文本使用 foreignObject 包含一些 HTML - 文本包装在 div 中:
所以我正在为学校编写一个 Ruby 程序,如果某个值是 1 或 3,则将 bool 值更改为 true,如果是 0 或 2,则更改为 false。由于我有 Java 背景,所以我认为这段代码应该有效:
我做了什么: 我在这些账户之间创建了 VPC 对等连接 互联网网关也连接到每个 VPC 还配置了路由表(以允许来自双方的流量) 情况1: 当这两个 VPC 在同一个账户中时,我成功测试了从另一个 La
我有一个名为 contacts 的表: user_id contact_id 10294 10295 10294 10293 10293 10294 102
我正在使用 Magento 中的新模板。为避免重复代码,我想为每个产品预览使用相同的子模板。 特别是我做了这样一个展示: $products = Mage::getModel('catalog/pro
“for”是否总是检查协议(protocol)中定义的每个函数中第一个参数的类型? 编辑(改写): 当协议(protocol)方法只有一个参数时,根据该单个参数的类型(直接或任意)找到实现。当协议(p
我想从我的 PHP 代码中调用 JavaScript 函数。我通过使用以下方法实现了这一点: echo ' drawChart($id); '; 这工作正常,但我想从我的 PHP 代码中获取数据,我使
这个问题已经有答案了: Event binding on dynamically created elements? (23 个回答) 已关闭 5 年前。 我有一个动态表单,我想在其中附加一些其他 h
我正在尝试找到一种解决方案,以在 componentDidMount 中的映射项上使用 setState。 我正在使用 GraphQL连同 Gatsby返回许多 data 项目,但要求在特定的 pat
我在 ScrollView 中有一个 View 。只要用户按住该 View ,我想每 80 毫秒调用一次方法。这是我已经实现的: final Runnable vibrate = new Runnab
我用 jni 开发了一个 android 应用程序。我在 GetStringUTFChars 的 dvmDecodeIndirectRef 中得到了一个 dvmabort。我只中止了一次。 为什么会这
当我到达我的 Activity 时,我调用 FragmentPagerAdapter 来处理我的不同选项卡。在我的一个选项卡中,我想显示一个 RecyclerView,但他从未出现过,有了断点,我看到
当我按下 Activity 中的按钮时,会弹出一个 DialogFragment。在对话框 fragment 中,有一个看起来像普通 ListView 的 RecyclerView。 我想要的行为是当
我是一名优秀的程序员,十分优秀!