Need a simple Android touch routine

Previous topic - Next topic

MrPlow

Hi

I need a simple enough routine that will work the stretchsprite method of screen scaling....

I am not sure about the maths for the mouse x y offsets using a higher res.

Can anyone point me in the right direction?

Gary
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

kanonet

Untested, but you should get the idea:

Code (glbasic) Select
// at program start:
LOCAL mouseoffsetx#, mouseoffsety#
GETSCREENSIZE mouseoffsetx, mouseoffsety
virtualx = 800   // width of your virual screen
virtualy = 600   // hight of your virtual screen
mouseoffsetx = sx/virtualx
mouseoffsety = sy/virtualy

// in your program loop:
MOUSESTATE mx, my
mx = mx*mouseoffsetx
my = my*mouseoffsety
// now you can use mx and my like you would do on a normal, not scaled screen
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

erico

Great! Kanonet! :good:

That helps me out too since it is less code then what I had planned first for my case.

MrPlow

Thanks Kanonet!

Sorry for the delay...work commits etc...cant wait to try it...

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

Does this work for Android touch or just normal mouse??
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

Sorry for the noob question here but ... is the virtual screen the screen being stretched or the screen res of the device?

320 x 240 (res of working app) virtual?

800 x 600 (res of device say...) actual?

offx = 800 / 320

Also for mxbutton = 200 does mxbutton now become 200 * offx as well?

or is it reversed and the 200 / offx ?

My device is showing a di
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

Think i got it...my createscreen had the wrong y value so trying now fingers crossed!!!
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

sorry again....but confused should the 800 x value be my "tall" coords and therefore y not x??

I thought i had it but my screen is gone wonky..
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

MrPlow

Is there an ingredient missing here.... what about dpi and HD devices?

Do I need to calc for devices like my Nexus 7 II ?

Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

kanonet

OK, that arent few posts... wouldnt it be faster/easier to try instead of asking? Anyway:
virtualscreen is the screen that you created with CREATESCREEN, so it has the size that you want to design your app with. It doesnt matter if you run your app on a low res device or a HD one, it will always get scaled to fill the full screen - i mean thats why we do this here, its the purpose of this snipped, right? Please note, that this will always fill the full screen, so it might break the screen ratio, e.g. if you create your virtual screen with 4:3 ratio and your device has a screenratio of 16:9 you will strech it fully, so quads will become rectangles etc. If you dont want this behaviour, but instead prefer some black (or any other color or image) borders, you need to adjust the code. I recommend that you set the resolution in the project settings to 9999x9998 or 9998x9999 so your up runs on the highes possible resolution of your device and you can fally scale what ever you want.
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64

MrPlow

I have a drop down in project settings and 9998 x 9999 is not one of them...does that go in a text file...also, another thing bugging me is my app name is not changing even though I changed in Android manifest.xml

Appreciate the help...free 'chess clock' coming your way ;-)

G
Comp:
Speccy-48k, Speccy-128k, Amigas, PCs

kanonet

If a resolution that you want to use is not in drop down menu, you can simply input it by hand. I dont know about changing the name in manifest, why not just change it in project settings?
Lenovo Thinkpad T430u: Intel i5-3317U, 8GB DDR3, NVidia GeForce 620M, Micron RealSSD C400 @Win7 x64