Draggable sprite overlapping different sprites

Get help using Construct 2

Post » Wed Jul 24, 2013 4:21 am

Hi guys,

I'm currently working on a project but I have a problem while doing it. Well I have a draggable sprite(chameleon) that will overlap two different sprites(DayBackground and NightBackground) and when the draggable sprite(chameleon) overlap to the different sprites(DayBackground and NightBackground), it will trigger different actions.

Example: Draggable sprite(Chameleon) overlap one of the sprite(DayBackground), the draggable sprite(Chameleon) will destroy.

I've tried doing sub-events and separating the conditions to different events but it doesn't work. How do I solve my problem? I want to achieve two different actions (based on 2 different conditions) using the same draggable sprite.

The two different sprite(DayBackground and NightBackground) are overlapping but I've solved the problem by positioning them out of the layout when it is not needed.

You can see the file here: https://www.dropbox.com/s/6r462q08qiac24e/Animals.capx

Hope to hear from you guys soon!
Thank you! Annisa122013-07-24 04:23:41
B
3
Posts: 5
Reputation: 312

Post » Wed Jul 24, 2013 5:01 am

At the end of the day to night transition, the background is still actually the daytime sprite, it's just on very last frame of the 'DayToNight' animation.. so it appears to be the nighttime sprite.

So.. now you probably realize that it's still being destroyed because the '..is overlapping daybackground' condition is still being met

You could just fix it so the background sprites swap correctly in the transition..

..but instead, i'd recommend redesigning this in a different way, which would solve your problem and also result in a cleaner events sheet.

have all the background stuff into one object, so don't worry about positioning/setting invisible etc.

And instead of checking what background it's overlapping, check a variable that toggles between 'day' and 'night' on the transition... or just a variable that toggles between 1 and 0 representing day and night.

This is good practice too as overlap checks are relatively expensive on cpu.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Wed Jul 24, 2013 7:47 am

Keepee: I've combine both animation to a single sprite but how do I toggles the variable? Is it Global Variable or Instance Variable? I never try Variable before and I'm currently lost right now. Hope you can help me :) I rarely use construct 2. Thank you!
B
3
Posts: 5
Reputation: 312

Post » Wed Jul 24, 2013 7:58 am

I think this CAPX will be more towards what you're after.

The WarmBlood animals will rotate right when you drag them on the day, and the ColdBlood animals will rotate left when you drag them on the night. And if you drop them anywhere else the will return to their original positions which are set at the start of the layout.

Note : That I have used families to make the code smaller, as well as put in conditions so you can't switch from day to night or move animals until the animations have finished.



If you have any questions, feel free to ask me
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699

Post » Wed Jul 24, 2013 8:39 am

emoaeden: Thank you so much :)
If I have any questions, I will let you know.
B
3
Posts: 5
Reputation: 312

Post » Wed Jul 24, 2013 2:56 pm

"..more towards what you're after"
[email protected]

Well, that's what I suggested you could settle for, but with 1 var you can lose the separate backgrounds' positioning and the overlap checking

@Annisa12 Variables are worth reading up on anyway, they'll open up possibilities/simplify stuff.. and are often essential. The manual will explain better than me, but in short, they are just stored values of number or text.

In this context what I was getting at, was a global text variable:

on touching the slide button for day/night, set that variable to "Day" or "Night"

and then in place of the 'is overlapping DayBackground' you can have 'if variable = "Day"'
or 'if variable = "Night"'

But anyways, not a big deal if this is all the project entails, but as it gets more complex, you'll probably want to start using them.
B
28
S
8
G
1
Posts: 469
Reputation: 4,683

Post » Thu Jul 25, 2013 4:27 am

@keepee
I was going to do it with variables, but from the look of the original CAPX, it seemed as if Annisa12 mightn't have known how to use them, and the changes I made were already vast, so I didn't want to add confusion
Using R243 for all examples
B
69
S
20
G
6
Posts: 379
Reputation: 9,699


Return to How do I....?

Who is online

Users browsing this forum: plinkie and 15 guests