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 / SetScissor () Problem

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 11th Dec 2014 10:34
Hi.

I create a game with (1280 x 800) resolution that show in windows without black border. but when I export it to android, left side have black border.

according to Development Tips (Removing black borders) at help file, I used SetScissor(0,0,0,0) for fix black borders but black border still exist.

I used GetScreenBoundsLeft() and GetScreenBoundsRight() for show what is negative value, that show -20 at left and 1300 at right.

how can fix this Problem?
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 11th Dec 2014 11:41
Can we see some code please? Even just a sort example to demonstrate the problem.

I use SetScissor(0,0,0,0) a lot, although I had no idea about the GetScreenBounds commands. Instead I had been working out the difference by using the device screen width and height.

It seems to work ok for me, using both versions of AppGameKit and on a whole variety of Android test devices.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 11th Dec 2014 15:10
Quote: "Can we see some code please?"


this is my code:

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 12th Dec 2014 13:58 Edited at: 20th Dec 2014 00:02
1280 x 800 gives an unusual aspect ratio.
I\'m not saying it\'s wrong but it could be the cause if your device doesn\'t support those screen dimensions.

1280x720 is a more normal aspect ratio - Have you tried that?

[Edit to add image]

Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 12th Dec 2014 14:36
1280x720 or 1280x720 have same problem.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 13th Dec 2014 21:38 Edited at: 13th Dec 2014 21:42
The problem in this case is not the SetScissor() command, it's that although you have changed the drawing area, you have not changed AGK's "edge of screen" physics walls.

I couldn't find a command to change them, but you can turn them off



And then create your own (by using invisible sprites or something) where the app needs them to be.

>Edit<

A better example of what SetScissor() does would be to create a full screen sprite to use as a background, Create it 50px too large all round, and position it at -50,-50. Then rem out the setscissor() command, run the program, un-rem the setscissor() and run it again.

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 13th Dec 2014 21:51 Edited at: 13th Dec 2014 21:52
I turn off edge of screen with your code but black border still exist.

Quote: "Then rem out the setscissor() command, run the program, un-rem the setscissor() and run it again."


I can't understand your mean.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 14th Dec 2014 01:03 Edited at: 14th Dec 2014 01:05
Using SetScissor() allows sprites to be drawn "outside" of the normal screen co'ords, but you still need to position them there.



I hope this code explains better

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 18th Dec 2014 20:29 Edited at: 18th Dec 2014 20:41
Quote: "
Using SetScissor() allows sprites to be drawn "outside" of the normal screen co'ords, but you still need to position them there."


I have AppGameKit v1. but I compiled your code like this:



but show me a Green background like this:



I don't understand your mean with this code. because it don't fix any Problem.
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 19th Dec 2014 07:32 Edited at: 19th Dec 2014 07:40
You need to broadcast it to an android device, to get the borders, will not work in windows!

It means, that the coordinate system starts at 0,0 and if you have black borders, then this is not in the upper corner of the screen, but to the right of the black border.

To show a sprite on the black border, you need to use negative coordinates, to get it there.

If your black border at the left is 40 pixel wide, then the screen starts at -40,0

You can not "stretch" the game to fill the screen, just use the scissor command, to force the screen to show graphics there, even if it's outside the defined resolution.

It's like Commodore 64, and placing sprites in the border of the screen, if your old enough to remember that.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 19th Dec 2014 07:47
Try this example on an android device, to understand it better



----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Dec 2014 11:47
Thanks Impetus73.

but I can't understand your mean.

at first post I said black border is -20 at left side and when I use SetScissor(0,0,0,0) no fix black border. the problem is that SetScissor(0,0,0,0) don't work.

this a Picture from your last code at my phone:

Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 19th Dec 2014 12:03
Does the red box not move over the black borders?, or is it hidden beneath?

The green will not be expanded, you need to add a sprite that is big enough to cover the black borders.

The black borders, are just areas of the screen of the physical device, that the resolution you selected does not cover.

If you don't understand this, then you should ignore the borders for now. Borderless programming, is harder, you need to adjust the UI, placements of physics borders, and handle the added negative values.

If you remove the scissor command from the code I gave you, you will see that the red dot does not move over the borders.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Dec 2014 12:55 Edited at: 19th Dec 2014 12:56
this is your code that I change Sprite size to (1300,800) and setvirtualResolution (1280,800) and set width and height at Setup.agc to (1280,800). but still black border exist.



this is a Picture:



Quote: "
you need to adjust the UI, placements of physics borders, and handle the added negative values."


how?
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 19th Dec 2014 18:03
There is no black borders here:



To answer the last question, Not easily! This would require a whole tutorial, and everything in the game would have to be set up to compensate for the real width and height of the user's screen.

Most people either let the black bars just appear, or they fill them with some static graphics.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Dec 2014 20:10 Edited at: 19th Dec 2014 20:39
thanks Impetus73. you could hide black border under green sprite but important Problem is hidden under background.

I create a sprite that can move to left and right with Virtualjoystic in android devices. but sprite can't move more than red line in below picture.

for fix this Problem I disable Physics wall with below code:



and create a invisible sprite for fix this Problem but don't change anything.wall move to right and is like a hidden wall under green background.


this is full code:






