好吧我正在使用一个时间为50毫秒的计时器来动画一些移动的文本(技术上它在文本之间滚动).
问题是,如果你仔细观察,你可以看到文字闪烁,并且id不喜欢闪烁..
所以我对动画不是那么好但是我能做些什么来减少闪烁?也许更快的过去时间?或者我应该甚至使用计时器吗?
编辑:
所以我试图实现双缓冲,我显然做了一些事情.
这是没有双缓冲的代码,这个工作正常,但有点闪烁.
void PaintScrollingText(ScrollingText *Settings, WPARAM wParam)
{
HDC hdc;
PAINTSTRUCT ps;
HANDLE hOldFont;
RECT rect;
hdc = wParam ? (HDC)wParam : BeginPaint(Settings->hWnd, &ps);
hOldFont = SelectObject(hdc, Settings->hFont);
SetTextColor(hdc, Settings->crForeGnd);
SetBkColor(hdc, Settings->crBackGnd);
GetClientRect(Settings->hWnd, &rect);
rect.right -= Settings->txt1XOffset;
DrawText(hdc, Settings->szText1, -1, &rect, DT_RIGHT);
rect.right += Settings->txt1XOffset - Settings->txt2XOffset;
DrawText(hdc, Settings->szText2, -1, &rect, DT_RIGHT);
SelectObject(hdc, hOldFont);
if (!wParam) EndPaint(Settings->hWnd, &ps);
}Run Code Online (Sandbox Code Playgroud)
这是我的代码,带有双缓冲.
void PaintScrollingText(ScrollingText *Settings, WPARAM wParam) …Run Code Online (Sandbox Code Playgroud) 我想在屏幕上显示一个计时器,倒计时将继续在屏幕上显示.它还会在特定时间间隔内发出一些声音警报.可能有多个计时器同时运行.实现此类型计时器系统的最佳方法是什么?我应该在每次启动计时器时运行一个线程并使用UIThread()更改时间显示吗?有一些更好的方法来实现它?有人可以给我示例代码吗?
g_timer_new如何工作?
有可能做一个
char timerz[50];
GTimer *timer
g_timer_start(GTimer *timer);
strcpy(timerz,(g_timer_elapsed(GTimer *timer))
Run Code Online (Sandbox Code Playgroud)
或者我该怎么做才能在gtk_frame中有一个计时器?
祝你今天愉快!:d
我试图在flex中使用计时器.我提到了这个例子:Timer : blog.flexexamples.com.
这是我想要实现的目标:
我想启动计时器,显示自计时器启动以来经过的时间.它应该独立于您所在的区域.(无论您所处的区域如何,计时器应该在每个区域都能正常工作).
计时器应该继续,除非点击某个按钮,我想在一个警告框中显示经过的时间(以分钟为单位),然后计时器应该从0开始再次启动.
我尝试了我的例子,但它无法正常工作.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
verticalAlign="middle"
backgroundColor="white"
creationComplete="init()">
<mx:Script>
<![CDATA[
import flash.events.TimerEvent;
import flash.utils.Timer;
import mx.controls.Alert;
private const TIMER_INTERVAL:Number = 10;
private var baseTimer:int;
private var t:Timer;
private function init():void {
t = new Timer(TIMER_INTERVAL);
t.addEventListener(TimerEvent.TIMER, updateTimer);
}
private function updateTimer(evt:TimerEvent):void {
var d:Date = new Date(getTimer()-baseTimer);
var min:String = (d.minutes).toString();
var sec:String = (d.seconds).toString();
counter.text = String(min+"."+sec);
}
private function startTimer():void {
baseTimer = getTimer();
t.start();
} …Run Code Online (Sandbox Code Playgroud) 我需要每秒调用一个函数,因为我想根据每秒存储数据,所以我不能错过第二个?什么是C的最佳方法?
下面是timer_create方法的骨架,这个可靠吗?
#include <stdio.h>
#include <time.h>
#include <signal.h>
timer_t gTimerid;
void start_timer(void)
{
struct itimerspec value;
value.it_value.tv_sec = 1;
value.it_value.tv_nsec = 0;
value.it_interval.tv_sec = 1;
value.it_interval.tv_nsec = 0;
timer_create (CLOCK_REALTIME, NULL, &gTimerid);
timer_settime (gTimerid, 0, &value, NULL);
}
void stop_timer(void)
{
struct itimerspec value;
value.it_value.tv_sec = 0;
value.it_value.tv_nsec = 0;
value.it_interval.tv_sec = 0;
value.it_interval.tv_nsec = 0;
timer_settime (gTimerid, 0, &value, NULL);
}
void timer_callback(int sig)
{
printf(" Catched timer signal: %d ... !!\n", sig);
}
int main(int ac, char **av) …Run Code Online (Sandbox Code Playgroud) 我有以下(可见)方法不断检查当前时间,并且当达到特定时间(在这种情况下是午夜)时,NSLog语句运行一次以表示正在执行的有用的事情:
- (void) checkTime {
while (true){
NSAutoreleasePool *loopPool = [[NSAutoreleasePool alloc] init];
NSDate *now = [[NSDate alloc] init];
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setDateFormat:@"HH:mm"];
NSString *nowDateString = [outputFormatter stringFromDate:now];
if([nowDateString isEqualToString:@"00:00"]){
NSLog(@"Store previous days data..");
BOOL stillMidnight = YES;
while(stillMidnight == YES){
NSDate *latestNow = [[NSDate alloc] init];
NSDateFormatter *latestOutputFormatter = [[NSDateFormatter alloc] init];
[latestOutputFormatter setDateFormat:@"HH:mm"];
NSString *latestString = [latestOutputFormatter stringFromDate:latestNow];
//Check if it is still midnight
if([latestString isEqualToString:@"00:01"]){
//leave while
stillMidnight = NO;
}
}
NSLog(@"No …Run Code Online (Sandbox Code Playgroud) var LevelCode:Array = [10,20,30,40,50,60,70,80,...,990,1000];
var Piece0:Timer = new Timer(50, LevelCode[0]);
var Piece1:Timer = new Timer(50, LevelCode[1]);
...
var Piece98:Timer = new Timer(50, LevelCode[98]);
var Piece99:Timer = new Timer(50, LevelCode[99]);
Run Code Online (Sandbox Code Playgroud)
我想同时启动Piece0计时器,Piece1计时器等.我试过了Piece0+Piece1.start();,但没办法.
你们能帮助我吗?
COED到目前为止:我不会,如果我应该使用线程或什么样的计时器-_--
clicker.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
counter++;
seconds = 5000;
timer.schedule(new TimerTask() {
public void run() {
Intent x = new Intent(startClickActivity.this, ClickCountActivity.class);
startActivity(x);
}
}, seconds);
}
});
Run Code Online (Sandbox Code Playgroud) 按下勾选按钮时出现运行错误.我正在尝试使用javax.swing.Timer按下勾选按钮来触发事件所以如果有人有任何建议我会很感激他们.我目前正在使用Eclipse,按下勾选按钮时会出现运行时错误.
线程"AWT-EventQueue-0"中的异常java.lang.Error:未解决的编译问题:类型ClockPanel必须在ClockPanel.actionPerformed(ClockPanel.java:10)实现继承的抽象方法ActionListener.actionPerformed(ActionEvent)
这是我正在使用的代码(3个类).
import java.util.Calendar;
import java.util.GregorianCalendar;
class Clock
{
int hour;
int minute;
int second;
Calendar gregcal = new GregorianCalendar();
int h = gregcal.get(Calendar.HOUR_OF_DAY);
int m = gregcal.get(Calendar.MINUTE);
int s = gregcal.get(Calendar.SECOND);
//default constructor
Clock()
{
hour = h;
minute = m;
second = s;
}
//parameterized constructor
Clock(int hour, int minute, int second)
{
this.hour = hour;
this.minute = minute;
this.second = second;
}
public int getHour()
{
return hour;
}
public int getMinute()
{
return minute;
} …Run Code Online (Sandbox Code Playgroud) 我有一个单例对象,并在其中定义了一个字典.
public class MyClass
{
public static readonly MyClass Instance = new MyClass();
private MyClass
{}
public Dictionary<int, int> MyDictionary = new Dictionary<int, int>();
}
Run Code Online (Sandbox Code Playgroud)
现在,我有两个System.Timers.Timer对象更新MyDictionary.
System.Timers.Timer timer1 = new System.Timers.Timer(5);
timer1.AutoReset = false;
timer1.Elapsed += new System.Timers.ElapsedEventHandler(MyTimer1Handler);
timer1.Enabled = true;
timer1.Start();
System.Timers.Timer timer2 = new System.Timers.Timer(5);
timer2.AutoReset = false;
timer2.Elapsed += new System.Timers.ElapsedEventHandler(MyTimer2Handler);
timer2.Enabled = true;
timer2.Start();
private void MyTimer1Handler(object sender, ElapsedEventArgs e)
{
MyClass.Instance.MyDictonary[1] = 100;
}
private void MyTimer1Handler(object sender, ElapsedEventArgs e)
{
MyClass.Instance.MyDictonary[2] = 100;
} …Run Code Online (Sandbox Code Playgroud)