Question about events, timedelta and attributes

This forum is currently in read-only mode.
  • I have no doubt this question has been asked before, and I also have no doubt that someone will point me to an existing tutorial or doc, but I have searched and tried, I even thought a section of the basic ghost shooter tutorial would be the answer, but its not.

    Basically, I want a sprite (TARGET) to have no collision, and when another sprite (CURSOR) crosses or otherwise touches it (moved using the mouse), it will become solid and change colour for 5 seconds, before reverting to normal.

    I have tried the following events, after adding a private variable (TIMER) to the TARGET with a value of 0:

    on collision between CURSOR and TARGET, TARGET: set TIMER to 5*TimeDelta

    TARGET value TIMER greater or equal 1*TimeDelta, system TARGET add attribute 'solid'. Target subtract TimeDelta from TIMER

    TARGET value TIMER less than 1*TimeDelta, system TARGET remove attribute 'solid'

    When I run, the TARGET will become solid, but it stays solid permanently.

    I'm not a noob to design, but coding and similar logic isnt my strong point. Id appreciate help

  • Not sure if you really need timedelta here.

    + cursor: On collision between cursor and Sprite

    -+ System: Trigger once

    --> Sprite: Set filter to

    --> Sprite: Set collision mode to None

    --> Function: Call function "timer 1" after 5000 ms

    + Function: On function "timer 1"

    -> Sprite: Set filter to

    -> Sprite: Set collision mode to Per Pixel

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hi newt, thanks for the response.

    I've tried what you said - by 'sprite: set filter' do you mean the colour filter?

    I have assumed it is, and what happens when I run is the sprite will change colour for 5 seconds, but the collision does not change. I have tried setting the sprite properties with 'solid' checked, and also tried with 'solid' unchecked.

    I have tried changing 'set collision mode' to add/remove attribute: solid, in the first event, then set collision mode: none, in the second. This works, so hopefully I can get away with it.

    However - as soon as I trigger the event, all duplicates of the sprite are affected, how do I make it affect only one sprite per collision?

    EDIT: I'm guessing its to do with applying a private variable, but I cant quite get my head around it.

  • You could place the sprite into a family, and have it check for a collision with family. That should solve the picking issue without having to introduce a private variable.

    Also "solid" is an attribute that some behaviors use. Its basically a way to do automatic collision detection. So unless your using a behavior its probably un needed.

  • I'm not too clued up on families yet, but I'll take your advice and guidance and try to work it out myself first, rather than asking.

    Cheers mate

  • Ok, when you set a private variable you don't need to use Timedelta. Only when you want it to change over time. The collision event would take care of the picking issue.

    So,

    Cursor overlaps Target - set timer to 5 This will only affect the sprites that are overlapping, after this line we are working only from the timer variable, so only the sprite with the changed variable will be affected.

    Timer is greater than 0 - Subtract 1*timedelta. This will bring Timer down 1 every second

    -Change collisions

    -Change colour filter

    Timer is less than 0 - Set timer to 0 - I don't know if this is needed without running it, but i think timedelta will run down below 0, so just in case this is here to lock it to 0

    Timer is equal to 0 - Change Collisions

    -Change colour filter

    TARGET value TIMER greater or equal 1*TimeDelta, system TARGET add attribute 'solid'. Target subtract TimeDelta from TIMER

    TARGET value TIMER less than 1*TimeDelta, system TARGET remove attribute 'solid'

    I believe this is where your problem is coming from. You are subtracting until it is 1, not below it. You condition to change the collisions comes when it is below 1. Have a look at that variable in your debug run.

  • Okay, for whatever stupid ignorant reasons, I just cant get it to function, so what I have done is create a seperate sprite to act as a bounding box collision, then creating it on collision, then destroying it after 5 seconds.

    Seems to do the job.

  • Final problem thats been niggling me:

    I want it to function so the collision change will only occur if the cursor overlaps the target for X seconds. If the cursor is removed then the duration will count down to 0.

    Hope that makes sense - If I move the cursor over the target, after 5 seconds (for example) the collision will change, if I remove the cursor before 5 seconds, the timer will deplete, but if I move back over again it will start counting up again from its current value.

  • I made an example this morning, and found why it is not working. I am also running late so forgive the short post.

    So in the example, you have the timer counting up if overlapped, and counting down if not. It also triggers another value at 5 seconds which lasts until the value has counted down. There is not collision change in this example because that was the problem. With no collisions you can't overlap objects with it.

    http://dl.dropbox.com/u/1487524/Scirra/ ... xample.cap

  • I'll have a look at your example, thanks Steven.

  • Here's another way to do it:

    Initially give "Sprite" the attribute solid. Sprite only needs 1 private variable 'time'.

    EDIT:

    Also add a box object and add it to a container with sprite. The box objects will serve as the collision detection for sprite because when sprite is set to no collision an overlapping condition can never be true.

    Here's what I came up with:

    http://dl.dropbox.com/u/5426011/examples/hideplatform.cap

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