|
Post by Wayne Rayner on Aug 25, 2011 9:55:43 GMT -5
Hello guys
How would you use the mouse to rotate a sprite. As in for a topdown shooter. I have tried but I have no theory on how to use a mouse to control a sprite infact I don't understand the mouse_xd() and mouse_yd() actually I thought * them together in sprsetangle function but that failed. For some reason I have no clue how this works.
If you can help me that will be awesome. If you can give me an explanation that would be awesome as well
thanks
Wayne Rayner
|
|
|
Post by PeterMaria on Aug 25, 2011 12:19:02 GMT -5
here my suggestion: Attachments:
|
|
|
Post by matthew on Aug 25, 2011 15:50:25 GMT -5
If you want to rotate a sprite using the mouse I think you'll need to use the atn2d command. A few years ago nicky wrote this program which drew a line from the centre of the screen to the location of the mouse. The same technique could be used to rotate a sprite.
|
|
|
Post by matthew on Aug 26, 2011 8:37:31 GMT -5
Okay Wayne, I had a few spare hours today so I knocked together a program that will rotate a sprite to point in the direction of the mouse-pointer. It's basically a combination of a two programs written by nicky & adam. textmode(text_buffered)
declare function spriteRotate(x1, y1, x2, y2)
dim screenCentreX = ( windowwidth () / 2 ), screenCentreY = ( windowHeight () / 2 )
dim texture = loadtex("./Data/F117.png") : dim sprite = newsprite (texture)
sprsetpos ( screenCentreX, screenCentreY )
' A structure to hold our two positions, sprite & mouse. struc sPoints dim position#(1) endstruc
dim sPoints centrePoint dim sPoints mousePoint
centrePoint.position# = vec2( screenCentreX, screenCentreY )
do
cls
' Debug text, useful to see what's going on printr "X: " ; mousePoint.position#(0) printr "Y: " ; mousePoint.position#(1) printr "Angle: " ; spriteRotate ( centrePoint.position#(0), centrePoint.position#(1), mousePoint.position#(0), mousePoint.position#(1))
' Update x & y mouse co-ordinates mousePoint.position# = vec2( ( mouse_x () * windowwidth () ), ( mouse_y () * windowheight () ) )
' Borrowed from a program Adam wrote sprsetangle( spriteRotate ( centrePoint.position#(0), centrePoint.position#(1), mousePoint.position#(0), mousePoint.position#(1)))
drawtext()
loop
function spriteRotate(x1, y1, x2, y2)
' Direct cut-&-paste of the function that nicky wrote dim tempAngle = atn2d ( x2 - x1, y2 - y1)
return ( 180 - tempAngle )
endfunction
|
|
|
Post by matthew on Aug 28, 2011 6:13:08 GMT -5
A simpler way without using Structures & Functions.
textmode(text_buffered)
dim screenCentreX = ( windowwidth () / 2 ), screenCentreY = ( windowHeight () / 2 )
dim texture = loadtex("./Data/F117.png") : dim sprite = newsprite (texture)
sprsetpos ( screenCentreX, screenCentreY )
dim mousePosX, mousePosY, asDegrees
do
cls printr "X: " ; mousePosX printr "Y: " ; mousePosY printr "Angle: " ; ( 180 - asDegrees ) mousePosX = ( mouse_x () * windowwidth () ) mousePosY = ( mouse_y () * windowheight () ) asDegrees = atn2d ( mousePosX - screenCentreX, mousePosY - screenCentreY ) sprsetangle ( 180 - asDegrees ) drawtext() loop
|
|
|
Post by Wayne Rayner on Aug 28, 2011 18:35:07 GMT -5
Thank you matthew you are to helpful.
I'm sorry for not being on sooner but I have had a wild weekend I went clubbing and got toataly smashed. I got home last night but wasn't in the mood to do anything. I'm hoping to get a gameplay test soon. So the game will use a lot of programs used in basic4GL but I like to use flash for my graphics as it is easy and fast for me (other graphics will be made in Art Studio Basic created by Crazynate and Tilemaps will be made by Tilemap Creator created by shadow. I'm thinking about writing a sound studio for creating various sounds for games but that will take a while, still going to try it out.
regards
Wayne Rayner
|
|
|
Post by Darkjester on Aug 29, 2011 14:36:05 GMT -5
try this formula to compute the angle for the object 180-ATN2D(x2#-x1#, y2#-y1#)
|
|
|
Post by matthew on Aug 29, 2011 16:55:09 GMT -5
Making an entire game from tools made with Basic4GL sounds like an interesting project Wayne.
ROFL You would have thought that I would have done that DJ. But for some strange reason I decided to split the Formula into two parts.
|
|
|
Post by Wayne Rayner on Aug 29, 2011 18:30:05 GMT -5
Well it will be an interesting project, but I did say that I will use flash for creating the player and the zombies as it I like using vector based graphics as they are easy to make.
As for other tools a Sounds program is a good idea, it will allow to make sounds easily, Basic4GL needs a program like that made from it, and the Art Studio Basic is good for graphics and Tilemap Creator is good as well. I believe that will be all I need but I'm probably missing a few other programs
|
|