I need suggestions for a functionality
by Joao Brandao · in Torque Developer Network · 10/04/2011 (10:30 am) · 2 replies
I'm trying to create my first game, and one of the things I need to make happen in the game is spawn objects on 2 horizontal lines going from right to left. There are 5 different objects that need to be spawned randomly. Imagine I have a banana, an apple, an orange, etc. I need to make them spawn in a random order off screen and move all the way to the left of the screen.
My question is, what is the best way to achieve this? should I create a spawn function that randomly picks one of the objects every X miliseconds? (I do need them to be spawned one after the other, like a train, and I tried choosing a spawn of 1000 miliseconds, and sometimes, they would appear a couple of pixels off, so it didn't look too good.
Or is there some other way I'm not considering?
My question is, what is the best way to achieve this? should I create a spawn function that randomly picks one of the objects every X miliseconds? (I do need them to be spawned one after the other, like a train, and I tried choosing a spawn of 1000 miliseconds, and sometimes, they would appear a couple of pixels off, so it didn't look too good.
Or is there some other way I'm not considering?
About the author
I'm a little old to start programming, as I'm 32, but being unemployed pushed me into learning new skills and go back to the area I graduated in (New Technologies). I am my own worst enemy, as I procrastinate a lot, and I'm very lazy. Also, I love games.
Recent Threads
#2
I also have a question about spawning in general. I have created a certain function that works on objects with a certain name (example: function objectname::onMouseUp {};)
How can I, when spawning an object, give it that name, so that the function also works with it?
10/05/2011 (1:18 pm)
thanks for the tips Robert!I also have a question about spawning in general. I have created a certain function that works on objects with a certain name (example: function objectname::onMouseUp {};)
How can I, when spawning an object, give it that name, so that the function also works with it?
Torque Owner Robert Fritzen
Phantom Games Development
I'd go with a three function approach, and they are as follows:
1. Spawn an object given parameters (type, initial position)
2. Apply movement to object given the parameters (objectID, newPosition)
3. Function to randomize speed, object spawned, ect.
Random numbers are pretty easy to accomplish in torque:
%num = getRandom(min, max);
I'm pretty sure element moving is the same as in the 3d engine
%object.setPosition(x, y);
That's what I'd do. Maybe someone who works alot with the @d engines can also offer input here.