Getting started with Defold

Yes, has to be in update. By the way, it’s meant for debugging only not as regular text for your game.

A factory is a component in the same way as a script, sprite, sound or particle fx, meaning that you need to add it to a game object. Right click the go in the Outline and select Add Component and chose Factory. Now you should see a Factory in the outline. Select it and pick the prototype go it should spawn.

I am doing that (or think I am) and here’s what I see…

I suspect it’s a code organization thing - something earlier I’ve done wrong that doesn’t allow the reference to any of my game objects to populate the prototype choice dialog.

Yep I saw that before - best for debugging, so I had focused on the GUI component which I had working before my original post. For sake of argument though, still would like to know how this (or any other functions) work as specific and stripped down as I can. So will play with this some more.

Actually right now about to play with Text GUI objects some more to recreate some things like spoken text from a character, etc. It does seem… like Defold thinks of text more as a GUI object than as an in-game object/canvas. But for those of us who think about having things like spoken character text, etc. we tend to think of things as on-screen text not necessarily a menu or score caption metaphor.

I realize it may not matter in terms of actual functionality but having seen some earlier posts about doing things like attaching text to a game object (so they move together easily) I suspect this disconnect between text for menus, scores, etc. vs. text for more narrative or other gameplay features creates the disconnect.

I can tell you long term you will want to be changing your render script, and maybe making another GUI layer / material that renders closer to how game objects work, and then use this layer for character speech bubble text / gameplay text like damage counters as it will make positioning easier for you. You’ll figure it out. Everything you are talking about is possible and in reasonable ways.

You can only select game object prototypes from game objects which exists on disk (ie New->Game Object file), not the ones you have created in-line in a collection (ie right-clicking in collection and Add Game Object).

I thought this was documented in the Manuals, but I can’t even find a section on factories. @sicher, where have we documented factories?

Thanks! Makes sense. Right now I’m just working with the objects and how to get them to do some things I want. Moving from there to layers for this would be smart. It seems what I would do is just pass some sort of function variable from the code to the GUI layer scripts that then is used to set up on that “speech” layer what I want to render. But that’s a ways a way, still working on a lot of BASICS. :wink:

That was a problem for me as well… there’s lots about factories but it’s spread across other tutorials and so it doesn’t necessarily bring focus… Thanks for the help - will try to get it to work.

So I tried what you said and still not getting anything to populate in the prototype field. I’m going to start a new project and try to see if that helps.

You have a Game Object made outside of the collection? Try to delete the ** too.

This example has a working factory : Big List of Defold Pro Tips!

What if you start typing the name of the game object as it is shown in the Project Explorer? Could you post another screenshot?

So I loaded up @Pkeod project he linked to. That took a bit as I had to figure out how to access local saves, and re-commit using the synchronize. I tried using SourceTree to help but it’s fighting me on my password token (will save that for a different post). So I used the local source control.

I got his Factory example to load and build/run.

I see how Factories must reference a .GO not stored in a collection. That sort of makes sense as these are, I guess, parent objects.

However, I deleted the factory reference in his prototype field which was /main/ghost.go and then opened the … dialog to select it again. No dice. Empty. Remove . Nothing. Typed ghost, nothing, typed ghost.go nothing, Typed /main/ghost.go nothing (OK is still ghosted).

If I go to the field (not the dialog) in the properties and type /main/ghost.go it works. I also typed in other files, and other elements like ghost.go without /main here just to see what would happen and it didn’t work (expected).

So for me it seems if I type the exact resource file location it will populate and work, but if I use the search and select dialog it does not.

I could post screenshots but they’re redundant.

I think I figured it out - I had changed my working sets in that dialog - probably trying to figure out something else before in terms of referencing and attaching items to game objects. Not sure yet - but is this part of the file dialog well explained in the documentation? I changed it back to Window Working Sets and things got better… - still learning this all… :slight_smile:

Oh, I’ve never even noticed the Working Set drop down and I’m 100% sure I have never modified it. I don’t think you’re supposed to fiddle with the working sets :slight_smile:

One thing I just noticed, and it’s the type of rookie mistake I’m making plenty of… For this page: http://www.defold.com/manuals/2dgraphics/ it might be good to add a note that says “SAVE YOUR ATLAS” first before adding images to a sprite as they won’t populate the dropdown list in the sprite properties box until you save the atlas changes. I know this is easily overcome, but small things like that in the documentation add a level of detail and support that can help n00bs like me.

I’ve already broken the first rule of Defold Club.

So I’ve got this all working. Not too difficult but now something more problematic - what is the easiest way to detect a touch on a specific sprite be it with the mouse or touch.? Is there no easy way to deal with determining an mouseover/touch event to any given sprint via the on-input? I see in other tutorials like the Magic Link tutorial, they’re just doing a quick grid calculation but that wouldn’t work for things no on a grid structure.

Good point. You’re not the first to forget to save first. @sicher, do we mention this anywhere in the manual? (I know it will not matter in the new editor, but until then it might be worth mentioning)

There is no out of the box detection of input on a sprite in the same way as there is gui.pick_node(). You can read the size of a sprite and bake the whole thing into a helper function of some kind, but it’s hard to make anything generic since you can modify the render script and set a totally different view, projection and other things you’d need to take into account. If you have a collision object on the sprite you could probably also do something with a collision object that you spawn/move to the position of the mouse and then check for a collision with your sprites.

Ok, that’s what I thought. For now I was just picking a target box within the general bounding box of the sprite and that may be good enough in terms of what I want to do. I had thought of using a collision object, but that might not work well for grabbing and moving an object on the screen. While it would help in some respects for irregular shaped objects, it seems like a lot of work for not much gain. What it might be useful for though is avoiding objects that when placed down are otherwise overlapping. I think what I’m building toward is a generic function that makes it possible to test for different things like this when moving around objects on the screen for drag and drop interactions. Food for thought… Thx.

1 Like