Reply
11 Jun 2012
Member
Playstation Staff

Mixing GameEngine2D with 3D elements

7 Replies 893 Views Created 11-06-2012

Hi guys

I'm building a game using the GameEngine2D and is working great

but now I want to add a 3D element on top of it, 

how can I do that?

is just 3D elements on top, like in another layer totally separate.

 

thanks for the help.

Please use plain text.
Reply
0 Kudos
Message 1 of 8 (893 Views)
Reply
0 Kudos
Level 6
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

HI varo_mix,

Thank you for your question. Yes, you can mix GameEngine2D with your 3D modelling. The GameEngine2D library does it's rendering onto the GraphicsContext, so you will just need to ensure that you control the rendering order between your 3D elements and the GE2D. When specifying which Scene to run with, it would be best if you use a manual loop (set boolean to true in RunWithScene) and then add your Director.Instance.Update() and Director.Instance.Render() respectively.

If you would like any further help, please do not hesitate to ask and we can post a sample.

Thanks,
James
PlayStation®Mobile Dev Team
Please use plain text.
Reply
0 Kudos
Message 2 of 8 (865 Views)
Reply
0 Kudos
Level 2
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

Thanks James

 

it would be very helpful to have an example of that

cause I'm having another issue with updates and that might help with that too.

 

thanks again

Please use plain text.
Reply
0 Kudos
Message 3 of 8 (856 Views)
Reply
0 Kudos
Level 6
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

Not a problem :smileywink:

 

I'll use BasicModelSample as a basis to overlay a GE2D SpriteUV on top of the 3D model (like a HUD). 

 

1. You'll first want to delcare another static variable for the BasicModelSample class, as follows:

public static Scene scene;

 

2. We can then initialize the Director, instantiate the Scene and then setup the SpriteUV in the Init() method.

Director.Initialize(300, 300, graphics);
			
scene= new Scene();
scene.Camera.SetViewFromViewport();
			
Texture2D text = new Texture2D("/Application/shoot.jpg", false);
TextureInfo info = new TextureInfo(text);
			
SpriteUV sprite = new SpriteUV();
sprite.TextureInfo = info;
sprite.Scale = info.TextureSizef;
sprite.Position = new Vector2(200, 200);
scene.AddChild(sprite);
			
Director.Instance.RunWithScene(scene, true);

By calling RunWithScene() and passing in true for the manual loop, this tells the GameEngine2D library that we'll be handling the calling of the update and render methods that it requires. 

 

3. We now need to call the Update() method on the Director. At the start of the Draw() method in BasicModelSample, add the following line. 

Director.Instance.Update();

 

4. Get the Director to Render().You'll want to place this after the call to graphics.Clear() and before graphics.SwapBuffers()

Director.Instance.Render();

 

5.Post swap, should be called after the call to graphics.SwapBuffers()

Director.Instance.PostSwap();

 

Hope this helps,

James

PlayStation®Mobile Dev Team
Please use plain text.
Reply
0 Kudos
Message 4 of 8 (854 Views)
Reply
0 Kudos
Level 2
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

well, I can run it but I can't see any difference in the result :smileyhappy:

 

can you switch it?, cause I already have all this stuff build using GE2D and I want to add the 3D elements to that

I kinda get what's happening but I don't want to destroy what I already have hehe

 

thanks

Please use plain text.
Reply
0 Kudos
Message 5 of 8 (847 Views)
Reply
0 Kudos
Level 2
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

ok I managed to get this working, GE2D and 3D model are on the scene yay!!
now the issue is, the model is BEHIND my GE2D elements,
how can I put the 3D in front and the GE2D behind?

draw order?

thanks for the help
Please use plain text.
Reply
0 Kudos
Message 6 of 8 (823 Views)
Reply
0 Kudos
Level 6
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

Great! You will need to make sure that your model draw calls happen after you have rendered the GameEngine2D elements, so for example in the BasicModelSample, you could move you call to Director.Instance.Reder() to directly after the graphics.Clear() call, and this should do the trick.

Hope this helps.
PlayStation®Mobile Dev Team
Please use plain text.
Reply
0 Kudos
Message 7 of 8 (818 Views)
Reply
0 Kudos
Level 2
 
Playstation Staff

Re: Mixing GameEngine2D with 3D elements

Hey JAmes

 

yeah it works is on top now, but I can't se the game now, the 3D model comes with the gl clear color, so it's covering the whole thing, how can I just declare like and alpha channel or something.

 

so what I'm saying is the 3d layer of this mix, has a barkground right, that you declare with the 

 

graphics.SetClearColor(0.0f, 0.0f, 0.0f, 0.5f);

 

and that is what is covering the whole screen and the GE2D layer of the mix is behind that

 

I'm thinking, set the model as it's alpha to blend it or something, set the clear color to nothing, but that's silly :smileyhappy:

 

thanks for the help man you rock!!

Please use plain text.
Reply
0 Kudos
Message 8 of 8 (812 Views)
Reply
0 Kudos