Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / SetSpriteUV on Android

Author
Message
JohnStabler
AGK Bronze Backer
11
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 1st Apr 2016 22:58
I'm using SetSpriteUV() and it seems to work on Windows but not on Android. The sprites simply don't appear.

Can anyone confirm?

[CODE]
fontImage = LoadImage("square-font.png")

for i = 0 to 9
numberSprites[i] = CreateSprite(fontImage)
SetSpriteDepth(numberSprites[i], 9)
SetSpritePosition(numberSprites[i], (i * 22), 100)
next i

SetNumberUV(numberSprites[0], 0, 33, 29, 33)
SetNumberUV(numberSprites[1], 29, 33, 19, 33)
SetNumberUV(numberSprites[2], 48, 33, 29, 33)
SetNumberUV(numberSprites[3], 77, 33, 29, 33)
SetNumberUV(numberSprites[4], 106, 33, 29, 33)
SetNumberUV(numberSprites[5], 135, 33, 29, 33)
SetNumberUV(numberSprites[6], 164, 33, 29, 33)
SetNumberUV(numberSprites[7], 193, 33, 29, 33)
SetNumberUV(numberSprites[8], 220, 33, 29, 33)
SetNumberUV(numberSprites[9], 249, 33, 29, 33)

do
Sync()
loop

function SetNumberUV(spriteID, x#, y#, width#, height#)

sw = width#
sh = height#
x# = x# / 452.0
y# = y# / 198.0
width# = width# / 452.0
height# = height# / 198.0
SetSpriteUV(spriteID, x#, y#, x#, y# + height#, x# + width#, y#, x# + width#, y# + height#)
SetSpriteSize(spriteID, sw, sh)

endfunction

[/CODE]
Hi. I am a real person (not a bot). I appreciate all replies and advice.
Funnell7
13
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 2nd Apr 2016 07:43
First thing I'd check is your file name case. square-font.png is not the same as square-font.PNG... Not an issue for Windows, but Android and iOS are very case sensitive.
Using AppGameKit V2 Tier 1
JohnStabler
AGK Bronze Backer
11
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 3rd Apr 2016 20:32
Sorry, I should have said. I tried loading the image in to a sprite to make sure it would display on Android and it worked fine.
Hi. I am a real person (not a bot). I appreciate all replies and advice.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Apr 2016 06:35 Edited at: 4th Apr 2016 06:36
I just tested one of my apps, and the UV is working on Android.
I have a small issue with it, although the sprite is powers of 2 (128 x 512) it has shrunk on the y-axis by about 5%. The white reels should be white all the way from top to bottom, they have a gap that is not there on Windows.

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt

Attachments

Login to view attachments
JohnStabler
AGK Bronze Backer
11
Years of Service
User Offline
Joined: 16th Aug 2013
Location: Cardiff, Wales, UK
Posted: 4th Apr 2016 14:30
BatVink, you may have just identified my problem. My texture's dimensions may not be power of 2. I'll check when I get home this evening.
Hi. I am a real person (not a bot). I appreciate all replies and advice.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Apr 2016 15:42
@BatVink: Yours isn't an aspect ratio problem is it?
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 4th Apr 2016 16:46
I'm not quite sure how the aspect ratio would cause this problem (my ignorance). But I have changed the ratio from 4:3 to 16:9, and the problem is exactly the same - works on windows, gap on Android.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 4th Apr 2016 18:55
You might need to adjust the height of the sprites to fit the Android screen with something like:


As a simple test, set your Windows window to the same size as your Android resolution (with SetWindowSize( 480, 800, 0 ) (for a Samsung Galaxy S2 example)) to see if you get those gaps on Windows too.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Apr 2016 11:30
I'm working with Paul on something, and he gave me this info. Pretty much what CJB said, along with a solution to the problem. The extra info you need to know is that I created my images with GetImage, it turns out this is where it goes wrong...

Quote: "the difference is due to the device not having a screen of exactly 1280x800 pixels, which means GetImage will return an image of a different size. The general rule is that if your virtual resolution does not match the window size, then the size values used in GetImage will not match the image size (but they are directly proportional). This means the image isn't a power of 2 and has some padding. You can work around this by using SetVirtualResolution(GetDeviceWidth(),GetDeviceHeight()) whilst you are creating images with GetImage, then the images are guaranteed to match the values you pass to GetImage. Just make sure that the device size is big enough for the image you want to create, i.e. a screen of size 480x360 can't create a 512x512 image."
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 7th Apr 2016 14:52
Quote: "I created my images with GetImage"
I ran into issues when trying to work with getimage (specifically the image size to screen size restrictions) so I built some functions that allow you to create an image of any size, and paste smaller images into it. Those functions proved super useful for building atlas images. I don't know if they'll suit your requirements, but it might give you an idea of an alternative way to achieve what you are trying to do.
V2 T1 (Mostly)
Phone Tap!
Uzmadesign
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Apr 2016 17:20
Sounds good and highly appreciated Maybe on another thread or by email, I feel I have hijacked this one.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 10th Apr 2016 20:34 Edited at: 10th Apr 2016 20:35
Oops! I only just realised I didn't post the link to those functions! Here it is:
https://forum.thegamecreators.com/thread/215958

Haha... I can see you've already seen them!
V2 T1 (Mostly)
Phone Tap!
Uzmadesign

Login to post a reply

Server time is: 2024-09-29 13:25:19
Your offset time is: 2024-09-29 13:25:19