版本cocos creator 1.9.1
问题:
cc.director.getPhysicsManager().enabled = true
this.rb = this.rb = getComponent(cc.RigidBody)
使用this.rb.linearVelocity.x = 800带.x运行不生效,使用this.rb.linearVelocity = cc.p(800,0) 不带才生效,难道这个值只能通过对.linearVelocity来赋vec2值,而不是直接用.x来赋值吗?
const moveLeft = 1
const moveRight = 2
cc.Class({
extends: cc.Component,
onLoad() {
this.moveFlag = 0
cc.director.getPhysicsManager().enabled = true
this.rb = this.getComponent(cc.RigidBody)
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_DOWN, this.onKeyDown, this)
cc.systemEvent.on(cc.SystemEvent.EventType.KEY_UP, this.onKeyUp, this)
},
onKeyDown(event) {
switch (event.keyCode) {
case cc.KEY.a:
case cc.KEY.left:
this.moveFlag = moveLeft
this.rb.linearVelocity = cc.p(-800,0);
break
(…略)