Question about events, timedelta and attributes

For questions about using Classic.

Post » Mon Jun 21, 2010 9:08 pm

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 :)
B
3
G
2
Posts: 11
Reputation: 697

Post » Tue Jun 22, 2010 4:45 am

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
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jun 22, 2010 7:59 am

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.
B
3
G
2
Posts: 11
Reputation: 697

Post » Tue Jun 22, 2010 10:20 am

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.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jun 22, 2010 6:27 pm

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
B
3
G
2
Posts: 11
Reputation: 697

Post » Wed Jun 23, 2010 4:51 am

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.
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Wed Jun 23, 2010 11:21 am

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.
B
3
G
2
Posts: 11
Reputation: 697

Post » Wed Jun 23, 2010 7:20 pm

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.
B
3
G
2
Posts: 11
Reputation: 697

Post » Wed Jun 23, 2010 8:02 pm

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
B
9
S
2
G
4
Posts: 346
Reputation: 2,726

Post » Thu Jun 24, 2010 8:19 am

I'll have a look at your example, thanks Steven.
B
3
G
2
Posts: 11
Reputation: 697

Next

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests