// 加载狐狸
let fox = pixiTexture.from('https://img.alicdn.com/imgextra/i1/39767794/O1CN01t13qMt27RhbmdFfsh_!!39767794.png')
let firfox = new pixiSprite(fox)
application.stage.addChild(firfox)
//移动狐狸
let flag = false
firfox.interactive = true
firfox.buttonMode = true
firfox.anchor.set(0.5) //设置中心点
firfox.x = application.screen.width / 2 //狐狸初始位置
firfox.y = application.screen.height - 300
// 滑动狐狸
firfox.on('touchstart', () => {
flag = true
})
.on('touchmove', (e) => {
if (flag) {
if (e.data.global.x > 115 / 2 && e.data.global.x < application.screen.width - 115 / 2 && e.data.global.y > 111 / 2 && e.data.global.y < application.screen.height - 111 / 2) {
firfox.x = e.data.global.x
firfox.y = e.data.global.y
} else {
}
}
})
.on('touchend', () => {
flag = false
})
.on('touchendoutside', () => {
flag = false
})
pixi.js 拖拽功能
最新推荐文章于 2022-10-10 22:20:54 发布