I managed to move around the map keeping the sprite fixed in a certain part, however, the algorithm is not " as efficient and fluid ", at some point the sprite gets stuck and doesn't leave the specific point anymore (although it still moves on the map )... (if anyone can help me improve this algorithm xD, I would be happy)
and also how do I get the position of this sprite in relation to the map? if I use the command: GetSpriteXByOffset and GetSpriteYByOffset, I get the sprite's position relative to the ViewPort...
I tried to use the following commands, but I believe I don't know how to use them, the values don't seem to be correct...
Scraggle wrote: "
WorldToScreenX()
WorldToScreenY()
ScreenToWorldX()
ScreenToWorldY()
"
// Project: MyLearnGame
// Created: 2022-01-11
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "MyLearnGame" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
global sprite
sprite = CreateSprite(LoadImage("sprite_00.png"))
//SetSpriteSize(sprite, 1, 100)
SetSpriteOffset(sprite, GetSpriteWidth(sprite)/2, GetSpriteheight(sprite)/2)
SetSpritePositionByOffset(sprite, 100, 100)
FixSpriteToScreen(sprite,1)
do
Printc("Sprite Angle is ")
Print(Str(GetSpriteAngle(sprite),2)+" Degrees")
MouseX# = GetPointerX()
MouseY# = GetPointerY()
PointSprite(sprite,MouseX#,MouseY#)
MovePlayer()
Sync()
loop
function MovePlayer()
x# = GetSpriteXByOffset(sprite)
y# = GetSpriteYByOffset(sprite)
Vx# = GetViewOffsetX()
Vy# = GetViewOffsetY()
angle# = GetSpriteAngle(sprite)
speed# = 2.0
if (GetRawKeyState ( 65 )) //LEFT
if (x# >= 400) and (x# <= 800)
inc x#, sin(angle#-90) * speed#
endif
if (y# >= 200) and (y# <= 600)
dec y#, cos(angle#-90) * speed#
endif
inc Vx#, sin(angle#-90) * speed#
dec Vy#, cos(angle#-90) * speed#
endif
if (GetRawKeyState ( 87 )) //DOWN
if (x# >= 400) and (x# <= 800)
inc x#, sin(angle#) * speed#
endif
if (y# >= 200) and (y# <= 600)
dec y#, cos(angle#) * speed#
endif
inc Vx#, sin(angle#) * speed#
dec Vy#, cos(angle#) * speed#
endif
if (GetRawKeyState ( 68 )) //RIGHT
if (x# >= 400) and (x# <= 800)
inc x#, sin(angle#+90) * speed#
endif
if (y# >= 200) and (y# <= 600)
dec y#, cos(angle#+90) * speed#
endif
inc Vx#, sin(angle#+90) * speed#
dec Vy#, cos(angle#+90) * speed#
endif
if (GetRawKeyState ( 83 )) //UP
if (x# >= 400) and (x# <= 800)
inc x#, sin(angle#+180) * speed#
endif
if (y# >= 200) and (y# <= 600)
dec y#, cos(angle#+180) * speed#
endif
inc Vx#, sin(angle#+180) * speed#
dec Vy#, cos(angle#+180) * speed#
endif
SetSpritePositionByOffset(sprite, x#, y#)
SetViewOffset(Vx#,Vy#)
endfunction