@tikidays,
Hi, for my 2D applications I use my way to calculate some stuff ...
If I understand your problem well ...
You want to rotate a light around the center of a sprite (ship) in an 2D space.
Your solution
Code: Select all
Procedure lights(*source.sprite)
updateXY(*source\lights()\offsetX,*source\lights()\offsetY, *source\rotate)
DisplayTransparentSprite(*source\lights()\image, source\x + tempX , source\y + tempY ,255,*source\lights()\colour)
EndProcedure
Procedure updateXY(offsetX.f, offsetY.f, direction.f)
directionRadian.f = Radian(direction) ; convert angle from degree to radian
tempX = ((offsetX)*Cos(directionRadian))-((offsetY)*Sin(directionRadian))
tempY = ((offsetY)*Cos(directionRadian))+((offsetX)*Sin(directionRadian))
EndProcedure
I work with longer variable names, sorry but for an old guy and very complex 2D/3D drawing programs it is better for me.
Please adapt for your needs ...
Code: Select all
;- GLOBAL ZONE
Global ShipSprite_PosX.w
Global ShipSprite_PosY.w
Global ShipSprite_Width.w
Global ShipSprite_Height.w
Global ShipSprite_CenterX.w
Global ShipSprite_CenterY.w
Global Light_PosX.w
Global Light_PosY.w
Global Light_OffsetX.w
Global Light_OffsetY.w
Global Light_Distance.w
Global Light_Angle.f
;- INIT ZONE
ShipSprite_PosX = 400
ShipSprite_PosY = 300
ShipSprite_Width = 101
ShipSprite_Height = 101
ShipSprite_CenterX = ShipSprite_PosX + Round (ShipSprite_Width/2, #PB_Round_Up)
ShipSprite_CenterY = ShipSprite_PosY + Round (ShipSprite_Height/2, #PB_Round_Up)
Light_Distance = 200 ; this is the distance in px between center of sprite and the light
Light_Angle = Radian (90.0) ; this is an example angle use for next loop for 0...360 deg
Light_OffsetX = Cos (Light_Angle) * Light_Distance
Light_OffsetY = Sin (Light_Angle) * Light_Distance
Light_PosX = ShipSprite_CenterX + Light_OffsetX
Light_PosY = ShipSprite_CenterY + Light_OffsetY
Marc,
- every professional was once an amateur - greetings from Pajottenland - Belgium -
PS: sorry for my english I speak flemish ...