Can I click on the sprite?

Just starting out? Need help? Post your questions and find answers here.
AZJIO
Posts: 73
Joined: Wed Dec 14, 2022 1:13 pm

Can I click on the sprite?

Post by AZJIO »

Can I click on the sprite? Can I get the coordinates of the click relative to the "OpenWindowedScreen" window to see if the sprite was clicked?
User avatar
useful
Posts: 116
Joined: Tue Feb 25, 2014 1:15 pm

Re: Can I click on the sprite?

Post by useful »

From the screen.sb example, it is ALSO clear that the only event available is #PB_Event_RenderFrame, and the SetFrameRate(XXX) function sets the frequency of these events. And then all that is available in the Mouse library.
2B or not 2B = FF
AZJIO
Posts: 73
Joined: Wed Dec 14, 2022 1:13 pm

Re: Can I click on the sprite?

Post by AZJIO »

I tried using a sprite for the game "fifteen", but there was a poor touch screen response, so I did using Canvas. The archive contains the source.


Changed SetFrameRate(60), it became normal.
Instead of lightly touching the screen, I had to hold my finger for a long time to move the sprite. This means that "SetFrameRate" affects not only the frequency of the animation, but also the frequency of the finger tap check.
You need to specify this in the help file, since my program has little animation and the frequency is not important, but it is important that it affects the reaction time of clicking on the screen.

Code: Select all

EnableExplicit

Procedure RenderFrame()
	Protected k
	Static SpriteFinger = -1
	Static x, y

	If ExamineTouchScreen() 
		
		For k = 0 To 4 
			If TouchScreenPushed(k) And SpriteFinger = -1 
				SpriteFinger = k
			EndIf
		Next

		If SpriteFinger <> -1 And TouchScreenPushed(SpriteFinger) 
			x = TouchX(SpriteFinger) - SpriteWidth(0) / 2		  
			y = TouchY(SpriteFinger) - SpriteHeight(0) / 2
		Else
			SpriteFinger = -1
		EndIf

		DisplaySprite(0, x, y)
		FlipBuffers()
	Else
		Debug "Touch screen not detected"
	EndIf
	
EndProcedure 

Procedure Loading(Type, Filename$, ObjectId)
	Static NbLoadedElements
	
	NbLoadedElements+1
	If NbLoadedElements = 1 
		FlipBuffers()		
	EndIf
EndProcedure

Procedure LoadingError(Type, Filename$, ObjectId)
	Debug Filename$ + ": sprite loading error"
EndProcedure

OpenScreen(340, 540, 32, "Test")
SetFrameRate(60)
ClearScreen($3f3f3f)

BindEvent(#PB_Event_Loading, @Loading())
BindEvent(#PB_Event_LoadingError, @LoadingError())
BindEvent(#PB_Event_RenderFrame, @RenderFrame())

LoadSprite(0, "./data/sprite.png")
AZJIO
Posts: 73
Joined: Wed Dec 14, 2022 1:13 pm

Re: Can I click on the sprite?

Post by AZJIO »

How to test the work of sprites? It takes me a lot of time to compile and install the program on my phone. Do I need to make a PureBasic analogue of the program in order to test the code using the ExamineMouse() functions?
Fred
Site Admin
Posts: 1506
Joined: Mon Feb 24, 2014 10:51 am

Re: Can I click on the sprite?

Post by Fred »

You can also use ExamineMouse() in SpiderBasic and test in the browser
Post Reply