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.

2D All the way! / Problems moving sprite w/ mouse

Author
Message
Dum_Bass
10
Years of Service
User Offline
Joined: 20th Mar 2013
Location: Hiding in your closet.
Posted: 5th Apr 2013 09:43
I have two interelated problems I was hoping someone smarter than myself could help with. I have a sprite that I am trying to control on the X axis by drawing it to the mouse's location and then confining to the mouse to the area within my program window.

void Player::movement( )
{
dbHideMouse( );

int mouseX = dbMouseX( );
int mouseY = dbMouseY( );

dbSprite (PLAYER, mouseX, 722, 13);
dbSetSpritePriority (PLAYER, 10);
dbSprite (SPRING, mouseX + 7, 707, 14);
dbSetSpritePriority (SPRING, 9);

if (dbMouseX( ) < 52)
{
dbSprite (PLAYER, 50, 722, 13);
dbSprite (SPRING, 57, 707, 14);
dbPositionMouse (50, mouseY);
}
else
{
dbSprite (PLAYER, mouseX, 722, 13);
dbSprite (SPRING, mouseX + 7, 707, 14);
}

if (dbMouseX( ) > 661)
{
dbSprite (PLAYER, 661, 722, 13);
dbSprite (SPRING, 668, 707, 14);
dbPositionMouse (662, mouseY);
}
else
{
dbSprite (PLAYER, mouseX, 722, 13);
dbSprite (SPRING, mouseX + 7, 707, 14);
}

if (dbMouseClick( ))
dbSprite (SPRING, mouseX + 7, 660, 14);

return;
}

The problem is that my sprite will stop as expected but "wobble" only on the left hand side of the screen as the mouse constantly repositions it's self back to 50(X).

The second problem comes in a similar flavor. I have another sprite bound to the same restrictions in this code:

ballStart = dbMouseX( );
ballYCoord = dbSpriteY (BALL) ;

if (dbMouseX( ) < 51)
dbSprite (BALL, 110, 687, 15);
else
dbSprite (BALL, ballStart + 45, 687, 15);
if (dbMouseX( ) > 661)
dbSprite (BALL, 723, 687, 15);
else
dbSprite (BALL, ballStart + 45, 687, 15);

the sprite "BALL" does what it is supposed to but if the mouse cursor is positioned < 51(X) than the BALL sprite suddenly redraws at 350(X) which is the middle of the screen but on at same Y axis is already drawn on.

Any thoughts or ridicule?
Dum_Bass
10
Years of Service
User Offline
Joined: 20th Mar 2013
Location: Hiding in your closet.
Posted: 6th Apr 2013 06:43
Sorry 'bout the format of the post. The code button for was not working for me last night for some reason when I posted.
xCatalyst
11
Years of Service
User Offline
Joined: 5th Dec 2012
Location: Pittsburgh, PA
Posted: 8th Apr 2013 22:21
The problem is in your conditions:


Because you have your conditions set so that if the mouse's x position is less than 52, it gets re-positioned to 50 (ie. less than 52, thus making the second 'if' statement useless because, since it got re-positioned, it will never be greater than 661). And vice versa.

The second problem comes from pretty much the same conditional flaw.

Dum_Bass
10
Years of Service
User Offline
Joined: 20th Mar 2013
Location: Hiding in your closet.
Posted: 9th Apr 2013 17:27
Thank you for the reply.

I have solved this with some restructering of my variables so that I can use collision decection more properly (Dark GDK). I chose the name Dum_Bass not for humor, but because never a truer title has been bestowed upon a fool.

I am learning C++ first and implementing the dark gdk for fun, privately, no professors or physical resources. I figure I would rather ask about a screw-up and be picked on than fail over and over again.

having said that; I solved the problem using simple sprite collision parameters and resetting the mouse curser only when it was outside of the parameters... Output: not "wobble" and a much happier "BALL" sprite.

Back to destroying my already feeble frontle lobe with trying to convince said sprites that I mean what I say.

Cheers.
xCatalyst
11
Years of Service
User Offline
Joined: 5th Dec 2012
Location: Pittsburgh, PA
Posted: 11th Apr 2013 00:03
Haha hey, we've all been there. At some point, even the most stubborn need atleast a little help

I believe making mistakes is the only way to truly learn something

Login to post a reply

Server time is: 2024-03-02 05:33:01
Your offset time is: 2024-03-02 05:33:01