flex中timer与Event.ENTER_FRAME

本文探讨了在Flex中使用Timer进行动画播放时遇到的时间同步问题,由于Timer受客户端硬件影响,导致动画时间偏差较大。建议改用Event.ENTER_FRAME事件来实现更稳定的动画效果,如线或圆球的移动。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于flex中使用timer做动画播放,例如:做个一线的移动,在timer监听的方法中累加线的x位置,但是线移动到结束位置发现与实际时间严重不一致,通过查资料发现timer受客户端cpu等硬件影响,会导致与实际时间严重不符的后果,所以建议使用监听Event.ENTER_FRAME这个事件来做例如:线,圆球移动动画播放.

参考资料:

http://bbs.9ria.com/thread-53853-1-1.html

from PySide6.QtWidgets import QApplication, QMainWindow, QFileDialog from PySide6.QtGui import QPixmap, QImage from PySide6.QtCore import QTimer, Qt import sys import cv2 import os import pygame import tempfile from moviepy import VideoFileClip from video02_ui import Ui_MainWindow class VideoApp02(QMainWindow): def __init__(self): super().__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) # 初始化音频系统 pygame.mixer.init() # 连接控件信号 self.ui.openButton.clicked.connect(self.openVideo) self.ui.playButton.clicked.connect(self.toggle_play) self.ui.stopButton.clicked.connect(self.stop_video) self.ui.horizontalSlider.sliderPressed.connect(self.slider_pressed) self.ui.horizontalSlider.sliderReleased.connect(self.slider_released) self.ui.horizontalSlider.sliderMoved.connect(self.slider_moved) # 初始化变量 self.file_path = None self.clip = None self.frame_count = 0 self.current_frame = 0 self.is_playing = False self.is_slider_pressed = False self.temp_audio = None # 定时器设置 self.timer = QTimer(self) self.timer.timeout.connect(self.update_frame) def toggle_play(self): if not self.file_path: self.ui.statusbar.showMessage("请先打开视频文件!") return if self.is_playing: self.pause_video() else: self.start_playback() def start_playback(self): try: if not self.clip: self.init_video() # 确保音频已加载 if not pygame.mixer.music.get_busy(): if os.path.exists(self.temp_audio.name): pygame.mixer.music.load(self.temp_audio.name) else: raise FileNotFoundError("音频文件不存在") if self.current_frame >= self.frame_count: self.current_frame = 0 self.is_playing = True
03-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值