Jump to content

  • Log In with Google      Sign In   
  • Create Account


Cursor obliterating the background.


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
5 replies to this topic

#1 stitchs   Crossbones+   -  Reputation: 1281

Like
0Likes
Like

Posted 20 August 2012 - 04:20 PM

Hello community,

First, let me specify my language and Graphics library: C++, Allegro 4.

So I've come across this minor issue whereby I have my cursor drawing on-screen. I am using Allegro's show mouse and letting the graphics library handling its draws. My 'riveting' Tic-Tac-Toe was fine, up until the point I decided to draw the current players' shape underneath the Arrow cursor, the reason for this being better visual clarity of exactly whose turn it is.

When I show the shape moving with the Mouse coordinates, the shape trails and draws all over the background. Then I made a function which saves a portion of the Buffer (minus the cursor/player-shape cursor), and redraws it after the buffer has been drawn to screen, thereby restoring the obliterated portion.

This works perfectly when I modify the mouse position using Integer Coordinates that are increased/decreased on various key-presses. I have even tested it at differing speeds of +=1, 15, 75 and each time the background is preserved. When I move the cursor without key-presses (with Allegro's standard mouse movement) the background is still shown to be obliterated, but in shudders. It's difficult to explain so please find an image attached.

I can't seem to understand why that no matter how fast the key-movement compared to mouse-movement happens, that the mouse has this effect.

Below is the code that saves the Bitmap portion;
[source lang="cpp"]BITMAP* GameEngine::f_SaveBitmapPortion(BITMAP* p_Source){ // Create a temporary bitmap ///BITMAP* temp; temp = Graphics::f_CreateBitmap(p_Source->w, p_Source->h); // TODO: (remove a_Buffer in favour of a second parameter, renamed to source // and change the name of p_Source to regionSize. blit(a_Buffer, temp, // Blit from the Buffer(source), using the coordinate location to 'cut-away' said area mouse_x - (p_Source->w / 2), mouse_y - (p_Source->h / 2), // to the Temp Bitmap(dest) coordinates at 0, 0 0, 0, p_Source->w, p_Source->h); // return the temp bitmap return temp;}[/source]
And below this is the code that shows where in the Main-loop that it is saved/re-drawn to screen;
[source lang="cpp"]// Drawing if(g.f_GetShapeCursor() != NULL) { portionBG = g.f_SaveBitmapPortion(g.f_GetShapeCursor()); } g.f_DrawGrid(g.f_GetBuffer()); g.f_CheckPlayerScores(g.f_GetBuffer()); scare_mouse(); blit(g.f_GetBuffer(), screen, 0, 0, 0, 0, screen->w, screen->h); unscare_mouse(); if(g.f_GetShapeCursor() != NULL) { blit(portionBG, g.f_GetBuffer(), 0, 0, mouse_x - (g.f_GetShapeCursor()->w / 2), mouse_y - (g.f_GetShapeCursor()->h / 2), g.f_GetShapeCursor()->w, g.f_GetShapeCursor()->h);}[/source]
Thanks very much for taking your time in reading this and any input is greatly appreciated.

Regards,

Stitchs.

P.S. Regarding the image, this portion of the buffer drawn isn't trailing all the time, it only happens once every several loops, so it looks like the Grid lines are being 'push-pulled' all over the place.

Attached Thumbnails

  • Oblit_BG.png


Sponsor:

#2 stitchs   Crossbones+   -  Reputation: 1281

Like
0Likes
Like

Posted 28 August 2012 - 11:47 AM

***BUMP***

I was hoping that there would have been a response by now. Apologies for the late bump but I have had no access to the net since the time of posting, and I wasn't sure whether or not to re-post as a new topic. Again, any help is greatly appreciated.

Regards,

Stitchs

#3 BeerNutts   Crossbones+   -  Reputation: 2758

Like
0Likes
Like

Posted 28 August 2012 - 11:50 AM

The simple solution is to re-draw the whole screen every frame. That will resolve the issue of your BG getting obilerated, and, I promise, you won't see any performance hit with it either.
My Gamedev Journal: 2D Game Making, the Easy Way

---(Old Blog, still has good info): 2dGameMaking
-----
"No one ever posts on that message board; it's too crowded." - Yoga Berra (sorta)

#4 caldiar   Members   -  Reputation: 702

Like
0Likes
Like

Posted 28 August 2012 - 11:57 AM

Try rounding up your floating point numbers (mouse_x - (GetShapeCursor()->w / 2)) and casting to an integer such as static_cast<int>(ceil(mouse_x - (GetShapeCursor()->w / 2))). Blitting a fraction of a pixel sounds like it could be the case for the issue you're experiencing.

#5 stitchs   Crossbones+   -  Reputation: 1281

Like
0Likes
Like

Posted 29 August 2012 - 12:08 PM

Thanks for your responses guys. I do redraw every single frame, I was using the BG copy function to remove the cursor 'trail' that was being left behind. Guessing there might be slight performance issues from Buffer/Mini-BG drawing on every frame?

I have solved the issue I was having by calling a clear_bitmap(buffer) at the end of the loop. It must have been the problem that I never noticed before as the grid is always drawn in the same position.

I am curious though, where would the floating point number come from if my shape cursor width, and the Allegro mouse X is of type Integer, to begin with?

#6 caldiar   Members   -  Reputation: 702

Like
1Likes
Like

Posted 29 August 2012 - 02:12 PM

oh man I should have totally picked up on the lack of a buffer clear. That very same issue happened with me years ago when I first tried writing a side-scrolling 2D shooter and had trails of characters being stretched all over the place.

The floating point number exists as an assumption. I assumed the mouse coordinates were floats. Since you're just working with ints there then you should be golden.

Glad to see you got this sorted out.




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.



PARTNERS