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 / DrawSprite in iOS

Author
Message
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 26th Jul 2017 01:29
I am using RendertoImage and then RenderToScreen to draw some sprites onto the screen. Works fine on my Mac, but when i broadcast to iOS, these sprites are shifted out of position horizontally.
(The code sets a virtual resolution of 1440 x 900).
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Jul 2017 01:45
What is the resolution of the ios device?
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 26th Jul 2017 12:47
The iOS device is 1920 x 1080.
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 26th Jul 2017 16:22
That tells you the aspect ratio is different. You could apply a corrective multiplier based on the aspect so they appear in the correct place.
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 26th Jul 2017 18:18
should the multiplier apply to x/y coordinates as well as width and height of the draw sprite? I'm not having any luck with implementing a multiplier.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 26th Jul 2017 21:32
You can temporarily change the virtual resolution to match you device. Then change it back after render to image
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 27th Jul 2017 00:05
Tried changing the virtual res, and although the graphics lined up correctly, everything was a lot smaller than it was supposed to be even after I switched the virtual resolution back. Not sure how to handle this.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Jul 2017 01:13
Can you post your rendertoimage() result and then some indication of you would like it to look?
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 27th Jul 2017 12:19
I've uploaded two screenshots one for the bad result and one for the good. As you can see the trees and other obstacles on the board are rendered at the device resolution, but not large enough for the final virtual resolution.

Attachments

Login to view attachments
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 27th Jul 2017 12:21
good result attached.

Attachments

Login to view attachments
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 27th Jul 2017 21:25
And some of the code maybe
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 28th Jul 2017 00:18
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Jul 2017 00:34 Edited at: 28th Jul 2017 00:35
I think it's because you're regenerating those sprites (Not sure what goes on in those functions)
What i would do is;


Also, what is the size of your render image?
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 28th Jul 2017 00:38
The render image is 1440 x 900
Here is what is happening in GenerateTRees():



As you can see the function uses DrawSprite to place each tree.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Jul 2017 02:44 Edited at: 28th Jul 2017 06:56
I'm not 100% sure but i think it might have to do with the fact that your using setspriteposition() AFTER you have changed the resolution

I attached a small example
1. touch to render to image (then the rendered image is displayed)
the screen is rendered to an image at your devices resolution 1920 x1080 in your case
a sprite is created and scaled using a calculation based on the GetScreenBounds() functions and GetDeviceWidth/Height() to calculate the ACTUAL resolution of your render area

2. touch to return to render to screen (if you touch in the bottom right corner it will send the image to the app of your choice (mail, dropbox etc))

**Update** Was not working!!! Now it is working

***Update***
I added another project (renderimage1) that just uses the actual aspect of the render area by using the getbounds() functions to calculate the width/height so there is no scaling required

Attachments

Login to view attachments
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 28th Jul 2017 13:52
Thanks. I'm trying to understand how your example works. When I click the mouse button, I don't see any change in the display - should I be?
tmu
7
Years of Service
User Offline
Joined: 2nd Feb 2017
Location:
Posted: 28th Jul 2017 21:25
I don't understand. Why do you need to keep changing virtual resolution? Should you not just draw at same resolution all the time and AppGameKit will scale it for you on the actual device?

Maybe you could make some example project that runs and is just very much stripped down version of your project. Like render any small pic on similar background to show the displacement effect. Probably people will quickly see how to fix then.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 28th Jul 2017 23:47 Edited at: 28th Jul 2017 23:50
Quote: " Thanks. I'm trying to understand how your example works. When I click the mouse button, I don't see any change in the display - should I be?"

No. Nothing changes because it is an EXACT capture of the screen. If you tap in the very far lower right it will send the .png file to your email/sms etc

I found i didn't need to change the resolution (I read that somewhere but you don't have to do that at all. See renderimage1.rar).

The most important thing in that example is the it uses GetScreenBoundsRight() - GetScreenBoundsLeft() to calculate the width and GetScreenBoundsBottom() - GetScreenBoundsTop() to calculate the height of the RenderToImage()
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 29th Jul 2017 01:19
based on your example I now have the following:



This results in no trees or obstacles appearing. So it seems that there is something wrong in the way the render image is created.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jul 2017 01:35 Edited at: 29th Jul 2017 08:22
Do you see the "field" sprite in the rendered image?

One other thing. I'm looking at your function GenerateTrees() and it appears to me that it only draws one tree (TreeSprite) and at the end of the function makes it invisible. Is that right?

greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 29th Jul 2017 13:42
Yes the field sprite appears in the final render. The GenerateTrees() function fills the map with a random number of trees using DrawSprite() function, but uses only a single tree sprite to do it.
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 29th Jul 2017 18:30
Quote: "I don't understand. Why do you need to keep changing virtual resolution? Should you not just draw at same resolution all the time and AppGameKit will scale it for you on the actual device?"


Can you explain how AppGameKit would scale on the actual device?
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Jul 2017 23:39
Attached is a project that uses your technique to render the sprites. Works fine for me

Attachments

Login to view attachments
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 31st Jul 2017 00:01
I guess the difference is that I am using a game map that is a different width and height than my iOS device (it is identical to my Mac display). The problem seems to occur as soon as the DrawSprite command is used. Placing Sprites using SetSpritePosition() doesn't cause a problem.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 31st Jul 2017 01:45
The example i posted uses a different resolution as well and it works ok
greycheek
8
Years of Service
User Offline
Joined: 13th Mar 2016
Location:
Posted: 31st Jul 2017 19:05
Finally solved the problem this way:



Curious because the documentation says setting aspect ratio shouldn't be necessary when setting a virtual resolution, only when using the default coordinate system.

Login to post a reply

Server time is: 2024-03-29 14:03:52
Your offset time is: 2024-03-29 14:03:52