greetings. im using Defold as tool for a college asignment. the game consist of a running simulation in which the player picks up trash.
im new on this engine so i get a little bit lost with the tutorials. i’ve already made the main animation and scrolling escene.
but i have some problems with the “pickable” object. what i was thinking was to give a factory element to it that would take reference from a “pickables” atlas. then it would generate the pickable in the last floortile ofthe escene. they already have the scrolling script so the idea is that the pickable will follow the scrolling movement until colliding with the player.
can that be done? im trying to follow the tutorials to see how can i implement it but the first one uses a single sprite object. the block factory tutorial got me insight in how to generate them. but i need the object to respond to collisions with the main character. not a block based system.
im a bit lost on that.
i also saw someone mention sprite tinting. does anyone know of a tutorial or has a small guide in how to do it for this engine? i’m new to the concept tbh. but’ive already have a white sprite and want to know how to change its color based on input.
A good way of changing the visuals of a factory created game object with a sprite component is to post a play_animation message to the sprite and specify which image from the atlas to show.
And if you expose a property on the “pickable” game object that you are creating you can pass in the image when the factory is creating the image and immediately change the sprite component. Example:
pickable.script:
go.property("sprite_id", hash(""))
function init(self)
msg.post("#sprite", "play_animation", {id = self.sprite_id })
end
thanks for the reply, i’ve taken the code and had looked at it. im not versed in lua so it takes a little bit of time to understand what’s happening.
i dont quite get the “pass image when factory is creating and then change the sprite component”…
i mean.
my pickable object is a separated GO. right, i have put the script on it
the factory object is put into one of the tiles on the ground collection. so its generated on that specific tile and it moves with the scrolling algorithm (or that’s what should happen i think)…
the factory is linked to pickable.go as its prototype.
however, when i run play, the pickable doesnt appear on screen. i dont get any errors either. it just runs the app like it was before.
i dont really know what im doing wrong tbh. tried to add the sprite from the atlas. and set the ID of the script to “cristal bottle”, the only image i have for testing.
but nothing happens.
EDIT:
checked if i had put the factory script. i didnt, but now im actually getting an error log. i added it to one of the floor objects in the collection. the one with the factory element.
now im trying to figure out what happened…but im still lost on this…
Is your pickable.go spawned? Put a print(“foobar”) in the init() function of the script you attached to the pickable.go. If you get any prints when you do factory.create() then you know that the pickable go’s are spawning.
If the pickable.go is spawned then maybe it’s a Z-order issue? The pickable.go might be rendered below the tile?
You mentioned that after you fixed the factory script you got an error? What kind of error are you getting?
i got some errors regarding the implementation of the factory script. some functions were missing, but the app is running fine now
however, i tried the print and it seems the pickable.go is not spawning…
actually, it seems the create_pickable function in the factory script isnt working either …
Ok, and the create_pickable() function is called from where and when? Follow the call stack backwards and print() at every step to figure out where it goes wrong.
nevermind, i decided to just make a GO for each of the supposed objects i will be adding in the game.
each one has its own sprite and a pickable script that responds to collision as a trigger, disabling the sprite when colliding with the character.
now. it seems there’s a collection factory in the engine. so i would like to know if its possible to do the trigger algorithm on the collection factory script
EDIT:
i tried using this
local props= {“cristal bottle”}
function init(self)
local self.objects_ids = collectionfactory.create(“objectfactory”,pos,rot, props, scale)
end
but it seems to launch an error. and i cant figure what is the issue…
function create_pickable(self,params)
pos=go.get_position()
rot=go.get_rotation()
scl=go.get_scale()
for i=1,params.pickables do
local pickable
factory.create("pickable_factory", pos,rot, { sprite_id = hash("cristal bottle") }, scl)
msg.post(pickable, "set_parent", { parent_id = go.get_id() })
msg.post(pickable, "start_animation", { delay = i/10 })
table.insert(self.pickables, pickable)
end
end
pos, rot and scl has no local keyword in front of them, thus making them global. You should try to avoid globals unless you’re absolutely sure what it is you are doing.
pickable never gets assigned. I assume you meant to do:
yeah it must have been a syntax problem. i just deleted the code for the time being.
the issue im having right now is regarding the GUI. i tried to make a test. but i dont know if im missing a component. i have a box, the logo as texture and its assigned. the gui element is added to a GO in a Collection, which is called in the main collection.
Windows just puts the “X application stopped working”…
im looking to the GUI elements to see what’s the issue. the gui uses the default layer. actually, the GUI doesnt even appear in the main collection. its invisible. so i cant say if its due to position or scale of the GO that houses the GUI
the engine as it is doesnt find any issue when building, but somehow the simulation crashes. that’s all i can say.
the GUI doesnt have any script either, i dont know if that can be the case…
If you wish you can invite me to the project (bjorn.ritzl@king.com). Don’t forget to synchronize your changes! I need to get to bed now but I can take a look tomorrow.