游戏引擎phaser.js3的使用之玩家和静态物理组碰撞

玩家和静态物理组都加载好了,那就应该开始操作玩家动态和静态之间的碰撞了

下面是通过点击图片按钮来操作碰撞的

sky.on('pointerdown', function () {

console.log('图片被点击了!');

})

图片点击后让动态的玩家和静态的物理组碰撞,就可以这么加

that.physics.add.overlap(player,platforms, collectStar, null, this)

在回调collectStar中做撞击后的操作

function collectStar (player, star){

star.disableBody(true, true);//碰撞后静态物体消失

可以操作撞击后静态物体消失,当然也可以做其他的操作

比如玩家和静态物理碰撞,玩家重新回到原来的位置,同时碰撞的静态做个动画操作

that.tweens.add({

targets: player,

x: player.x,

y: 100,//设置玩家向下的高度

duration: 500,

ease: 'Linear',

onComplete: function () {

// 回到原来的位置

tween = that.tweens.add({

targets: player,

x: player.x,

y: 10,

duration: 1000,

ease: 'Linear'

});

}

})

上面的这种操作就是玩家的动态,就是玩家向下后回到原来的位置,静态物理组也可以做这样的操作,大家可以照着改一改哦,有不懂的可以来问的,+V 1606725537。!!!!!

相关推荐
ue星空1 小时前
【Godot】更换编辑器外观主题
编辑器·游戏引擎·godot
fanfan_hongyun2 小时前
unity 与cad 坐标系映射
unity·游戏引擎
神码编程5 小时前
【Unity】 HTFramework框架(七十)MultiChoiceDropdown可多选的下拉菜单
unity·游戏引擎·ugui·dropdown·下拉菜单
淡海水6 小时前
15-07-YooAsset面试篇-Unity性能优化与内存管理
java·unity·面试·性能优化·c#·游戏引擎
ue星空6 小时前
【Godot】AudioStreamPlayer2D音频播放
游戏引擎·音视频·godot
淡海水2 天前
15-02-YooAsset面试篇-Unity架构设计与源码
java·unity·面试·c#·游戏引擎·yooasset
郝学胜-神的一滴2 天前
中级OpenGL教程 030:gl_FragCoord解锁区域渲染与深度可视化新姿势
c++·unity·游戏引擎·图形渲染·unreal engine·opengl
xcLeigh5 天前
Unity基础:Light灯光组件入门——Directional Light、Point Light与Spotlight
unity·游戏引擎·教程