About Monkey 2 › Forums › Monkey 2 Programming Help › Pyro 2 Questions
This topic contains 16 replies, has 3 voices, and was last updated by
therevills 1 year, 7 months ago.
-
AuthorPosts
-
August 27, 2017 at 4:05 am #10021
Hey Playniax – so I’ve finally got around to play with Pyro 2 and got a couple of questions so far
* Is delta timing needed for the scene graph object?
* Why 2 different modules for Pyro-Framework and Pyro-SceneGraph? Just trying to get my head around which on to use and where…
* How would a create a GUI layer so it doesnt move with the camera? For example I’m playing with the shadowcaster example and would like the LayerLabel not to move with the camera?[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115[crayon-5cb9b8fd2349d298857125 inline="true" ]' Import assets#Import "../assets/playniax.png"#Import "../assets/playniax_N.png"#Import "../assets/playniax_S.png"#Import "../assets/background.png"#Import "../assets/background_N.png"#Import "../assets/background_S.png"#Import "../assets/light.png"#Import "../assets/comici.ttf"#Import "<std>"#Import "<mojo>"#Import "<pyro-scenegraph>" ' Import pyro scene.Using std..Using mojo..Using pyro.framework..Using pyro.scenegraph..Global virtualResolution:=New Vec2i( 640,480 ) ' Backing global for virtual resolution.Class PyroExample Extends Window' Backing fields:Field light:LayerSpriteField logo:LayerSpriteField scene:SceneField camera:CameraField label:LayerLabelMethod New( title:String,width:Int,height:Int,flags:WindowFlags=WindowFlags.Resizable )Super.New( title,width,height,flags )Layout="letterbox"scene=New Scene( Self ) ' Create a scene.camera=New Camera( scene )' Setup camera.Local layer:=New Layer( scene ) ' Add layer.layer.AmbientLight=New Color( .1,.1,.1,1 )' Create background spritesLocal background:=New LayerSprite( layer,Content.GetBump( "asset::background.png","asset::background_N.png","asset::background_S.png" ) )background.Location=virtualResolution/2 ' Center of the screen.'logo=New LayerSprite( layer,Content.GetBump( "asset::playniax.png","asset::playniax_N.png","asset::playniax_S.png" ) ) ' Create a sprite using the Playniax logo.logo=New LayerSprite( layer,Content.GetImage( "asset::playniax.png" ) ) ' Create a sprite using the Playniax logo.logo.Location=virtualResolution/2logo.Image.ShadowCaster=New ShadowCaster( New Rectf( 1,1,logo.Width-2,logo.Height-2 ) ) ' Add a shadow caster to the sprite image.' A light is just a sprite but you need to set lighting on by changing the Type property to 2.light=New LayerSprite( layer,Content.GetLight( "asset::light.png" ) )light.Type=2 ' LayerSprite now functions as a light! ( 1=normal )light.Scale=New Vec2f( 3,3 )Local guiLayer:=New Layer(scene)' ( Note that the content manager is used to load the images but Image.Load can also be used )' Label:label=New LayerLabel()label.Layer=guiLayerlabel.Font=Font.Load( "asset::comici.ttf",48 )label.Color=New Color( 1,0,1 )label.Text="Hello world!"label.X=100label.Y=100EndMethod OnMeasure:Vec2i() OverrideReturn virtualResolutionEndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()light.Location = MouseLocation+camera.Locationlabel.Text = MouseLocation' Scrolling keys:If Keyboard.KeyDown( Key.Left ) camera.X-=5If Keyboard.KeyDown( Key.Right ) camera.X+=5If Keyboard.KeyDown( Key.Up ) camera.Y-=5If Keyboard.KeyDown( Key.Down ) camera.Y+=5scene.Update() ' Update must be called before Draw!scene.Draw( canvas ) ' Draw all scene objects to canvasLocal y:=8Local gap:=20canvas.DrawText( "Mouse location:" + label.Text, 8, y)y+=gapcanvas.DrawText( "Camera location:" + camera.Location, 8, y)y+=gapcanvas.DrawText( "light location:" + light.Location, 8, y)EndEndFunction Main()New AppInstanceNew PyroExample( "Pyro example",640,480 )App.Run()EndOr should I be doing something different?
August 27, 2017 at 6:19 am #10025Is delta timing needed for the scene graph object?
No
Why 2 different modules for Pyro-Framework and Pyro-SceneGraph?
When is started Pyro2 I attempted to have one module for both but found that having ‘specialised’ modules just worked better.
Just trying to get my head around which on to use and where…
I generally use the Scenegraph for game / sprite oriented stuff and GUI module for buttons, labels, etc as an overlay.
Not a fixed set of ‘rules’ but the examples reveal my personal preference.
How would a create a GUI layer so it doesnt move with the camera? For example I’m playing with the shadowcaster example and would like the LayerLabel not to move with the camera?
In your particular example you can add and extra layer and set the layer MultiplierX and MultiplierY to 0. The layers X and Y positions are multiplied by the camera X and Y and by the Multiplier X and Y values so you can create a parallax scrolling effects by changing the values. Setting them to 0 will cause the layers not to move when you move the camera.
Monkey123Local layer2:=New Layer( scene )layer2.MultiplierX=0layer2.MultiplierY=0August 28, 2017 at 8:31 am #10061Thanks Tony!
So much code to look thru!
From what you are suggesting I should use the gui module for the overlay instead of the layer?
With the screen manager is there a way to have transitions (eg fade between them)?
Edit: Should I be using screens or scenes? O_O
August 28, 2017 at 3:55 pm #10071Did you go thru the modules bananas? Step by step they should clear things up. I attempted to keep them as minimum as possible to expose diffrent parts of the framework…
Anyway, a screen and a scene are not the same. You can use the screen manager and screens like the monkey Window class except you can set up multiple screens and switch easily between them. From a screen OnUpdate and OnRender you can update and draw a scene.
Also have a look at the ‘t01_screens’ template in the Pyro essentials found here
For fading you can use the DrawFader( canvas,value ) command.
The jungle.monkey2 demo in the essentials zip show you how its done.
I did recently start a series of tutorials that I want to update regulary so hopefully this will help!
Here are the humble beginnings!
I added the scene graph basics today!
August 29, 2017 at 9:59 am #10098The Jungle example is perfect, this should be in your examples folder! I was having a hard time with the Screen and adding a Scene… in the example you have:
scene=New Scene( ScreenManager )
I must be rusty in MX2 as how does that even work? You are passing a class to scene not an instance of a class???
When declaring screens is the last one instantiated the first one to be shown?
I’ve added fading to the Jungle demo example, but is there an easier way with the framework?
(I couldnt paste the code here)
August 29, 2017 at 10:47 am #10103You are passing a class to scene not an instance of a class???
Just press F2 on ScreenManager and jump to declaration. You’ll see that
Monkey123Property ScreenManager:ScreenManager()Return _screenManagerEndyes! mx2 allow us naming variables the same as classes, so we can be surprised sometimes.
(this lang feature prevents me to do code jumping properly – especially in such cases)
August 29, 2017 at 6:03 pm #10107Nerobot to the resque!
The scene must know its Window or in this case the ScreenManager ( the ScreenManager is an extension of the monkey2 Window class ).
The Jungle example is perfect, this should be in your examples folder!
At the time the module manager zip file limit was only 2 mb? I was forced to split it up a bit. I think mark changed it to 5? I should have a look at that. Maybe a lot of people missed the cool stuff.
When declaring screens is the last one instantiated the first one to be shown?
Yes, but you can control it with the Set command.
Monkey1game.Set()I’ve added fading to the Jungle demo example, but is there an easier way with the framework?
Not at this time really
Thing is, with Igntition and Pyro I learned that to much predetermined stuff keeps devs boxed in ( doing things my way ) that I tried to keep things as open and flexible as possible.
I might write a transitions lib that deals with this automatically like Ignition has but a bit more open.
August 30, 2017 at 9:15 am #10114Thanks Nerobot… I didnt think to pressed F2, I just thought it was the class! D’oh! That does make reading code a bit harder!
Thanks again Tony for the info.
A transition lib would be great, adding fading betweening screens makes games look so much more professional.
I might have missed but is Pyro2 source opensource on GitHub or similar?
August 30, 2017 at 4:31 pm #10120I might have missed but is Pyro2 source opensource on GitHub or similar?
Pyro is opensource but not on GitHub ( yet )
No experience with GitHub sharing / merging etc. Still on my todo list to have a go.
September 4, 2017 at 9:23 am #10263Possible bug, run the b05_shadowcaster demo and then maximise the window. The position of the light sprite is drawn incorrectly.
September 4, 2017 at 8:12 pm #10273Thanks! It looks like a bug in the banana, not Pyro. The banana uses a virtual resolution but the ‘real’ mouse values. I will update the banana asap!
September 5, 2017 at 8:42 am #10279Ah… I’m trying to do something similar whats the fix?
Also what you suggest on getting Canvas details in the OnUpdate method, for example canvas.Viewport.Width?
And currently we cant pass in a texture flag to GetBump in the content manager, I’ve added to my version of pyro-framework:
[/crayon]Monkey12345[crayon-5cb9b8fd40983513741533 inline="true" ] Method GetBump:Image( diffuse:String,normal:String,specular:String,specularScale:Float=1,flipNormalY:Bool=True,shader:Shader=Null,textureFlags:TextureFlags=TextureFlags.FilterMipmap)...obj._bump=Image.LoadBump( SmartPath( diffuse ),SmartPath( normal ),SmartPath( specular ),specularScale,flipNormalY,shader,textureFlags )...Hmmm looks like all the Content resources you cant set a texture flag unless I’ve missed something…
I’ve also added a OnPostRender method in screenmanager’s Screen class:
[/crayon]Monkey12[crayon-5cb9b8fd40989640912069 inline="true" ] Method OnPostRender( canvas:Canvas ) VirtualEndWhich is called by ScreenManager OnRender method:
[/crayon]Monkey12345[crayon-5cb9b8fd4098e167427706 inline="true" ] Elseif ( _currentScreen._runOnce=False And _currentScreen._started=True )_currentScreen.OnRender( canvas )_currentScreen.OnPostRender( canvas ) ' NEW!EndifThis allows me to add extra stuff such as a fader etc.
Is there a better place to discuse these changes or are you happy with this thread?
September 5, 2017 at 9:59 am #10281whats the fix
Will post that later
currently we cant pass in a texture flag to GetBump in the content manager
I see. Or I missed it or Mark added it recently not sure. Anyway, will try to add that.
Is there a better place to discuse these changes or are you happy with this thread?
Maybe some kind of more direct communication is needed because I am interested in what the ‘Diddy guy’ thinks that should be added. I use Slack, Skype or do you have a suggestion except for github.
September 5, 2017 at 6:28 pm #10284There are basically 2 correct ways to get the mouse coords when a virtual resolution is used or the camera zooms in/out/rotates.
Monkey1mouse:=camera.GetMouseLocation( layer )or
Monkey12mouse:=layer.GetMouseLocation( camera )what you suggest on getting Canvas details in the OnUpdate method
For now, the canvas size is always the same as the window size ( or view ). You can also call camera.View.Width or camera.View.Height
I will change this in the future because I want to be able to render the scene to an image larger or smaller as the default canvas and at the time I coudn’t decide the best approach on passing the width and height to the update part. But I think for now your safe to get the window or camera sizes…
September 9, 2017 at 2:12 am #10357Hmmm tried both:
[/crayon]Monkey12[crayon-5cb9b8fd51c8f439923693 inline="true" ]mouse := camera.GetMouseLocation( layer )mouse := layer.GetMouseLocation( camera )Doesnt fix the issue…
-
AuthorPosts
You must be logged in to reply to this topic.