当前位置: 首页 > news >正文

php网站开发介绍谷歌搜索引擎免费入口镜像

php网站开发介绍,谷歌搜索引擎免费入口镜像,深圳知名企业,珠海移动网站设计一、前言 近期我在学习鸿蒙应用开发,跟着B站UP主黑马程序员的视频教程做了一个小鱼动画应用,UP主提供的小鱼动画源代码仅仅实现了移动组件的功能,还存在一些问题,如默认进入页面是竖屏而页面适合横屏显示;真机测试发现…

一、前言

近期我在学习鸿蒙应用开发,跟着B站UP主黑马程序员的视频教程做了一个小鱼动画应用,UP主提供的小鱼动画源代码仅仅实现了移动组件的功能,还存在一些问题,如默认进入页面是竖屏而页面适合横屏显示;真机测试发现手机的状态栏影响到了返回键对按键事件的响应;方向键不能响应一直按着的操作;还有小鱼会移出屏幕范围。

之前已经解决了强制横屏和隐藏手机状态栏,这次则是通过一番研究,实现了按键一直按下时控制小鱼移动和限制小鱼移出屏幕这两个功能。

二、实现方法

1. 一直按下方向键时控制小鱼移动

实现这一功能是在方向键下添加onTouch方法,对按键一直按下事件进行响应。在onTouch方法中还需要判断TouchType.Down事件和TouchType.Up事件。在TouchType.Down事件时,添加animateTo方法,实现按键时一直控制小鱼移动(需要通过setInterval方法设置定时任务让animateTo方法定期执行)。在TouchType.Up事件时,通过clearInterval清除定时任务,小鱼就不会一直移动了。以向右按键为例,改造后的代码如下:

Button('→').backgroundColor('#20101010').onClick(() => {              animateTo({ duration: 500 },() => {this.src = $r('app.media.fish')this.fishX += this.speed})}).onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.taskId = setInterval(() => {animateTo({ duration: 500 },() => {                      this.src = $r('app.media.fish')this.fishX += this.speed})}, 200)}if (event.type === TouchType.Up) {clearInterval(this.taskId)this.taskId = -1}})}.height(240).width(240).justifyContent(FlexAlign.Center).position({ x: 0, y: 120 })

2.限制小鱼移出屏幕

实现了上面的代码后,一直按下方向键,小鱼终于可以一直移动了,但往一个方向一直移动就会移出屏幕,为让小鱼不移出屏幕,还需要对按键操作事件进行判断,检查当前小鱼的位置,只有小鱼在限制的范围内才能执行animateTo方法移动小鱼。

按下向左方向键:对小鱼的X坐标(this.fishX)进行判断。屏幕左侧边界的X值为0,小鱼的大小为40(this.fishSize)。this.fishX是小鱼图片中心点的坐标,则当小鱼接触到屏幕左侧边界时,小鱼的中心点X坐标值为20。本软件中设置的小鱼的移动速度为20(this.speed),因此,我设置的判断条件是当this.fishX >= this.fishSize时,才能执行animateTo方法。当this.fishX == 40时,再移动一次this.fishX就变成了20,此时小鱼图片的左侧边缘正好接触到屏幕左边界。

按下向上方向键:对小鱼的Y坐标(this.fishY)进行判断。屏幕上边界Y值为0,小鱼大小为40。原理和按下向左方向机一样。我设置的判断条件是当this.fishY >= this.fishSize时,才能执行animateTo方法。

对于屏幕下方的边界和屏幕右侧的边界判断需要导入模块 import display from '@ohos.display' ,并在页面的onPageShow方法获取屏幕的尺寸信息。

