Sign in to follow this  

[.net] Game Tiles in C#

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a a map created with a 2D array of PictureBox. I also have a main sprite that I can move around that is a PictureBox. The thing is, if my 2D array is more than 20 (i.e. tiles[25][25]) I can move my main sprite a few pixels, then it will just stop moving. Then I'll have to release the key, then repress to make it move. I know that it's probably not the most efficient way, but can someone explain to me why this is happening? Also how would you guys create a basic 32x32 game tile? Which Control would you guys extend? Here's some code/psuedo code to explain things. // I have a timer, interval set to 16 milliseconds timer.Interval = 16; // timer tick handler calls drawhero void TimerTick(.....) DrawHero(); private void DrawHero() { if( up ) { hero.Location = new Point( x, y-=3 ); hero.Refresh(); } if( down ) { hero.Location = new Point( x, y+= 3 ); hero.Refresh(); } if( left ) { hero.Location = new Point( x-=3, y ); hero.Refresh(); } if( right ) { hero.Location = new Point( x+=3, y ); hero.Refresh(); } } Well thats about it. Hope yall can help. Thanks. Triele

Share this post


Link to post
Share on other sites
Well, you should not have a picture box per tile because that will increase message/events/redrawing overhead a lot, especially if you have lots of tiles.

A better solution would be to create a single Map (derived from Control for instance) class which contains an array of Tiles (and Tile is not derived from any on control). In the Map.Paint() method you simply go through your array of Tiles and render them on the client area of the Map instance.

The problem you currently are having could be that focus on the PictureBox is lost after a few pixels movement due to some event or other thing in your app.

Share this post


Link to post
Share on other sites
Thanks. Yeah, I kinda figured that was the problem, so I already went ahead and did what you mentioned, and things are 'kinda' working now.
Ahhh!!! Damn collision detection...I'll save that for another day.

Triele

Share this post


Link to post
Share on other sites

This topic is 4198 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this