I exported APK with some 2d engines and never seen any Problem like AGK.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Dec 2014 20:39 Edited at: 19th Dec 2014 20:39
Maybe I'm missing something here but if black bars are your problem then wouldn't this stop them from ever occurring?


Or this?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Dec 2014 21:09 Edited at: 19th Dec 2014 21:22
use "SetVirtualResolution(GetDeviceWidth(), GetDeviceHeight())" fix black border but show half of my map. (new Problem)

Seem this Problem is a Bug in AGK. because "SetScissor(0,0,0,0)" good work in windows but don't work on Android Devices.
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 19th Dec 2014 22:16
@Scraggle, Using SetScissor allows you to use the entire screen and maintain the Aspect Ratio that you designed the game in.

Both of the solutions you provided will alter the aspect ratio to that of the device, and will stretch or distort

@Behdadsoft:
Your wall is 10 pixels wide. You are positioning the top left hand corner of the sprite at the edge of the screen. Your sprite is stopping when it hits the other side of your sprite.

To fix this problem, position the wall sprite like this...



Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th Dec 2014 23:50 Edited at: 20th Dec 2014 00:21
Quote: "Both of the solutions you provided will alter the aspect ratio to that of the device, and will stretch or distort"

Yep, a bit of test shows that you are absolutely correct!

A bit more testing (after a few beers so forgive me if understand this incorrectly) tells me that to avoid any stretching we should always maintain an aspect ration of 1 - a perfect square and then to avoid any black bars, do something like this:



That uses a 1x64 pixel sprite (sky.png) stretched to fill the screen and a 256x256 pixel image just to show that it is still square and unstretched.

That to me seems like the way to set up any game - although I might see things differently in the morning without the beer goggles.

Same code, two screen sizes:

Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 20th Dec 2014 05:21
Quote: "To fix this problem, position the wall sprite like this...

+ Code Snippet
SetSpritePosition(wall,psxL-10,0)"


negative value is not same at all devices.in my device negative value is -20 and in my second device is -71. this solution is not work for all devices.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 20th Dec 2014 13:20 Edited at: 20th Dec 2014 14:36
In the sober light of day I stand by my code.

Here is a media-less version that will work for both percentage and virtual resolutions.
No black bars, and sprites can be positioned at the edges of the display regardless of its dimensions and/or aspect ratio:



Attachments

Login to view attachments
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 20th Dec 2014 22:04
thank Scraggle, but your code is very Slut and I can't understand it.
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 20th Dec 2014 22:09
I can only apologise on behalf of my code, I had no idea it was so promiscuous.
Funnell7
12
Years of Service
User Offline
Joined: 8th Sep 2011
Location: UK, England
Posted: 20th Dec 2014 22:28
Lol...
=PRoF=
21
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 21st Dec 2014 01:08 Edited at: 21st Dec 2014 01:12
@Behdadsoft:

Quote: "negative value is not same at all devices.in my device negative value is -20 and in my second device is -71. this solution is not work for all devices. "


The negative value for the edge of the screen is handled by the variable psxL and it changes depending on the device running the program, the -10 is simply the width of the invisible sprite you are using as a wall.

>Edit<
I'm also not sure "slut" was quite the word you were trying to say...

Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 21st Dec 2014 08:52
I think Behdadsoft just needs to learn some programming, before starting to make this kind of complicated code. He does not seem to grasp the most basic of concepts. I don't know how to dumb this down any more, since it's hard to cope with even for seasoned programmers.

People who are new to programming, should not jump into deep water. Leave the black bars, and deal with them when you understand why they are there.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
JimHawkins
14
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 21st Dec 2014 11:44
Totally agree.

-- Jim - When is there going to be a release?
Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 21st Dec 2014 11:46
Best advice so far!
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Dec 2014 12:27
I understand your code Scraggle and is not Slut.

but your code don't work in my project.

this is my code. I add your code after "do---loop" and add
"initDisplay( VIRTUAL, 1280, 800 )" at first line of my project. but when I export it to my phone don't change anything.



this your code that I Improve it for myself that could better understand.
I remove 4 box and create a Player that can move to left and right. but seem there is a invisible wall in top and bottom of screen.but when export it to my phone, there is no invisible wall at left and right.

Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 21st Dec 2014 14:48
You are back to square 1...

Disable the built in physics walls (They only care about the virtual resolution, not the extra black bar area), and place dummy sprites outside the borders, as you did before.

The physics system does not automatically extends into the borders, even if you think you magically made them go away, the borders are still there

The last code example, works fine on my android HTC one M8, it just stops at the physics walls at coordinates 0,0 and 1279,0, not -25,0 and 1304,0 as they should.

----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Dec 2014 14:52
Quote: "The last code example, works fine on my android HTC one M8, it just stops at the physics walls at coordinates 0,0 and 1279,0, not -25,0 and 1304,0 as they should."


in last code, sprites no have physics and work very well. but my sprite have Physics and collide with invisible walls.
Impetus73
12
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 21st Dec 2014 15:07
Using only code from your own examples:



----------------
AGK programmer
Did Amiga / AMOS programming in the 90's.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Dec 2014 15:52
Thanks Impetus73. now work very well

Login to post a reply

Server time is: 2024-04-26 07:16:35
Your offset time is: 2024-04-26 07:16:35