LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 05-25-2007, 11:46 AM   #1
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889
Blog Entries: 1

Rep: Reputation: 30
C++/SDL: Images moving too slowly. Images loaded once, etc. Why?


I am looking at games on the Super Nintendo, NES and etc., and I noticed how smooth their backgrounds and other objects move across the screen. I'm trying to recreate that after a couple unsuccessful attempts. I have made a small program that just moves a stick man across the screen everywhere, except where some blocks are at.

http://www.yousendit.com/transfer.ph...E52A1E3A0EF883

Just execute sc_game and you can see what I mean.

I am trying to get speed variation in my objects. So far, to get that smoothness I see in 2D games, moving images one pixel at a time across the screen using a specific time frame for each image sounds like the best way to achieve this.

The problem with the above application is that it does not use a time frame. And strangely, it is running strangely slow. Why?

Am I supposed to move images across the screen by the pixels (instead of one) along with a time frame?

Thanks in advance.
 
Old 05-26-2007, 08:21 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
Currently your object "blob" just updates positions using a defined offset
Code:
void scobject::move ()
{
	switch ( move_x )
	{
		case LEFT : xywh.x -= offsetX; break;
		case RIGHT: xywh.x += offsetY; break;
		case STOP :                    break;
...
The simplest method to use is linear interpolation with each frame having a time step.
Using a fixed time step can help in making a game run the same no matter what the machine specs are, where as a variable time step gives differing results.

Code:
struct Object
{
	float x,y;//position
	float vx,vy;//velocity

	update(float time_step)
	{
		//v = u + at
		//position = initial + velocity * time
		x += vx * time_step;
		y += vy * time_step;

	}
};

Here is two links from Glenn Fiedler that you should read:
http://www.gaffer.org/game-physics/fix-your-timestep/
http://www.gaffer.org/game-physics/integration-basics/

Last edited by dmail; 05-26-2007 at 08:28 AM.
 
Old 05-26-2007, 05:11 PM   #3
RHLinuxGUY
Member
 
Registered: Oct 2003
Distribution: Ubuntu 7.04
Posts: 889

Original Poster
Blog Entries: 1

Rep: Reputation: 30
Thank you, I am implemented time based movement into my game.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
CD images roAder Slackware 9 04-28-2006 10:31 PM
Moving images Fasn8n Linux - General 3 02-13-2006 01:44 PM
Convert cd images to dvd images rcsuk Debian 2 07-11-2005 10:34 AM
Corrupt Images when loaded through FTP tumana Linux - Newbie 10 09-08-2004 04:16 AM
C++, SDL, and images rebelcan Programming 8 08-29-2003 08:20 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:21 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration