Posted: 18th Oct 2021 17:42
you're getting the sprite Offset(s) when you mean GetSpriteX/YByOffset
+ 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

click the boxes
Posted: 18th Oct 2021 18:20
Virtual Nomad

Thanks, I will look at it and learn from it.


Great example by the way.
Posted: 18th Oct 2021 18:35
How do I se my players angle to match the swing?

I set my sprite player not to rotate so im hoping my player can have its angle set to.
Posted: 18th Oct 2021 20:14
How do I se my players angle to match the swing?

what have you tried so far?
Posted: 18th Oct 2021 20:37
what have you tried so far?


This works good but when I get off the swing my angle is all messed up.

+ Code Snippet
if GetPhysicsCollision(player,rope_2)=1
	ropeAng=GetSpriteAngle(rope_2)
	SetSpriteAngle( player, ropeAng )
endif


I tryed this but it maes my player shake back and forth

+ Code Snippet
if GetPhysicsCollision(player,rope_2)=1
	ropeAng=GetSpriteAngle(rope_2)
	SetSpriteAngle( player, ropeAng )
else
SetSpriteAngle( player, 0 )
endif
Posted: 18th Oct 2021 21:02
when I get off the swing my angle is all messed up.
set it to whatever when you get off the swing.

player shake back and forth
it seems its getting on/off/on again (over and over).

if you put a timer() between getting off and when it can get back on again, it could help.

if you make it a selectable action (getting on/off the rope using a button, for example), that would solve as well but you need to make a rule/trigger, somehow.

then,
+ Code Snippet
if GetPhysicsCollision(player,rope_2)=1
    ropeAng=GetSpriteAngle(rope_2)
    SetSpriteAngle( player, ropeAng )
else
SetSpriteAngle( player, 0 )
endif

is going to constantly set the angle to 0 when not colliding with rope_2. if you leave that "as is", forget about changing angles anywhere else.

meanwhile, if you haven't already implemented sprite groups, the further you get into adding various elements, the more obvious the need will become.
Posted: 19th Oct 2021 2:27
Virtual Nomad

I was thinking about setting a distance and if im not in that distance my angle will reset.

Ill let you know if this works.

And yes, I am using sprite groups to filter bullets and other things like coins.

I am very surprised at how much code this game has already lol/

but in the old days they used millions of lines of coding.


Edit:::

This works good here

+ Code Snippet
rope_Dis=GetSpriteDistance(player,rope_2)
if rope_Dis<5 and GetspriteCollision(player,rope_2)=1
	ropeAng=GetSpriteAngle(rope_2)
	SetSpriteAngle( player, ropeAng )
	SetSpritePhysicsFriction(player,1)
endif

if rope_Dis>5 and GetspriteCollision(player,rope_2)=0
SetSpriteAngle( player, 0 )
endif	
Posted: 19th Oct 2021 21:46
scrolling sprite

Ok so i decided to play around with scrolling my background instead of loading 70 back ground sprites and I don't like the effect.

it looks real bad.

I need the background to scroll at my players speed only if my player is moving, sometimes my player gets stuck even if the button is pushed or joystick.

So somehow I need to figure out how to scroll my background at my player speed.

this is what I am doing and it well, not so good.


