Jump to content
  • Advertisement
Sign in to follow this  
triele

[.net] Game Tiles in C#

This topic is 4508 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!