How could do this?

This forum is currently in read-only mode.
  • 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

  • Post your .cap so someone can take a look at what's going wrong.

  • 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.

  • 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.

  • "How could do this?"

    Tee-hee!

    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).

  • lol theres nothin wrong with every x ms

  • Anywho, I wouldn't touch the "every X milliseconds" condition with a ten foot long clown pole.

    WHAT?

    THEN YOU ARE

    DOING

    IT

    WRONG

    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.

    Look up more info about this on the wiki.

  • 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.

  • 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....

    it's wrong

    .

  • Oops!

    I.. err... the...

    Haha, I'm so stupid

    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!

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1 question : are simple events like: "if object value is equal to X" as bad as always?

    I certainly hope not

    Like I said, you only have to consider time when you are performing time-sensitive things.

    If you need to Always check a value, that's fine. If you need to Always update the scrolling to follow a player, that's cool. If you need to Always point at the the mouse, that's cool too.

    There's plenty of situations where using Always is a good idea, but if you are dealing with time then it's not a good idea.

    If you want to make a timer using Always, then you can do it like so:

    + Always
       -> Subtract 60*TimeDelta from TimerVariable
    [/code:34sys8sk]
    
    If your target FPS is 60 then this will subtract 1 every second from your TimerVariable.  TimeDelta is providing a method to measure time in this case.
    
    Or you could do like so:
    
    [code:34sys8sk]
    + Every 1000 MS
        -> Subtract 1 from TimerVariable
    [/code:34sys8sk]
    
    And it does pretty much the same thing, only in whole numbers instead of floats.
  • Yep, I have plenty of time-based events that have just 1 condition such as : "If object value is equal to X"... and that seems to be as bad as "always"

    Oh well, I got some work to do .

  • Yep, I have plenty of time-based events that have just 1 condition such as : "If object value is equal to X"... and that seems to be as bad as "always"

    Before you go changing stuff, post an example of what you mean, just to be clear.

  • There's no need, I've done what the wiki recommends (switching to unlimited framerate for testing) and I think I've fixed everything.

    Using "always" conditions wasn't my main problem, it was conditions on their own which had nothing to do with time, I.E.

    Condition: if enemy value is equal to bla bla bla

    Is the same as using :

    Condition: always

    But it's all fixed now, thanks for the help .

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)