Jump to content

View more

Image of the Day

雑魚は多めにして、爽快感重視にしつつ・・・(´・ω・`)
早いとこ、ベースを作って、完成にもっていかないとね。
タイトルもまだ迷ってるだよなぁ。 
#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

SDL Surface not appearing

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
7 replies to this topic

#1 nano511   Members   

103
Like
0Likes
Like

Posted 04 August 2011 - 07:34 AM

I just made this new class for my "monster". But the monster is not appearing.

Here is the relevant code

Monster.cpp
Monster::Monster( Environment* GameEnvironment )
{
	graphics = GameEnvironment->graphics;
	monsterRight[0] = graphics->LoadImage( "Monster_Right_0.bmp" );
	monsterRight[1] = graphics->LoadImage( "Monster_Right_1.bmp" );
	monsterRight[2] = graphics->LoadImage( "Monster_Right_2.bmp" );
	monsterRight[3] = graphics->LoadImage( "Monster_Right_3.bmp" );
	monsterLeft[0] = graphics->LoadImage( "Monster_Left_0.bmp" );
	monsterLeft[1] = graphics->LoadImage( "Monster_Left_1.bmp" );
	monsterLeft[2] = graphics->LoadImage( "Monster_Left_2.bmp" );
	monsterLeft[3] = graphics->LoadImage( "Monster_Left_3.bmp" );

	direction = LEFT;
	frame = 0;
	int xPos = 490;
	int health = 100;
}
void Monster::Move( int playerX )
{
	if( playerX < xPos )
	{
		direction = LEFT;
		frame++;
		xVel -= 3;
	}
	else if( playerX > xPos )
	{
		direction = RIGHT;
		frame++;
		xVel += 3;
	}
}
void Game::HandleEvents()
{
	...

	player->HandleEvents();
	monster->Move( player->xPos );
}
void Game::Logic()
{
	... 

	monster->xPos += monster->xVel;

        ...
}
void Game::Render()
{
        ...

	if( monster->frame >= 4 )
		monster->frame = 0;

        ...

	// Draw the monster
		if( monster->direction == RIGHT )
			graphics->ApplySurface( monster->xPos, 311, monster->monsterRight[ monster->frame ], graphics->screen );
		else if( monster->direction == LEFT )
			graphics->ApplySurface( monster->xPos, 311, monster->monsterLeft[ monster->frame ], graphics->screen );
	

	graphics->UpdateScreen();
}


#2 Wooh   Members   

1088
Like
0Likes
Like

Posted 04 August 2011 - 07:59 AM

In the constructor you have
int xPos = 490;

int health = 100;

These are local variables and they are not used anywhere. I think what you meant to do was to set Monster::xPos and Monster::health. I guess this could be what caused the problem because if xPos get a very large value the monster will not be within the screen.

#3 rip-off   Moderators   

10891
Like
0Likes
Like

Posted 04 August 2011 - 08:41 AM

You also increment (or decrement) the velocity every frame - unless the monster position is exactly equal the player. Instead, you should use either an acceleration value (which should probably be limited to some reasonable maximum) or instead simply set the velocity, instead of incrementing it.

#4 nano511   Members   

103
Like
0Likes
Like

Posted 04 August 2011 - 08:45 AM

In the constructor you have

int xPos = 490;
int health = 100;
These are local variables and they are not used anywhere. I think what you meant to do was to set Monster::xPos and Monster::health. I guess this could be what caused the problem because if xPos get a very large value the monster will not be within the screen.


What do you mean they're local. Those are member variables. Health isnt used anywhere yet, but monster->xPos is used in the code. The number is so large because i want him to start off the screen, then walk over to the player.

And thank you to the guy who said about setting the velocity instead of incrementing it.




#5 rip-off   Moderators   

10891
Like
1Likes
Like

Posted 04 August 2011 - 08:47 AM

Because you used the "int" keyword, you are creating new, unused variables and giving them values. If you want to assign to your member variables, instead write:
xPos = 490;
health = 100;


#6 nano511   Members   

103
Like
0Likes
Like

Posted 04 August 2011 - 09:14 AM

XD how could i not notice that lol!

But he's still not showing up. :(

#7 rip-off   Moderators   

10891
Like
0Likes
Like

Posted 04 August 2011 - 09:40 AM

Are you sure the images are loading? Have you used your debugger to step through the render function and inspected the values of the monster's position, etc?

#8 nano511   Members   

103
Like
0Likes
Like

Posted 04 August 2011 - 09:47 AM

Yeah i figured it out. I keep my images in my Media folder, and i forgot to prefix all the images with Media\.

Thanks for the help though!




Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.