[0]发现bug,update大问题!!!!!!!!! 2.13版本
import { TableMgr } from "../common/table/TableMgr";
import { BaseWin } from "../common/windows/BaseWin";
import Const from "../Const";
import UIMain from "../ui/Game/UIMain";
export default class GameWnd extends BaseWin {
public view: UIMain;
/** 角色 */
private character: Laya.Sprite
/** 角色刚体*/
private rig: Laya.RigidBody
/** 医疗包*/
private addhp: Laya.Sprite
/** 速度包*/
private addseed: Laya.Sprite
/** 跳跃高度包*/
private addHight: Laya.Sprite
/** 碰撞組*/
private collision: []
/** 地面*/
private plane: Laya.Sprite
/** 是否向左移动*/
private isleft: boolean = false;
/** 是否向右移动*/
private isright: boolean = false;
constructor() {
super();
this.packageName = "Game";
this.resName = "Main";
this.isFullWindow = true;
}
/**
* 初始化组件 第一次new的时候执行
*/
onConstruct() {
}
/**
* 打开窗口就调用
*/
onShow() {
super.onShow()
this.character = this.view.m_character.displayObject
/** 给地面添加碰撞器*/
this.plane = this.view.m_plane.displayObject
let planecoll = this.plane.addComponent(Laya.BoxCollider)
let chacoll = this.character.addComponent(Laya.BoxCollider)
planecoll.x = 0;
planecoll.y = 0;
planecoll.width = 2775
planecoll.height = 89
chacoll.width = 80
chacoll.height = 120
this.character.addComponentIntance
/** 给物体添加刚体属性*/
this.rig = this.character.addComponent(Laya.RigidBody)
let p = this.plane.addComponent(Laya.RigidBody) as Laya.RigidBody
this.character.pivot(this.view.m_character.width/2, this.view.m_character.height/2)
p.type = "static"
this.character.pivot(this.view.m_character.x, this.view.m_character.y)
// rig.gravityScale = 0.2
this.rig.allowRotation = false
this.rig.gravityScale = 6
this.view.m_jump.onClick(this, this.onJump)
this.view.m_left.on(Laya.Event.MOUSE_DOWN,this, this.onleft)
this.view.m_left.on(Laya.Event.MOUSE_UP,this, this.notleft)
this.view.m_right.on(Laya.Event.MOUSE_DOWN,this, this.onright)
this.view.m_right.on(Laya.Event.MOUSE_UP,this, this.notright)
this.view.m_left.onClick(this, this.onleft)
}
onJump() {
this.rig.applyForceToCenter({x:0,y:-60000})
}
onleft() {
this.isleft = true
this.isright = false
}
notleft() {
this.isleft = false
console.log(this.isleft);
/**打印是false,但是update还是在执行*/
}
onright(){
this.isright = true
this.isleft =false
}
notright(){
this.isright = false
}
/**
* 关闭窗口调用
*/
onHide() {
console.log("GameWnd onHide");
}
private onBtnClick() {
console.log("onBtnClick");
}
update(){
if(this.isleft == true){
console.log('zuo');
this.rig.applyLinearImpulse({x:this.view.m_character.width/2,y:this.view.m_character.height/2},{x:-10,y:0})
}
if(this.isright == true){
console.log('you');
this.rig.applyLinearImpulse({x:this.view.m_character.width/2,y:this.view.m_character.height/2},{x:10,y:0})
}
}
}
import { BaseWin } from "../common/windows/BaseWin";
import Const from "../Const";
import UIMain from "../ui/Game/UIMain";
export default class GameWnd extends BaseWin {
public view: UIMain;
/** 角色 */
private character: Laya.Sprite
/** 角色刚体*/
private rig: Laya.RigidBody
/** 医疗包*/
private addhp: Laya.Sprite
/** 速度包*/
private addseed: Laya.Sprite
/** 跳跃高度包*/
private addHight: Laya.Sprite
/** 碰撞組*/
private collision: []
/** 地面*/
private plane: Laya.Sprite
/** 是否向左移动*/
private isleft: boolean = false;
/** 是否向右移动*/
private isright: boolean = false;
constructor() {
super();
this.packageName = "Game";
this.resName = "Main";
this.isFullWindow = true;
}
/**
* 初始化组件 第一次new的时候执行
*/
onConstruct() {
}
/**
* 打开窗口就调用
*/
onShow() {
super.onShow()
this.character = this.view.m_character.displayObject
/** 给地面添加碰撞器*/
this.plane = this.view.m_plane.displayObject
let planecoll = this.plane.addComponent(Laya.BoxCollider)
let chacoll = this.character.addComponent(Laya.BoxCollider)
planecoll.x = 0;
planecoll.y = 0;
planecoll.width = 2775
planecoll.height = 89
chacoll.width = 80
chacoll.height = 120
this.character.addComponentIntance
/** 给物体添加刚体属性*/
this.rig = this.character.addComponent(Laya.RigidBody)
let p = this.plane.addComponent(Laya.RigidBody) as Laya.RigidBody
this.character.pivot(this.view.m_character.width/2, this.view.m_character.height/2)
p.type = "static"
this.character.pivot(this.view.m_character.x, this.view.m_character.y)
// rig.gravityScale = 0.2
this.rig.allowRotation = false
this.rig.gravityScale = 6
this.view.m_jump.onClick(this, this.onJump)
this.view.m_left.on(Laya.Event.MOUSE_DOWN,this, this.onleft)
this.view.m_left.on(Laya.Event.MOUSE_UP,this, this.notleft)
this.view.m_right.on(Laya.Event.MOUSE_DOWN,this, this.onright)
this.view.m_right.on(Laya.Event.MOUSE_UP,this, this.notright)
this.view.m_left.onClick(this, this.onleft)
}
onJump() {
this.rig.applyForceToCenter({x:0,y:-60000})
}
onleft() {
this.isleft = true
this.isright = false
}
notleft() {
this.isleft = false
console.log(this.isleft);
/**打印是false,但是update还是在执行*/
}
onright(){
this.isright = true
this.isleft =false
}
notright(){
this.isright = false
}
/**
* 关闭窗口调用
*/
onHide() {
console.log("GameWnd onHide");
}
private onBtnClick() {
console.log("onBtnClick");
}
update(){
if(this.isleft == true){
console.log('zuo');
this.rig.applyLinearImpulse({x:this.view.m_character.width/2,y:this.view.m_character.height/2},{x:-10,y:0})
}
if(this.isright == true){
console.log('you');
this.rig.applyLinearImpulse({x:this.view.m_character.width/2,y:this.view.m_character.height/2},{x:10,y:0})
}
}
}
没有找到相关结果
已邀请:
1 个回复
Laya_Fred
赞同来自: