How could do this?

For questions about using Classic.

Post » Sun Jan 17, 2010 7:44 pm

Hi guys!

Could you tell me how I can make a sprite spawn sprites by itself, I mean, automatically?

What I have done is making a event which spawns every 5000 milliseconds a sprite, but when I run the layout just spawns one object only and then nothing happens.

I hope you can help me guys!

Greetings
B
1
G
2
Posts: 6
Reputation: 637

Post » Sun Jan 17, 2010 8:37 pm

Post your .cap so someone can take a look at what's going wrong.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Mon Jan 18, 2010 5:08 am

how are you setting the x and the y because if you are not setting them to something then you will get a bunch spawned on the same spot.
B
5
S
2
G
4
Posts: 632
Reputation: 2,829

Post » Wed Jan 27, 2010 10:30 pm

Use the "every X milliseconds" condition... then I believe for the action, you click on System (the computer icon) and click on "Create Object", and choose the thing which shoots as the object.

Then from Create Object, do something like this for the X/Y:

(Name of sprite which shoots the thing).X
(Name of sprite which shoots the thing).Y

There might be some more math involved such as subtracting/adding numbers to the X/Y values to change the position a little.

You will probably also need some form of bullet-like behavior for the things which shoot.

And I'm probably sounding more complicated than I mean to.
B
7
S
2
G
3
Posts: 110
Reputation: 1,926

Post » Fri Jan 29, 2010 6:17 pm

"How could do this?"

Tee-hee! :lol:

Anywho, I wouldn't touch the "every X milliseconds" condition with a ten foot long clown pole.
Give the object an alterable value, call it "shoot" (what else?) then...

Always:
Object: Add random(3)+(2) to object.value('shoot')

Object.value('shoot') is equal to or greater than 100:
System: create object- bullet at object.x and object.y.
Object : set value "shoot" to 0

Modify the numbers here depending on how often you wish that object to shoot.
And this is all assuming you want an object to shoot something and that you know what to do from here (bullet movement or behavior).
B
2
G
3
Posts: 25
Reputation: 900

Post » Fri Jan 29, 2010 7:08 pm

lol theres nothin wrong with every x ms
B
11
S
3
G
4
Posts: 622
Reputation: 3,186

Post » Fri Jan 29, 2010 8:24 pm

[quote="Oko":2kyvlyg8]Anywho, I wouldn't touch the "every X milliseconds" condition with a ten foot long clown pole.[/quote:2kyvlyg8]

WHAT? :shock:


THEN YOU ARE [size=150:2kyvlyg8]DOING [/size:2kyvlyg8] [size=175:2kyvlyg8]IT [/size:2kyvlyg8] [size=200:2kyvlyg8][color=#FF0000:2kyvlyg8]WRONG[/color:2kyvlyg8][/size:2kyvlyg8]


Allow me to inform you of a little thing called framerate independence, forum member Oko. If you use Always, then what happens if you run the game on a very slow or very fast computer? The game will run slower or faster, that's what. People on slow machines will have an easier game, and people on fast machines will have a much harder game, because stuff is spawning at like, twice the speed or more.

When you use Every X Milliseconds, you GUARANTEE that it will spawn at the same rate on all computers. REMEMBER THIS WELL. SEAR IT INTO YOUR BRAIN WITH A HOT IRON. YOU HAD BETTER START USING EVERY X MILLISECONDS OR I WILL HUNT YOU DOWN AND CRUSH YOU. :evil:

Look up more info about this on the wiki.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Jan 29, 2010 8:40 pm

Just to clarify, you use Always when you need to perform an action every tick. This is for behind-the-scenes game logic, for the most part. Ticks happen at different rates on different computers. You don't want any sort of time-sensitive actions happening every tick.

Any time that time is a variable in your actions, whether it's spawning enemies over time, moving objects (because speed is a calculation of distance and time), or simply counting seconds, you need to use Every X Milliseconds or TimeDelta to ensure that the rate stays constant across all systems.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Jan 29, 2010 9:34 pm

To corroborate what Deadeye so eloquently stated, you can try your code using fixed framerate and trying different numbers there. 15, 30, 50, 60, whatever. See if the game is consistent (yes, establishing a minimum value before the game breaks is fair enough).


if it's not consisten't.... [color=#FF0000:2olh37na][size=200:2olh37na]it's wrong[/size:2olh37na][/color:2olh37na].
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Fri Jan 29, 2010 11:07 pm

Oops! :oops:

I.. err... the...
Haha, I'm so stupid :lol:

1 question : are simple events like: "if object value is equal to X" as bad as always?
I certainly hope not, as I would have to sift through the 170 events of my no-where-near-finished game engine!
B
2
G
3
Posts: 25
Reputation: 900

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests