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 / Limit 2D drawing box ?

Author
Message
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 5th Apr 2020 15:34
Hello,

Is there a way to define a box inside the screen, where graphics can be draw ( 2D, Images, Sprites, etc.) ?
I didn't found commant for that and SetScissor don't work for direct sprite drawing cutting.

Regards,
Fred
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 5th Apr 2020 15:48
not sure exactly what you are after but creating an image could be done simply by the following this then could be used for a sprite

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 5th Apr 2020 17:40
@Fubarpk :
Thank you for your reply. I understand your idea, but due to the fact that more than 1 clipping must be done per frame, use the render() / getImage will not be really ... fast :p
I'd prefer something that says for example :

DrawingArea( 48,10,630,460 ) : Mean 2D graphics are not drawn out of the box p1=48,10 ; P2=630,460.
When I paste a sprite at 30, 20 for example, the pixels from X=30 to X=47 are not drawn and only the part of the sprite that should be render from X=48+ will be rendered.
It's a sort of clipping.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 5th Apr 2020 21:07
Can you explian a little more why setscissor won't work. It seems like it's tailor made for your situation
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 5th Apr 2020 21:27 Edited at: 5th Apr 2020 21:30
I use draw sprite to display layers and tiles on screen.
When the user click on the "resize window" button (that makes application being full screen), if original screen ratio X/Y is lost, you can see larger area than the display I have created and then on the left side of the screen, you can see a scrolling area you shouldn't

The screen capture should you, with the red box-rounded area, the problem.

Is this due to the scissor don't working on 2D Sprite draw commands, or is this due to the resolution change ?

Regards,

Attachments

Login to view attachments
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 5th Apr 2020 23:35
It would have to be related to your resolution change, unless you set the wrong coordinates for the scissor.
Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 6th Apr 2020 01:01
As a guide you could use DrawBox to draw your scissor area so you know exactly where it is
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 6th Apr 2020 09:17
Perhaps a workaround would help.
It seems to me that all you want to do is force the black bars at the edge of the screen so why not simply draw black sprites over the top of anything that is in that area?
Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 7th Apr 2020 10:00 Edited at: 7th Apr 2020 10:01
@Scraggle : It should be a workaround for this case, but imagine you have to define specific (different) boxes for each layer to draw ... You cannot draw black sprite outise the current layer as it should make disappear graphics from the ones previously drawn (at the same frame).
TomToad
6
Years of Service
User Offline
Joined: 6th Jan 2018
Location:
Posted: 7th Apr 2020 15:48
You might want to call Update() Render() and Swap() instead of Sync(), so try something like
...set layer 1 scissor
...show layer 1
Render()
...hide layer 1
...set layer 2 scissor
...show layer 2
Render()
--snip--
...set last layer scissor
...show last layer
Render()
Swap()
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 7th Apr 2020 16:52
I'm a little confused as to what exactly you want to achieve, or rather the issue.


That for example maintains the 4:3 Aspect ratio on a 16:9 Resolution.
But for some reason GetScreenBorders doesn't seems to actually do anything.

(keep in mind it's supposed to be Negative the Offset at Top & Left., while it'll be Resolution + Offset at Bottom & Right)
But they always return 0 for me, not sure if it's an AGK-S bug or such... but to be honest I'd not actually use this approach, because you'd have to change the Scissor Back Post Rendering the Viewport to have the Borders Usable.
It's just easier instead to use Black Borders and simply calculate Offset Ranges for the Desired Viewport.

Sure, you get some overdraw... but that's not too performance intensive, at least not compared to some other more notable limitations of AGK.

Freddix
AGK Developer
22
Years of Service
User Offline
Joined: 19th Sep 2002
Location: France
Posted: 8th Apr 2020 20:26 Edited at: 8th Apr 2020 21:30
@Raven :
Thank you, I have used your sample to understand correctly how SetScissor works ..
In fact, I've not understood everything, but using this, it works :
(it automatically use the max best zoom with aspect ratio kept from virtual resolution definition.



EDIT : With the 1st one called before all render, I can update display/window value and store them.
Then I have a special Scissor method now that can handle part of screen and that can be called at any time to define a drawing box, it works with my Layers system now
To makes this 2nd method work, the 1st one must be called before (and only once per frame ... This second one can be used several times in one frame to define portions of screen to display.



With these 2 methods we can keep aspect radio correct in concordance with the virtual resolution set. and use scissors inside the virtual resolution display.

@TomToad : Yes, now I have a scheme following your idea ...
- Update the display view keeping virtual & true window size
- Loop all layer display : SetScissor for layer ... Render layer ... next layer ...
- Restore full scrissor with the correct aspect ratio for all other drawings requested...

Thank you all. Problem solved
PluginKIT improved with all these !!!! [ And the 2 code pastes are part of PluginKIT for AppGameKit

Login to post a reply

Server time is: 2024-11-22 04:42:50
Your offset time is: 2024-11-22 04:42:50