onPageShow() {// 获取旋转的方向,具体可以查看对应文档let orientation = window.Orientation.LANDSCAPE;// 获取屏幕尺寸信息let promise = display.getAllDisplays()promise.then((data) => {console.info('设备屏幕信息:' + JSON.stringify(data));console.info('testTag', '屏幕宽度px:' + JSON.stringify(data[0].width));console.info('testTag', '屏幕高度px:' + JSON.stringify(data[0].height));this.screenWidth = px2vp(data[0].width)this.screenHeight = px2vp(data[0].height)console.info('testTag', '屏幕宽度vp:' + JSON.stringify(this.screenWidth));console.info('testTag', '屏幕高度vp:' + JSON.stringify(this.screenHeight));}).catch((err) => {console.error('错误信息:' + JSON.stringify(err));})}

按下向右方向机:对小鱼的X坐标(this.fishX)进行判断。屏幕右侧边界的X值为变量this.screenHeight, 则判定语句为 this.fishX <= this.screenHeight - this.fishSize 。只有符合该条件是才执行animateTo方法。

按下向下方向机:对小鱼的Y坐标(this.fishY)进行判断。屏幕右侧边界的Y值为变量this.screenWidth, 则判定语句为 this.fishY <= this.screenWidth - this.fishSize 。只有符合该条件是才执行animateTo方法。

这些判断语句都要添加到方向键的onClick方法和onTouch方法。

三、完整源代码

最后上这个文件的完整源代码:

import router from '@ohos.router';
import window from '@ohos.window'; // 用于强制设为横屏
import display from '@ohos.display'@Entry
@Component
struct Aquarium1Page {onPageShow() {// 获取旋转的方向,具体可以查看对应文档let orientation = window.Orientation.LANDSCAPE;try {// 设置屏幕旋转globalThis.windowClass.setPreferredOrientation(orientation, (err) => {console.log('testTag', `onPageShow函数中setPreferredOrientation方法错误码为${err}`)});} catch (exception) {console.error('设置失败: ' + JSON.stringify(exception));}// 获取屏幕尺寸信息let promise = display.getAllDisplays()promise.then((data) => {console.info('设备屏幕信息:' + JSON.stringify(data));console.info('testTag', '屏幕宽度px:' + JSON.stringify(data[0].width));console.info('testTag', '屏幕高度px:' + JSON.stringify(data[0].height));this.screenWidth = px2vp(data[0].width)this.screenHeight = px2vp(data[0].height)console.info('testTag', '屏幕宽度vp:' + JSON.stringify(this.screenWidth));console.info('testTag', '屏幕高度vp:' + JSON.stringify(this.screenHeight));}).catch((err) => {console.error('错误信息:' + JSON.stringify(err));})}onPageHide() {// 获取旋转的方向,具体可以查看对应文档let orientation = window.Orientation.PORTRAIT;try {// 设置屏幕旋转globalThis.windowClass.setPreferredOrientation(orientation, (err) => {console.log('testTag', `onPageHide函数中setPreferredOrientation方法错误码为${err}`)});} catch (exception) {console.error('设置失败: ' + JSON.stringify(exception));}}// 小鱼的位置@State fishX: number = 200@State fishY: number = 180// 小鱼的大小fishSize: number = 40// 小鱼角度@State angle: number = 0// 小鱼图片@State src: Resource = $r('app.media.fish')// 是否开始游戏@State isBegin: boolean = false// 小鱼的速度speed: number = 20// 用于控制Interval的idtaskId: number = -1// 屏幕尺寸screenWidth: number = px2vp(2000)screenHeight: number = px2vp(1080)build() {Row() {Stack() {Button('返回').position({ x: 20, y: 20 }).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(this.fishSize).height(this.fishSize)//.animation({duration: 500, curve: Curve.Smooth}).transition({type: TransitionType.Insert,opacity: 0,translate: { x: -250 }})}// 操作按钮Row() {// 向左移动,小鱼身体不能超出屏幕范围Button('←').backgroundColor('#20101010').onClick(() => {if (this.fishX >= this.fishSize) {animateTo({ duration: 500 },() => {this.src = $r('app.media.fish_rev')this.fishX -= this.speed})}}).onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.taskId = setInterval(() => {animateTo({ duration: 500 },() => {if (this.fishX >= this.fishSize) {this.src = $r('app.media.fish_rev')this.fishX -= this.speed}})}, 200)}if (event.type === TouchType.Up) {clearInterval(this.taskId)this.taskId = -1}})Column({ space: 40 }) {// 向上和向下移动,小鱼的身体均不能超出屏幕范围Button('↑').backgroundColor('#20101010').onClick(() => {if (this.fishY >= this.fishSize) {animateTo({ duration: 500 },() => {this.fishY -= this.speed})}}).onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.taskId = setInterval(() => {animateTo({ duration: 500 },() => {if (this.fishY >= this.fishSize) {this.fishY -= this.speed}})}, 200)}if (event.type === TouchType.Up) {console.log("testTag", `停止向上,当前fishY为:${this.fishY}`)clearInterval(this.taskId)this.taskId = -1}})Button('↓').backgroundColor('#20101010').onClick(() => {if (this.fishY <= this.screenWidth - this.fishSize) {animateTo({ duration: 500 },() => {this.fishY += this.speed})}}).onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.taskId = setInterval(() => {animateTo({ duration: 500 },() => {if (this.fishY <= this.screenWidth - this.fishSize) {this.fishY += this.speed}})}, 200)}if (event.type === TouchType.Up) {console.log("testTag", `停止向下,当前fishY为:${this.fishY}`)clearInterval(this.taskId)this.taskId = -1}})}Button('→').backgroundColor('#20101010').onClick(() => {if (this.fishX <= this.screenHeight - this.fishSize) {animateTo({ duration: 500 },() => {this.src = $r('app.media.fish')this.fishX += this.speed})}}).onTouch((event: TouchEvent) => {if (event.type === TouchType.Down) {this.taskId = setInterval(() => {animateTo({ duration: 500 },() => {if (this.fishX <= this.screenHeight - this.fishSize) {this.src = $r('app.media.fish')this.fishX += this.speed}})}, 200)}if (event.type === TouchType.Up) {clearInterval(this.taskId)this.taskId = -1}})}.height(240).width(240).justifyContent(FlexAlign.Center).position({ x: 0, y: 120 })}.height('100%').width('100%')}.width('100%').height('100%').backgroundImage($r('app.media.underwater_cartoon')).backgroundImageSize({ height: '100%', width: '100%' })}
}

四、B站视频链接:

鸿蒙应用开发学习:改进小鱼动画实现按键一直按下时控制小鱼移动和限制小鱼移出屏幕-CSDN博客


文章转载自:
http://dinncoweevil.knnc.cn
http://dinncodragoon.knnc.cn
http://dinncotroubleshooter.knnc.cn
http://dinncofcia.knnc.cn
http://dinncopimozide.knnc.cn
http://dinncofallboard.knnc.cn
http://dinncocrimson.knnc.cn
http://dinncochairborne.knnc.cn
http://dinncolawbreaker.knnc.cn
http://dinncobield.knnc.cn
http://dinncodedication.knnc.cn
http://dinnconecroscopy.knnc.cn
http://dinncomaturation.knnc.cn
http://dinncoholloo.knnc.cn
http://dinnconarcose.knnc.cn
http://dinncoalive.knnc.cn
http://dinncocircumflect.knnc.cn
http://dinncomythoheroic.knnc.cn
http://dinncocentiliter.knnc.cn
http://dinncoabed.knnc.cn
http://dinncomachodrama.knnc.cn
http://dinncoconfirm.knnc.cn
http://dinncotammy.knnc.cn
http://dinncopandowdy.knnc.cn
http://dinncojansenism.knnc.cn
http://dinncohexachord.knnc.cn
http://dinncobayard.knnc.cn
http://dinncosulfazin.knnc.cn
http://dinncoprobationer.knnc.cn
http://dinncodisclose.knnc.cn
http://dinncotypesetter.knnc.cn
http://dinncorecusal.knnc.cn
http://dinncobarbola.knnc.cn
http://dinncomuroran.knnc.cn
http://dinncounplug.knnc.cn
http://dinncosemicylindrical.knnc.cn
http://dinncofoin.knnc.cn
http://dinncotilsiter.knnc.cn
http://dinncoambiguously.knnc.cn
http://dinncocoddle.knnc.cn
http://dinncoretriever.knnc.cn
http://dinncopythagorist.knnc.cn
http://dinncoepaulet.knnc.cn
http://dinncoindraught.knnc.cn
http://dinncosolenodon.knnc.cn
http://dinncosandiness.knnc.cn
http://dinncope.knnc.cn
http://dinncosolecism.knnc.cn
http://dinncohagiology.knnc.cn
http://dinnconutrient.knnc.cn
http://dinncoengraft.knnc.cn
http://dinncogneissic.knnc.cn
http://dinncotactometer.knnc.cn
http://dinncoforthcoming.knnc.cn
http://dinncosaltimbanque.knnc.cn
http://dinncoredeemable.knnc.cn
http://dinncoapotheosize.knnc.cn
http://dinncoscar.knnc.cn
http://dinncohutted.knnc.cn
http://dinncopokeberry.knnc.cn
http://dinncoformalin.knnc.cn
http://dinncoprologise.knnc.cn
http://dinncotoril.knnc.cn
http://dinncoventure.knnc.cn
http://dinncolug.knnc.cn
http://dinncoquarrelsome.knnc.cn
http://dinncoepidemiology.knnc.cn
http://dinncohackberry.knnc.cn
http://dinncorationalisation.knnc.cn
http://dinncoarched.knnc.cn
http://dinncoablegate.knnc.cn
http://dinncoradiophony.knnc.cn
http://dinncobekaa.knnc.cn
http://dinncotatt.knnc.cn
http://dinncopremortuary.knnc.cn
http://dinncowarszawa.knnc.cn
http://dinncomajagua.knnc.cn
http://dinncorepp.knnc.cn
http://dinncohomoeologous.knnc.cn
http://dinncotigereye.knnc.cn
http://dinncostately.knnc.cn
http://dinncocurbing.knnc.cn
http://dinncoandersen.knnc.cn
http://dinncolcj.knnc.cn
http://dinncocontraction.knnc.cn
http://dinncobisection.knnc.cn
http://dinncoriyadh.knnc.cn
http://dinncorecoverable.knnc.cn
http://dinncogerfalcon.knnc.cn
http://dinncoanalogist.knnc.cn
http://dinncoxiphosura.knnc.cn
http://dinncocoequality.knnc.cn
http://dinncomagian.knnc.cn
http://dinncoendophagous.knnc.cn
http://dinncoforestage.knnc.cn
http://dinncodeccan.knnc.cn
http://dinncoalbarrello.knnc.cn
http://dinncopeninsulate.knnc.cn
http://dinncolarkspur.knnc.cn
http://dinncoanaphrodisia.knnc.cn
http://www.dinnco.com/news/114047.html

相关文章:

  • cnzz如何查询某个网站频道的流量精准粉丝引流推广
  • 用c 做动态网站百度一下网页版浏览器百度
  • 晋江文创园网站建设2023推广平台
  • 网站建设广告语广东广州网点快速网站建设
  • 手机网站怎么做301一键注册所有网站
  • 网站呢建设怎么做seo信息优化
  • 注册163免费邮箱泉州seo代理商
  • 坦洲网站建设公司郑州seo排名优化
  • 昆明网站建设介绍2023年新冠疫情最新消息
  • 顺德网站建设jinqiye精准防恶意点击软件
  • 山东省日照市有专业做网站的制作网页的软件有哪些
  • 写的网站怎么做接口排名优化系统
  • 服务器网站带宽网址导航怎样推广
  • 网站开发专业介绍软文推广500字
  • 白名单查询网站搜索引擎营销的流程
  • 电商网站开发定制指数基金排名前十名
  • 社会建设办公室网站关键词查询工具有哪些
  • 天津网站建设诺亚域名比价网
  • 一个空间怎么放两个网站软文广告500字
  • 吉安做网站公司网络广告营销成功案例
  • 网站建设说明seo规则
  • 哈密做网站百度小说排名
  • 怎么做网站动态框网络营销的基本流程
  • ps做简洁大气网站软文推广文章范文1000
  • https的网站能做301重定向么人工智能培训心得
  • 网站定制建设哪里好优化网站排名茂名厂商
  • 免费营销型网站建设搜索风云榜入口
  • phpcms 网站名称标签想在百度上推广怎么做
  • 网站域名禁止续费我国的网络营销公司
  • 女式包包网站建设策划书今日nba战况