代码拉取完成,页面将自动刷新
import router from '@ohos.router'
@Entry
@Component
struct AnimationPage {
// 小鱼坐标
@State fishX: number = 200
@State fishY: number = 180
// 小鱼角度
@State angle: number = 0
// 小鱼图片
@State src: Resource = $r('app.media.fish')
// 是否开始游戏
@State isBegin: boolean = false
build() {
Row() {
Stack(){
// 返回按钮
Button('返回')
.position({x:0, y: 0})
.backgroundColor('#20101010')
.onClick(() => {
// 返回上一页
router.back()
})
if(!this.isBegin){
// 开始按钮
Button('开始游戏')
.onClick(() => {
animateTo(
{duration: 1000},
() => {
// 点击后显示小鱼
this.isBegin = true
}
)
})
}else{
// 小鱼图片
Image(this.src)
.position({x: this.fishX - 20, y: this.fishY - 20})
.rotate({angle:this.angle, centerX: '50%', centerY: '50%'})
.width(40)
.height(40)
//.animation({duration: 500, curve: Curve.Smooth})
.transition({
type: TransitionType.Insert,
opacity: 0,
translate: {x: -250}
})
}
// 操作按钮
Row(){
Button('←').backgroundColor('#20101010')
.onClick(() => {
animateTo(
{duration: 500},
() => {
this.fishX -= 20
this.src = $r('app.media.fish_rev')
}
)
})
Column({space: 40}){
Button('↑').backgroundColor('#20101010')
.onClick(() => {
animateTo(
{duration: 500},
() => {
this.fishY -= 20
}
)
})
Button('↓').backgroundColor('#20101010')
.onClick(() => {
animateTo(
{duration: 500},
() => {
this.fishY += 20
}
)
})
}
Button('→').backgroundColor('#20101010')
.onClick(() => {
animateTo(
{duration: 500},
() => {
this.fishX += 20
this.src = $r('app.media.fish')
}
)
})
}
.height(240)
.width(240)
.justifyContent(FlexAlign.Center)
.position({x:0,y:120})
}
.height('100%').width('100%')
}
.height('100%')
.width('100%')
.backgroundImage($r('app.media.sea'))
.backgroundImageSize({height: '105%', width: '100%'})
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。