Image problem

This is a discussion on Image problem within the C++ Programming forums, part of the General Programming Boards category; I have a little program running and i can add 'sprites' onto the program and they can move However, i ...

  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    12

    Question Image problem

    I have a little program running and i can add 'sprites' onto the program and they can move

    However, i am having trouble finding help for rotating a stationary image.


    Code:
    GameFramework Game(0);  
    
    CreateNewScreenItem Sprite1(0,-3,8 ,1); // When a new characteris added
    I used this to add the image, and it just sits there

    Just wonderng if anyone can help me from this, say i link to a tutorial or something?
    If you need more code, just ask

  2. #2
    Epy
    Epy is offline
    Fortran lover Epy's Avatar
    Join Date
    Sep 2009
    Location
    California, USA
    Posts
    974
    Whatever that is, it's not straight C. Is this from a certain game library, or C# perhaps? Need more info.

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    Oh sorry, its C++, i must have posted in the wrong place

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,914
    Moved to C++ programming forum.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,596
    There is no way we can tell you how to rotate a sprite with the information you have given. The sprite class should have a rotate function. If it doesn't and it is raster-based then rotating the image is going to be extremely difficult. If it is a Direct3D or OGL based sprite then you would need to rotate the quad via transformations.

  6. #6
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    If it doesn't and it is raster-based then rotating the image is going to be extremely difficult.
    In SDL, where rotating a sprite is impossible without using OpenGL, what people usually do is make a new sprite for every 10 degrees of rotation (36 in total, obviously depends on how neat it has to look, could make 360 sprites even) and then rotate the pixel-data of the image itself. This rotates the sprite around it's own axis ofcourse, to rotate around a different axis you'd also need to change the x,y coords.

    All this is terribly slow however so it needs to be done before the main game loop, which in turn means storing alot of almost identical sprites in memory, which also isn't very smart or elegant. And also it messes with the dimensions of the sprite which could be a problem if the game uses bounding box collisions.
    All in all quite a bad solution.

    Edit:
    I'm assuming all of this is 2D ofcourse.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  7. #7
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    Thanks guys

    Well i am doing a carHUD and want the speed-o-meter to move starting from the left -90 degrees and rotating a full 180 so its now 90 angle.

    Nothing wih acceration right now, just rotate at a content speed.

    Just looking for a tutorial or some help on here would be nice

    Will post code abit later when i get home.

  8. #8
    Registered User
    Join Date
    Oct 2009
    Posts
    12
    This is the code i currently have:

    I will be adding a SPEEDOMETER item
    and NEEDLE item

    I need the needle to beable to rotate 180degrees to show the speed of the car

    Code:
    GameFramework AdventureGame(0); //You must create a new instance of the game for every new game.
    CreateNewScreenItem RABBIT(0,-1 ,8 ,1); //When a new character or baddie is needed.
    CreateNewScreenItem SNAIL (0,1,23,0);
    CreateNewScreenItem GEARBOX (-1,-1,2,0);
    CreateNewScreenItem GEARBOX1 (20,-1,2,0);
    CreateNewScreenItem GEARBOX2 (20,-1,2,0);
    CreateNewScreenItem GEARBOX3 (20,-1,2,0);
    CreateNewScreenItem GEARBOX4 (20,-1,2,0);
    CreateNewScreenItem GEARBOX5 (20,-1,2,0);
    CreateNewScreenItem GEARBOX6 (20,-1,2,0);
    
    //main entry point for your program
    int APIENTRY WinMain(HINSTANCE Now,HINSTANCE,LPSTR ,int)
    {
    	AdventureGame.StartGame(Now); //starts game loop
    	AdventureGame.PlayMusic(L"be.mid",true); //plays midi files for music.
    	if(AdventureGame.Running()) // game loop just include.
    		return true;
    	else 
    		return false;
    }
    
    // use this function for loading in graphics, BMP's, PNG's or JPEG's.
    // each image displayed on the screen needs graphic images to be loaded in,
    // you can load:
    // a single image
    // an image for each direction.
    //2,3 or 4 images for each direction for simple animation.
    void GameFramework::LoadGameGraphics()
    {
    	RABBIT.LoadImages("Graphics/Rabbit/playerl1.png","Graphics/Rabbit/playerl2.png",
    					  "Graphics/Rabbit/playerr1.png","Graphics/Rabbit/playerr2.png",
    					  "Graphics/Rabbit/playerb1.png","Graphics/Rabbit/playerb2.png",
    					  "Graphics/Rabbit/playerf1.png","Graphics/Rabbit/playerf2.png");
    
    	SNAIL.LoadImage("Graphics/Snail/snailf1.png");
    
    	GEARBOX.LoadImage("Graphics/Gearbox/cars-gear-stick-prev.png");
    	GEARBOX1.LoadImage("Graphics/Gearbox/cars-gear-stick-1.png");
    	GEARBOX2.LoadImage("Graphics/Gearbox/cars-gear-stick-2.png");
    	GEARBOX3.LoadImage("Graphics/Gearbox/cars-gear-stick-3.png");
    	GEARBOX4.LoadImage("Graphics/Gearbox/cars-gear-stick-4.png");
    	GEARBOX5.LoadImage("Graphics/Gearbox/cars-gear-stick-5.png");
    	GEARBOX6.LoadImage("Graphics/Gearbox/cars-gear-stick-6.png");
    	
    	AdventureGame.LoadBackgroundImage("Graphics/Screens/SplashScreen.jpg",splash_screen);
    	AdventureGame.LoadBackgroundImage("Graphics/Screens/Options.jpg",option_screen);
    	AdventureGame.LoadBackgroundImage("Graphics/Screens/MainGame.jpg",main_game_screen);
    	AdventureGame.LoadBackgroundImage("Graphics/Screens/GameOver.jpg",game_over_screen);
    	AdventureGame.LoadBackgroundImage("Graphics/Screens/HighScore.jpg",high_score_screen);
    
    }
    
    //use this function for displaying anything u want on the screen
    void GameFramework::DisplayMainGame()
    {
    	RABBIT.DisplayItem(); //display RABBIT
    	SNAIL.DisplayItem();	//dislays GHOST
    	GEARBOX.DisplayItem();
    	GEARBOX1.DisplayItem();
    	GEARBOX2.DisplayItem();
    	GEARBOX3.DisplayItem();
    	GEARBOX4.DisplayItem();
    	GEARBOX5.DisplayItem();
    	GEARBOX6.DisplayItem();
    	AdventureGame.DisplayScore(-15,-12); //Displays a score at the relevant x,y coordiantes.
    }
    
    //This section checks for keyboard, mouse or joystick input.
    void GameFramework::MainGameInput()
    {
    
    	if (AdventureGame.keypressed[DIK_SPACE] & 0x80)
    		//SPEEDDIAL.SetSpeed=0 etc
    
    	if (AdventureGame.keypressed[DIK_1] & 0x80)
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(-1),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_2] & 0x80)
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(-1),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_3] & 0x80)
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(-1),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_4] & 0x80)
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(-1),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_5] & 0x80)
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(-1),
    		GEARBOX6.SetPositionX(20);
    
    	if (AdventureGame.keypressed[DIK_6] & 0x80)
    		GEARBOX.SetPositionX(20),
    		GEARBOX1.SetPositionX(20),
    		GEARBOX2.SetPositionX(20),
    		GEARBOX3.SetPositionX(20),
    		GEARBOX4.SetPositionX(20),
    		GEARBOX5.SetPositionX(20),
    		GEARBOX6.SetPositionX(-1);
    
    	if (AdventureGame.keypressed[DIK_UP] & KEY_PRESSED_DOWN) 
    		RABBIT.MoveUp();
    	
    	if (AdventureGame.keypressed[DIK_DOWN] & KEY_PRESSED_DOWN)
    		RABBIT.MoveDown();
    	
    	if (AdventureGame.keypressed[DIK_LEFT] & KEY_PRESSED_DOWN)   
    		RABBIT.MoveLeft();
    	
    	if (AdventureGame.keypressed[DIK_RIGHT] & KEY_PRESSED_DOWN)  
    		RABBIT.MoveRight();
    
    	if (AdventureGame.keypressed[DIK_SPACE] & 0x80)   
    		AdventureGame.changeStage();
    
    	/*********************************************/
    	/* Used if you have a joystick               */
    	/* if your objects drift then you need to    */
    	/* Calibrate teh joystick in windows         */
    	/*********************************************/
    	if (AdventureGame.JoyPresent == true)
    	{	
    		if (AdventureGame.joy_state.lX  > 0)
    			RABBIT.MoveRight();
    		if (AdventureGame.joy_state.lX  < 0)
    			RABBIT.MoveLeft();
    		if (AdventureGame.joy_state.lY  < 0)
    			RABBIT.MoveUp();
    		if (AdventureGame.joy_state.lY  > 0)
    			RABBIT.MoveDown();
    	}
    
    	if (AdventureGame.Collision(&SNAIL,&RABBIT)) //Simple collision detection pass both objects as a pointer 
    		AdventureGame.IncreaseScore();			// true returned if the 2 objects collide.
    		
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. image analysis theory: mapping a network
    By elninio in forum C++ Programming
    Replies: 5
    Last Post: 10-30-2008, 01:23 PM
  2. OpenGL Color update problem
    By arifin in forum C++ Programming
    Replies: 0
    Last Post: 07-22-2008, 12:17 AM
  3. HotSpot image controls (web)
    By novacain in forum C# Programming
    Replies: 0
    Last Post: 06-25-2008, 04:27 AM
  4. Image rotation - doesn't always work
    By ulillillia in forum C Programming
    Replies: 12
    Last Post: 05-03-2007, 12:46 PM
  5. Problem displaying bitmaps
    By batman123 in forum Game Programming
    Replies: 2
    Last Post: 01-09-2005, 01:01 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21