Pixi纹理精灵和动画实现

<template>
  <div>

  </div>
</template>

<script setup>
import * as PIXI from 'pixi.js'
const app = new PIXI.Application({
  width:window.innerWidth,
  height:window.innerHeight,
  backgroundColor:0x1099bb,
  resolution:window.devicePixelRatio ||1,
  antialias:true, //抗锯齿
});
document.body.appendChild(app.view);

// 创建纹理
const texture = PIXI.Texture.from("./texture/剑.png")

// 创建一个精灵
const sprite = new PIXI.Sprite(texture)

// 设置精灵锚点
sprite.anchor.set(0.5, 0.5)

// 设置精灵的位置
sprite.x = app.screen.width / 2
sprite.y = app.screen.height / 2

// 设置精灵旋转45度
sprite.rotation = Math.PI/4

// 设置精灵缩放
sprite.scale.set(2, 2)

// 设置精灵透明度
sprite.alpha = 0.8

// 设置精灵的锚点
 app.stage.addChild(sprite)

// ticker实现动画
app.ticker.add((delta)=>{
  sprite.rotation += 0.01 * delta
})



</script>

<style>
*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
canvas{
  width: 100vw;
  height: 100vh;
  position: fixed;
  top: 0;
  left: 0;
}
</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值