Same sprite with random sine behaviour (capx incl.)

0 favourites
  • 6 posts
From the Asset Store
Rotate & Animation for 16 Direction & Mouse Direction
  • Hi,

    I want to have one sprite that I generate at random location, and then I want that sprite to have a random sine behavior assigned, either a horizontal or a vertical in a random order, and I want that behavior to be consistent throughout the sprite’s journey down the screen.

    What I have achieved is not a consistent behaviour. It changes throughout the sprite’s journey.

    Please correct my capx!

    dropbox.com/s/dgyd9feysmve9jv/randomSine.capx?dl=0

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Event 2 doesn't pick a Sprite, so it affects all Sprites. Either move the random action to event 5 and skip the function, or pass in the UID of Sprite to the function and Pick by UID first, to get the correct instance.

  • Thanks for the reply, I have been messing around with picking by UID trying to pass that into the function as a parameter but I could not achieve a desired effect. I probably do not understand how that UID works, what is the best source of reference to learn that? I have browsed through a couple of tutorials. Have not found them useful, should you know of the most relevant one, let me know!

  • Thanks for the reply, I have been messing around with picking by UID trying to pass that into the function as a parameter but I could not achieve a desired effect. I probably do not understand how that UID works, what is the best source of reference to learn that? I have browsed through a couple of tutorials. Have not found them useful, should you know of the most relevant one, let me know!

    Voytek

    1-You will need the two things the UID of who is calling the function and normally this you will pass it in a parameter when you call the function, you can add as much as parameters you like but for this you just need 1 parameter so the first parameter will count from (0) wich means on parameter 0 you will add the Sprite.UID wich will be the sprite UID who is calling the function

    2-And the second one, once you created the function you need to tell the function that needs to apply those Actions that are inside the Function just to that UID who is calling the Function, this you do it by (sprite>> Pick by unick UID) then you will have to add from where? has to pick the UID so you add Pick From "Function.Param(0)" wich is the Sprite.UID that you pass when you calling the function

    Example:

    Trigger to call the function:

    Sprite On created: Call Function "randomMove" + Add Parameter= Parameter 0 so here you add the Sprite.UID

    Function:

    On Function "randomMove"

    Second Condition: (sprite>> Pick by unick UID) =here you add: Function.Param(0)

    Here is an Example just in case you didn't understand my explanation, here I just changed two things from your capx,

    Line 2: I added Second Condition: (sprite>> Pick by unick UID) =Function.Param(0)

    Line 4: Added Parameter= Parameter 0 = Sprite.UID

    Capx: https://www.dropbox.com/s/hx3cb8iyyid3dc0/Sine.UID.capx?dl=0

  • There is not much to say about UID. It just a unique number assigned by the system to every instance of an object.

    It has only a few ACE's. ACE stands for Action, Condition, Expression.

    Conditions:

    System > Object UID exist <---- see if there is an object with that UID

    Object > Pick by unique ID <-- Pick the instance matching an UID.

    Actions

    None

    Expressions

    Object.UID <----- returns UID of that object. Use it where ever you can type as a variable.

    And that is all there is to say.

    Now that is out of the way, i have some question for you.

    Use a function when you want to use the same block of code without duplicating it (less events) or when you want to pick from scratch. So ......

    Why use a function, when as a result there are more events ?

    Why use 'on creation' ? When the only result is more event ?

    Why duplicate Event 5 into Event 6 ? This would be an good excuse to use a function, eventually.

    Why apply those actions on Sine for EACH object for EACH tick ?

    Why change properties that are easier to set (and change later on) in the properties pane ?

    Why try to include that 1 sprite created in the layout and all the weird tricks that go with it ? Just destroy it.

    If you keep going this way, you end up with ...

    (1) to many not-debug-gable events ... &

    (2) a performance of close to zero because to many objects are forced to do something every tick.

    https://www.dropbox.com/s/c2mxttsyp6i9d ... .capx?dl=0

    Edit: I see that tarek2 reacted in his helpful, lovely way while i was writing this, i have nothing to add, but i post this aywayz

  • Thank you for fabulous answers, I really appreciate your expertise assistance.

    A few questions have been asked. Well, I suppose that majority are to let me think more about what I do, there is also one that appears it should be answered on my part:

    [quote:2slt9lcp]Why apply those actions on Sine for EACH object for EACH tick ?

    [quote:2slt9lcp]Why apply those actions on Sine for EACH object

    I actually want to have two sprites with the same random behaviour,

    one a friend and one a folly, the only way to distinguish them

    is not by their behaviour, which changes, but by the way they look. Futhermore, sine

    is supposed to add some action to the game as well as serve as a confusing element

    for the player.

    [quote:2slt9lcp]for EACH tick

    I want my sprites to travel from top to bottom with these behaviours, I suppose the way to do it is in the capx.

    There is one comment/question that I am uncertain whether I get it right. You may clarify if it is of any importance:

    [quote:2slt9lcp]Why try to include that 1 sprite created in the layout and all the weird tricks that go with it ? Just destroy it.

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