Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Need help with moving sprites in a top-down shooter

Author
Message
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 1st Jul 2010 21:18
I'm making a top down shooter. I've decided that i want the main character to be in the center of the screen always. I achieved that with moving the sprite that represents the ground in the opposite direction of the direction chosen by the player. For example:
The player holds the UP key - The ground sprites is moving DOWN -
thus creating the effect of the character moving UP.
But if I use this technique, every sprite that is supposed to be still, needs to be moved along with the background.

Is this a good technique? Or is there a way to keep all the still sprites still, and to move the main character's coordinates while still keeping him at the center of the screen?

I just love the smell of code in the morning...
bloodmage2
15
Years of Service
User Offline
Joined: 14th Jun 2009
Location:
Posted: 1st Jul 2010 23:03
well, coordinates are coordinates, so the best way to acheive your effect is to have an array of ints (so, say < int IDs[64]; > and set all of it to a certain number, i'd go with -1; whenever you add a sprite, add its index to the end of your array, and have a separate int for how many sprites you have ( < int totalSprites = 0; > ). every time you move, run a for loop and move all of the (so, < for(int i = 0; i < totalSprites; i++) >. the coordinates are relative to the top-left corner of your screen, so there is no moving of coordinates. if the array at index i is not -1, ( < if(IDs[i] != -1) > ) go ahead and move it.

alltogether, it would be something like

int IDs[64] = {-1, .... };
int totalSprites = 0;


void move()
{
for(int i = 0; i < totalSprites; i++)
{
if(IDs[i] != -1)
Move(i);
}
}

Move() being a void returning function with one int parameter that moves the sprite.

-to the optimist, the glass is half full. to the pessimist, it is half empty, to the engineer, it is twice as big as it needs to be.
http://www.lionsbloodstudios.justinman.net/index.htm
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 2nd Jul 2010 00:49
So you are telling me that this only works by moving all of the sprites that are imobile (ground, house, corpse...) at once? Cause that's what i'm doing right now, but it sounds like a burden for the system.

I just love the smell of code in the morning...
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 2nd Jul 2010 01:01
Poof Master
14
Years of Service
User Offline
Joined: 14th Jan 2010
Location:
Posted: 2nd Jul 2010 08:18
I would agree with Hassan. He helped me with making a 2d camera. Once you get the basics of it it's really useful. For my project I am using it and it actually made things a lot easier on me in some ways. For example when I tell my camera to update it updates all of my objects as well. With an Object Oriented approach it can be very useful.
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 2nd Jul 2010 10:20
That is exactly what i had in mind: a 2D camera. But i can see that you are an expert, and i'm a begginer, so creating my own class is a little much for me. To be honest I didn't understand any of that code you wrote in that thread. I was looking for a basic way to move the view in a 2D world, but it seems there isn't one, so i'll just stick with the easy method and move the world around the character.
Thank you.

I just love the smell of code in the morning...
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 2nd Jul 2010 11:05
everything can be explained, but which part you don't get, how classes works or how the class is doing it's job?

Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 2nd Jul 2010 18:10
Well, if you are willing to explain it to me I will be very greatfull. I don't understand how classes work...

I just love the smell of code in the morning...
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 4th Jul 2010 11:29
Well dude, you really should study classes now, it's the most important part of programming required for game development (well for me, at least), you can create very complex stuff without getting your code messy, so yes, take a look at cplusplus.com 's tutorials about classes and inheritance, and i assure you it's going to be helpful, also, once you get an idea about how classes works generally, come back to this thread and i'll show you how this camera class works

Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 4th Jul 2010 15:02
Thanks for the advice... I hope I can handle this.

I just love the smell of code in the morning...
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 4th Jul 2010 20:03
No wait... I was going to learn the enum and switch stuff... that's in the Dark GDK tutorial. I figured that it's a basic thing to know, and very helpful... i think i should learn it first. Can i PM you later when i will begin learning classes, if i will need your help?

I just love the smell of code in the morning...
Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: &lt;script&gt; alert(1); &lt;/script&gt;
Posted: 5th Jul 2010 11:41
sure

Login to post a reply

Server time is: 2024-07-04 10:56:18
Your offset time is: 2024-07-04 10:56:18