10 Replies - 982 Views - Last Post: 17 January 2014 - 11:09 AM Rate Topic: -----

#1 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:04 AM

I am making a game. I have a 16x16 sprite(which has an alpha channel) which is to move across the screen when the user presses his/her arrow keys. This all works fine-and-dandy but my sprite leaves a trail everywhere it has been. I understand that I need to redraw the portions of the map that the sprite has touched. I don't fully understand copying portions of bitmaps with rectangles. Can someone review my movement code and suggest how I can reorganize it to make it work correctly?

 ElseIf e.KeyCode = Keys.Down Then
            Dim g As Graphics = Graphics.FromImage(WholeImg)
            Dim fr_rect As New Rectangle(x, y, 16, 16)    'I have no clue what to do with these lines. I dont know exactly know what the four numbers adjust or if this is the right spot to have 
            Dim to_rect As New Rectangle(x, y, 16, 16)    'these in my code.
            g.DrawImage(WholeImg, to_rect, fr_rect, _
        GraphicsUnit.Pixel)
            g.DrawRectangle(Pens.Red, to_rect)   'this draws a red rectangle around the area it modifies, just so i can see it. This will be removed once i figure it out.

                y = y + 3                     'The sprite's Y location goes up
            g.DrawImageUnscaled(character, x, y) 'draws my sprite at the new position

                Me.BackgroundImage = WholeImg


Is This A Good Question/Topic? 0
  • +

Replies To: Removing Sprite Trails in a Game

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14094
  • View blog
  • Posts: 56,469
  • Joined: 12-June 08

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:07 AM

Where is that code stashed at?

You may find this helpful on clearing up what the basics on drawing should be:
http://www.dreaminco...-basics-part-1/
Was This Post Helpful? 0
  • +
  • -

#3 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:08 AM

It is in the form1 keydown event. I will check that link out.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14094
  • View blog
  • Posts: 56,469
  • Joined: 12-June 08

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:09 AM

Eesh.. that is a bad idea.
Was This Post Helpful? 0
  • +
  • -

#5 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:12 AM

why? :whatsthat:
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14094
  • View blog
  • Posts: 56,469
  • Joined: 12-June 08

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:16 AM

It doesn't make sense in the context of an 'engine'. In my tutorial (that I linked) it shows a more controlled process that is not contingent on a user inputting anything.. the engine keeps chugging once it is kicked off and on semi constant time scale.
Was This Post Helpful? 0
  • +
  • -

#7 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:42 AM

I checked out your example and I don't understand it. :/ Sorry.
Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14094
  • View blog
  • Posts: 56,469
  • Joined: 12-June 08

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:43 AM

Bummer.

Is there any particular part you don't understand, or how would you like me to respond to that comment?
Was This Post Helpful? 0
  • +
  • -

#9 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 10:50 AM

I suppose just saying "bummer" is sufficient. I don't expect you to tear your example apart and explain it to me.I don't understand the majority of it. If you don't mind could you pretend that my original code wasn't completely ass-backwards and tell me how to make it do what I was trying? I want to at least get this working before I restructure 1000 lines of code. Thanks.
Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 14094
  • View blog
  • Posts: 56,469
  • Joined: 12-June 08

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 11:01 AM

Again - not seeing how your code is attempting to work makes it difficult to recommend anything along of the vein of what you are trying. only showing one chunk, wedged in a key down, isn't really helpful.

If you gleamed anything from my tutorial - the key you want to hold If you want to repaint in an orderly method. Being I have no idea what you have in your paint event (or even if you are considering one) I would look at clearing the screen (maybe jamming a refresh/repaint in there) before you go off and draw things again.

Outside of that - who knows.. chasing busted code with more code seems like a less than fruit bearing experience.
Was This Post Helpful? 0
  • +
  • -

#11 xilith117   User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 99
  • Joined: 13-August 11

Re: Removing Sprite Trails in a Game

Posted 17 January 2014 - 11:09 AM

yeah. :/
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1