gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > sprite dragging.

#168141 - rik_DS - Fri Apr 10, 2009 11:31 pm

Hi

Say that you can pick a sprite with the mouse and drag it around...What I would like to do is to be allowed to only drag in the direction the sprite is rotated. I believe the solution would be to create a rectangle around sprite and orient the rectangle with the sprite...but im not sure how this can be achieved.
Could use some advice :)

Thanks

#168151 - sgeos - Sat Apr 11, 2009 3:08 pm

First, you'll want to create a data model. The sprite will be the view of that model. Attach flags like canDragLeft to the model and update them to reflect whatever you are trying to do. Then when the player tries to drag the object left, only move it left if the canDragLeft flag is true.

#168154 - rik_DS - Sat Apr 11, 2009 7:52 pm

Hi sgeos

btw, I meant stylus above and not mouse :)

Basically what I would like to do is to create a rectangle extending forward from the sprite like in here: http://www.red3d.com/cwr/steer/Obstacle.html
No movement around is necessary. Say that if the sprite is rotate 80 degrees, this rectangle should was be oriented correctly with the sprite, then you can only drag the sprite within that rectangle, the direction it is facing.

Thanks

#168155 - sgeos - Sat Apr 11, 2009 9:38 pm

rik_DS wrote:
btw, I meant stylus above and not mouse :)

It does not matter what your pointing device is.

rik_DS wrote:
Basically what I would like to do is to create a rectangle extending forward from the sprite like in here: http://www.red3d.com/cwr/steer/Obstacle.html
No movement around is necessary. Say that if the sprite is rotate 80 degrees, this rectangle should was be oriented correctly with the sprite, then you can only drag the sprite within that rectangle, the direction it is facing.

In that case, just make your object move "forward" at an 80 degree angle using whatever math you are comfortable with (probably trig or matrices). You might need a check to prevent movement if user tries to move the object backwards.