2 registered members (Quad, aliswee),
835
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Time to quit 3DGS
[Re: preacherX]
#469515
11/19/17 09:37
11/19/17 09:37
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
@preacherX: [...] For example, I just spoke with someone who is studying Game Design with Unity and asked him how I can create a sprite in Unity with code:
The code would be something like this:
Vector3 rndPos = new Vector3(10.0f,10.0f,10.0f); GameObject Go = new GameObject(); Go.transform.position = rndPos; Go.transform.localScale *= 10.0f; Go.transform.rotation = Quaternion.Euler(0, 0, 10.0f); SpriteRenderer renderer = Go.AddComponent<SpriteRenderer>(); Sprite tmp = Resources.Load<Sprite>("Stein"); renderer.sprite = tmp;
In lite_C I would just use this:
ENTITY* Go=ent_create("Stein.png",vector(1,1,1),StoneBehaviour); Go.roll=10;vec_fill(Go.scale_x,1);
Or does someone know if there is an easier way to do this in Unity? I Mostly agree with Sid. Plus, the difference between those two code examples is that the lite-c code has the position cramped into the .._create-line. Other than that, Acknex just hides a lot while (- from what I can see in the code snippet -) Unity offers you more possibilities here. The resource loading is most likely a lot better than Acknex's, too. Ignoring all that, you could simply write a function for either engine and use it as a one-liner to create sprites. Yes, the additional freedom in Unity/Unreal also requires you to write a few more lines at the lower level, but once you have that intermediate layer of code working, this difference is not really a problem anymore. Honestly, I'd prefer it that way in acknex, too, because I regularly run into problems that the engine is making difficult or impossible to solve by obfuscating and hiding things in engine functions to "make things easier". Now, I don't wanna turn this into an "acknex is crap"-rant but I don't fully agree with your point. (also, I don't wanna be nit-picky but there are pointer errors in your code that only work due to lite-c's automatic (de)referencing. I'd recommend anyone who uses Acknex to turn that off)
POTATO-MAN saves the day! - Random
|
|
|
Re: Time to quit 3DGS
[Re: preacherX]
#469529
11/20/17 02:53
11/20/17 02:53
|
Joined: Dec 2002
Posts: 3,363 Vindobona (Ostarichi)
Harry Potter
Expert
|
Expert
Joined: Dec 2002
Posts: 3,363
Vindobona (Ostarichi)
|
Or does someone know if there is an easier way to do this in Unity? Hi, It is not as difficult as it looks like. But you have to know that you need two different objects. First you need a sprite object. This can simply be created with Sprite.Create
mySprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
But this is only a sprite object in memory. If you want to render this sprite, you also need a gameObject for it (or many gameObjects if you want to render that sprite many times in the scene). This gameObject is similar to an 'entity' in 3DGS. GameObjects can manually be created in the level editor, or at runtime via the following coding:
GameObject GOname = new GameObject();
A gameObject is only something like a container for all kinds of entities. It can be a sound, or a mesh, or many other things. GameObjects can have one or more Components who defines which functionalities this object has. Such Components can be 'MeshRenderer' or 'AudioSource' or 'VideoPlayer' or physics effects, or hundreds of other things. And you also can develop your own Components (classes). And one of these Components is the 'SpriteRenderer'. It is used to render sprites in a scene. So if you have created a gameObject for the sprite at runtime, you also need to add a Component for rendering sprites. And this is done by:
private SpriteRenderer sr;
sr = gameObject.AddComponent<SpriteRenderer>() as SpriteRenderer;
And then you only need to assign your sprite to that SpriteRenderer Component (set parameter 'sprite'). This is done by: That's all. Okay, then you also can use e.g. transform.position to position your sprite, or transform.rotation, or something like that. Because each gameObject automatically has a 'transform' Component which can be used to position, rotate or scale a gameObject. Here is a typical example for a class, developed for Unity. It has one parameter for the texture (public Texture2D tex;). It creates an empty sprite renderer, with a light grey non transparent background color. And it creates a button with text 'Add sprite' on the screen. When you press that button, it is assigning the texture to the sprite.
// Create a Sprite at start-up.
// Assign a texture to the sprite when the button is pressed.
using UnityEngine;
public class spriteCreate : MonoBehaviour
{
public Texture2D tex;
private Sprite mySprite;
private SpriteRenderer sr;
void Awake()
{
sr = gameObject.AddComponent<SpriteRenderer>() as SpriteRenderer;
sr.color = new Color(0.9f, 0.9f, 0.9f, 1.0f);
transform.position = new Vector3(1.5f, 1.5f, 0.0f);
}
void Start()
{
mySprite = Sprite.Create(tex, new Rect(0.0f, 0.0f, tex.width, tex.height), new Vector2(0.5f, 0.5f), 100.0f);
}
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 100, 30), "Add sprite"))
{
sr.sprite = mySprite;
}
}
}
Here the documentation: https://docs.unity3d.com/ScriptReference/Sprite.Create.htmlGreetings, Harry
|
|
|
Re: Time to quit 3DGS
[Re: Harry Potter]
#469543
11/20/17 11:14
11/20/17 11:14
|
Joined: Sep 2005
Posts: 352 Germany
preacherX
Senior Member
|
Senior Member
Joined: Sep 2005
Posts: 352
Germany
|
After some hard hours of Unity learning and a skype session with a Unity insider I think I got it! These are my first steps with Unity: https://www.youtube.com/watch?v=NeY7oAZp2Ro&feature=youtu.beNot much yet to see, but I'm very happy that I understand it and now I'm coming closer to my goal bringing RPG PARTY to the Nintendo Switch!^^ I have to admit, Unity have some cool features (for example nice particle editor). However, for a beginner I think scripting with lite-C is easier to understand. I think if I had started with Unity many years ago without any programming experience I would had been lost!
|
|
|
Re: Time to quit 3DGS
[Re: preacherX]
#469557
11/21/17 13:12
11/21/17 13:12
|
Joined: Apr 2007
Posts: 3,751 Canada
WretchedSid
Expert
|
Expert
Joined: Apr 2007
Posts: 3,751
Canada
|
Just for shits and giggles, this is the terse version of the Unity sprite code (I kicked the weird scale because the Lite-C version sets the scale to 1 which is the default for Unity anyhow (same of GS, so I don't really understand what it's there fore to begin with).
GameObject Go = new GameObject();
Go.transform.position = new Vector3(1.0f,1.0f,1.0f);
Go.transform.rotation = Quaternion.Euler(0, 0, 10.0f);
Go.AddComponent<SpriteRenderer>().sprite = Resources.Load<Sprite>("Stein");
No idea what I'm trying to say with this. Ya'all need to learn how to move on in life. OOP is great, and once you grok it you won't be able to go back to Lite-C.
Shitlord by trade and passion. Graphics programmer at Laminar Research. I write blog posts at feresignum.com
|
|
|
Re: Time to quit 3DGS
[Re: WretchedSid]
#469560
11/21/17 13:34
11/21/17 13:34
|
Joined: Sep 2005
Posts: 352 Germany
preacherX
Senior Member
|
Senior Member
Joined: Sep 2005
Posts: 352
Germany
|
This looks really clear! After all, it is not so hard as I thought and you're right, sometimes you have to move on! ^^ Something strange I learned in Unity and can tell all beginners working with Unity: In lite_C you could do this: "Go.x = 10;" In Unity you can only read the single vectors like " if(Go.transform.position.x > 10)" but you cannot write the single vector like "Go.transform.position.x = 10.0f;" ! You would have to use something like this: "Go.transform.position = new Vector3(10.0f,Go.transform.position.y,Go.transform.position.z)" Some more letters to write but if I can go to the Nintendo Switch in exchange it is okay for me!
|
|
|
Re: Time to quit 3DGS
[Re: preacherX]
#469582
11/23/17 08:10
11/23/17 08:10
|
Joined: Aug 2003
Posts: 118 Deutschland
Ezzett
Member
|
Member
Joined: Aug 2003
Posts: 118
Deutschland
|
In Unity you can only read the single vectors like " if(Go.transform.position.x > 10)" but you cannot write the single vector like "Go.transform.position.x = 10.0f;" !
You would have to use something like this: "Go.transform.position = new Vector3(10.0f,Go.transform.position.y,Go.transform.position.z)"
Yes, because Go.transform.position.x is just a float attribute and not a vector. So you need to call the constructor to create a complete Vector3 instance. The game object in Unity obviously uses a component pattern to decouple code. This adds a lot of flexibility but makes the code more complex which makes it harder to understand for beginners. But the larger your projects gets the more you will benefit from such patterns because if your requirements change late in development you will spend a lot less time to modify your code.
|
|
|
Re: Time to quit 3DGS
[Re: Ezzett]
#469584
11/23/17 09:02
11/23/17 09:02
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
okay, I think I have accidentally found the perfect game engine for 3DGS refugees: Xenko https://xenko.com . Free for individuals, uses C#, its editor is called as Game Studio and objects are called as entities , and you can use 3DGS entity action styled updates (see Asynchronous scripts) : http://doc.xenko.com/latest/en/manual/scripts/types-of-script.html(it is WIP, a lot of features are missing, so imo not a real option currently)
|
|
|
Re: Time to quit 3DGS
[Re: sivan]
#469586
11/23/17 11:20
11/23/17 11:20
|
Joined: Jun 2009
Posts: 2,210 Bavaria, Germany
Kartoffel
Expert
|
Expert
Joined: Jun 2009
Posts: 2,210
Bavaria, Germany
|
@sivan: sounds kinda promising, although I wouldn't expect too much from it... also, personally I'd prefer C++ over C# ;(
POTATO-MAN saves the day! - Random
|
|
|
Re: Time to quit 3DGS
[Re: Reconnoiter]
#469590
11/23/17 14:14
11/23/17 14:14
|
Joined: Mar 2011
Posts: 3,150 Budapest
sivan
Expert
|
Expert
Joined: Mar 2011
Posts: 3,150
Budapest
|
tbh I would not use it, I just wanted to share it because of the funny correlations. I also prefer C++ (and UE4!), but Unity is also a good choice. btw its code snippets look simple, so might be easier for beginners similarly to 3dgs/lite-c...
if choose Unity or UE4, you can get many-many tutorials, source codes, assets, information, and partners, which can be more important when you jump seriously in game development.
|
|
|
|