you're getting the sprite Offset(s) when you mean GetSpriteX/Y
+ Code Snippet// Project: rope
// Created: 2021-07-03
// By: Virtual Nomad
// show all errors
SetErrorMode(2)
SetPhysicsGravity(0,200)
// set window properties
SetWindowTitle( "rope" )
SetWindowSize( 1280,720, 0 )
SetWindowAllowResize( 1 )
// set display properties
SetVirtualResolution( 1280,720)
SetOrientationAllowed( 1, 1, 1, 1 )
SetSyncRate( 60, 0 )
SetScissor( 0,0,0,0 )
UseNewDefaultFonts( 1 )
GLOBAL Boxes as Integer []
for x = 1 to 4
Boxes.Insert (AddBox(x))
next x
Boxes.Sort()
Base = CreateSprite(0) : SetSpriteSize(Base, 200,32) : SetSpritePositionByOffset(Base,100,300)
SetSpritePhysicsOn(Base,1) : SetSpritePhysicsFriction(base,0.0)
Player = CreateSprite(0) : SetSpriteSize(Player,32,32) : SetSpritePositionByOffset(Player,100,100)
SetSpritePhysicsOn(Player,2)
SetSpritePhysicsCanRotate(Player,0)
SetSpritePhysicsFriction(Player,0.1)
Red = MakeColor(255,0,0)
Hook = 0
Hooked = 0
do
PX# = GetSpriteXByOffset(Player) : PY# = GetSpriteYByOffset(Player)
MX# = GetPointerX() : MY# = GetPointerY()
LR# = GetJoystickX()*50.0
SetSpritePhysicsImpulse(Player, PX#,PY#, LR#, 0.0)
If GetPointerPressed()
This = GetSpriteHit(MX#,MY#)
If Boxes.Find(This) => 0
If Hook > 0
If GetJointExists(Hook) then DeleteJoint(Hook)
Endif
Hook = CreateRopeJoint(PLayer,This,PX#,PY#,MX#,MY#,200.0,1)
RX# = MX# : RY# = MY#
Hooked = 1
Endif
Endif
If Hooked > 0 then DrawLine(PX#,PY#,RX#,RY#,Red,Red)
If GetRawKeyState(27) then End
Sync()
loop
Function AddBox(x)
ThisBox = CreateSprite(0) : SetSpriteSize(ThisBox,64,64)
SetSpritePositionByOffset(ThisBox,200 + x*200,100)
SetSpriteColor(ThisBox,Random(128,255), Random(128,255), Random(128,255), 255)
SetSpritePhysicsOn(ThisBox,1)
EndFunction ThisBox