+ Code Snippet
SetSpritePositionByOffset(background_1,PX#,50)

    move=GetSpritePhysicsVelocityX( player )
    x# = GetJoystickX()
    if running=0 then u# = u# +x#/240
    if running=1 then u# = u# +x#/200
   if Move>3 or Move<-3 then SetSpriteUVOffset(background_1,u#,0.0)
Posted: 19th Oct 2021 23:13
I think .... player x / screen width, use Mod to get the remainder and thats your offset
Posted: 19th Oct 2021 23:45
PartTimeCoder

I divide my screen width to my Player x to get a speed?

I'm a little confused here sorry.

All I need is a good way to scroll my background to my player speed and only if they are moving.
Posted: 20th Oct 2021 0:26
rather than trying to match the speed just use the players x position, we can use Mod() but there isnt much need and I think mod has overhead we dont want in a loop, just use what you already have, the players position, if the background is going to scroll with the player then just use the players global x position to offset your UV, so now mid jump and he suddenly stops the background stops with him

its best not to use SetSpritePosition while using physics but Get... we can use that as much as we want to no effect
Posted: 20th Oct 2021 3:05
PartTimeCoder

I did a test to see the memory with 70 background sprites to just using one and I have more memory with just one as I scroll the texture.
Like 30 mg more memory.

So I've decided not to scroll, its a bad idea.

Thanks for your help anyhow.

I do appreciate it.
Posted: 20th Oct 2021 18:10
Are you saying scrolling an image requires 30mb of memory ...

I really doubt that, I have an Asteroid type setup using physics in infinite space environment that uses the below function to scroll the background with a lerp and the entire game run at 20mb, if you are adding 30 by scrolling an image the you are doing something very very wrong!

a single 1024x1024 background covers the entire universe but never moves, I just offset the image to give the illusion of movement

+ Code Snippet
Function StarSystem_Update()
	view_x# = GetViewOffsetX()
	view_y# = GetViewOffsetY()
	new_x#=GetSpriteXByOffset(gPlayer.sprite_id)-RES_WIDTH/2
	new_y#=GetSpriteYByOffset(gPlayer.sprite_id)-RES_HEIGHT/2
	lerp_x# = Lerp( view_x#, new_x# , 0.1 )
	lerp_y# = Lerp( view_y#, new_y# , 0.1 )
	SetViewOffset(lerp_x#, lerp_y#)
	SetSpriteUVOffset(gStarSystem.back_id, GetViewOffsetX()/2500, GetViewOffsetY()/2500 )
EndFunction


although it is a little jumpy in the browser : https://parttimecoder.itch.io/space-game-thing?secret=LgiU3MpR1yiHtfxxt7bO94SyZS4
Posted: 20th Oct 2021 19:07
I really doubt that


+ Code Snippet
    print("Gpu memory                  = "+str(GetImageMemoryUsage() ))
    print("Pixels drawn                = "+str(GetPixelsDrawn() ))
    print("Images in memory            = "+str(GetLoadedImages()  ))


I've done many tests and I was also very surprised myself.

And to be honest with you, I don't want any jumps in my scrolling and there are many to count.

every time when I get stopped mid air in a jump.

Plus I don't plan on adding any more to any level, all my levels are going to match each other in sprite counts, I hope.
Posted: 20th Oct 2021 20:32
I've done many tests and I was also very surprised myself.


Because you don't understand it, does not mean its broken.

I have a rather old low end laptop if a function has overhead believe me I would encounter it.
Posted: 20th Oct 2021 23:21
not mean its broken


I never said anything about being broken my friend.

But I do understand memory and sprites loaded and just about everything there is to know about computers.

What is it I don't understand?

Please explain so I can know myself.
Posted: 21st Oct 2021 0:00
Seriously, now that's a bold statement for someone that did not know what Box2D was?, maybe not everything then, huh?

ok, the render pipeline, understanding memory and computers you will understand that the image is sent to the GPU, the default sprite shader generated by AppGameKit sends texture coord's to tell the GPU where to draw your sprite within its frame, using SetSpriteUVOffset simply changes the value sent to the shader telling the GPU what to draw, no overhead is add, no extra arguments sent, no extra memory used, I fail to see how it affected your memory usage and have explained in detail how I have come to that conclusion but you assert that it did, one of us is misunderstanding something here!
Posted: 21st Oct 2021 2:20
Edit out.
Posted: 24th Oct 2021 5:32
Well Here is a update on level 2, still have a lot more to do.

I added many new aspects to this level and for future levels.

Note: The game will be much faster pace then this, I just slow it down to show the progress.
Posted: 24th Oct 2021 16:57
A bit of a weird sliding action while on the platform and your animations are still a bit out of sync size wise but dam, your levels look fantastic, the rope jump works well just a shame that sprite does not have a "grab" animation

Your jump physics look 100% better, still a tad high maybe but a nice arc your settings are almost spot on and she seems to land with a bit of a thump, which is good.

Again your levels look great, its just a crying shame that AppGameKit does not have out of the box 2D lighting as your level would really benefit from a little atmosphere.

Overall I'd say its coming along nicely, 10/10 for effort, well done