createFromObjects()在phaser中不起作用?(createFromObjects() not working in phaser?)
我正在尝试用移相器制作游戏。 我创建了一个带有对象层的tilemap。 但是,当我尝试将对象层中的对象添加到组“checkers”时,重叠不起作用。 这是我的代码:
function preload() { game.load.spritesheet("bird","assets/flappybird.png",92,64,3); game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/obstacle.png'); game.load.image('checktiles', 'assets/empty.png'); game.stage.backgroundColor = '#c9c9c9'; } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('map'); //OBSTACLES map.addTilesetImage('obstacle', 'tiles'); layer = map.createLayer('Tilelaag 1'); layer.resizeWorld(); map.setCollisionBetween(1, 12); //CHECKERS checkers = game.add.group(); checkers.enableBody=true; map.createFromObjects('Object Checkers', 5, 'checktiles', 0, true, false, checkers); //PLAYER player=game.add.sprite(92,game.world.heigth-300,"bird"); player.scale.setTo(0.5,0.5); game.physics.arcade.enable(player); player.body.gravity.y=300; player.animations.add("fly",[0,1,2],10,true); player.body.collideWorldBounds = true; player.body.velocity.x=150; //CURSORS cursors=game.input.keyboard.createCursorKeys(); spacebar=game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); //CAMERA game.camera.follow(player); } function update() { var hit=game.physics.arcade.collide(layer,player); game.physics.arcade.overlap(player, checkers,Addpoint,null,this); player.animations.play("fly"); if(spacebar.isDown) { player.body.velocity.y = -150; } if(hit) { game.state.restart(); } } function Addpoint() { console.log("Called"); }
I' am trying to make a game in phaser. I have created a tilemap, with an objectlayer. However when I' am trying to add an object from the object layer to the group "checkers" the overlap doesn't work. Here is my code:
function preload() { game.load.spritesheet("bird","assets/flappybird.png",92,64,3); game.load.tilemap('map', 'assets/map.json', null, Phaser.Tilemap.TILED_JSON); game.load.image('tiles', 'assets/obstacle.png'); game.load.image('checktiles', 'assets/empty.png'); game.stage.backgroundColor = '#c9c9c9'; } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); map = game.add.tilemap('map'); //OBSTACLES map.addTilesetImage('obstacle', 'tiles'); layer = map.createLayer('Tilelaag 1'); layer.resizeWorld(); map.setCollisionBetween(1, 12); //CHECKERS checkers = game.add.group(); checkers.enableBody=true; map.createFromObjects('Object Checkers', 5, 'checktiles', 0, true, false, checkers); //PLAYER player=game.add.sprite(92,game.world.heigth-300,"bird"); player.scale.setTo(0.5,0.5); game.physics.arcade.enable(player); player.body.gravity.y=300; player.animations.add("fly",[0,1,2],10,true); player.body.collideWorldBounds = true; player.body.velocity.x=150; //CURSORS cursors=game.input.keyboard.createCursorKeys(); spacebar=game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); //CAMERA game.camera.follow(player); } function update() { var hit=game.physics.arcade.collide(layer,player); game.physics.arcade.overlap(player, checkers,Addpoint,null,this); player.animations.play("fly"); if(spacebar.isDown) { player.body.velocity.y = -150; } if(hit) { game.state.restart(); } } function Addpoint() { console.log("Called"); }
原文:https://stackoverflow.com/questions/42039879
更新时间:2023-11-29 15:11
最满意答案
那是因为你没有加载jQuery插件!
您需要加载此脚本:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
That's because you are not loading the jQuery plugin!!
You need to load this script:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
相关问答
更多-
它实际上需要包含Twitter Bootstrap的dropdown.js http://getbootstrap.com/2.3.2/components.html It actually requires inclusion of Twitter Bootstrap's dropdown.js http://getbootstrap.com/2.3.2/components.html
-
CSS Bootstrap下拉菜单(CSS Bootstrap Dropdown Menu)[2022-05-06]
你错放了CSS课程 应该只有一个.dropdown-menu,它包含所有.dropdown-menu-item元素Bootstrap Menu Ex。 belowe