How do I correctly use this expression

Get help using Construct 2

Post » Fri May 22, 2015 3:43 pm

Hello all,

I'm trying to move a number of objects off the screen. I can do this by:-

Every tick -> Set Y -> Self.Y+1

The above works exactly as I want. The object moves down and off the screen. Except it keeps moving forever, obviously. So, I thought I would try:-

Every tick -> Set Y -> Self.Y = 490 | self.Y < 490 ? Self.Y+0 : self.Y + 1

However, that does nothing. I have looked in the manual (which is where I got the idea for the expression). Could someone please advise where I'm going wrong. thanks.
Last edited by tekkendp on Fri May 22, 2015 4:00 pm, edited 1 time in total.
B
12
S
2
Posts: 15
Reputation: 1,084

Post » Fri May 22, 2015 3:59 pm

Ok - I have figured out what I was doing wrong:-

Every tick -> Set Y -> Self.Y = 490 ? Self.Y+0 : self.Y+1

It's works well, but is it good practise?
B
12
S
2
Posts: 15
Reputation: 1,084

Post » Fri May 22, 2015 4:02 pm

You don't say, but I am guessing you want to destroy the object when it is outside of layout?
Here is one way:
Image
B
35
S
10
G
4
Posts: 250
Reputation: 7,908

Post » Sat May 23, 2015 1:59 am

what do u want to do with that?
Play my games on www.pocketgames.es
B
13
S
3
Posts: 45
Reputation: 819

Post » Sat May 23, 2015 3:15 am

It is one way.
But indeed you can use some behavior.
Or simply use the "Is on screen" condition of an object. As long as it is true, you move it down.
The moment the object is out of the screen it won't be moved anymore.

To apply a movement you can also add the bullet behavior, this way you don't need code (apart some code to mention that once out of the screen you want the object to stop moving, have the bullet speed set to 0).

You can find about all this in the manual as well.
New to Construct ? Where to start

Image Image

Image Image

Please attach a capx to any help request or bug report !
Moderator
B
284
S
109
G
91
Posts: 7,319
Reputation: 87,487

Post » Sat May 23, 2015 7:39 am

I would not use "Every tick: something.Y+1", it will heavily depend on frame rate and if your game runs at 30 fps for one player and 60 fps for the other, it is 100% faster for the second player compared to the first player.
Visual Novel 'Engine' in 100 Events
if you ever have to choose between buying Construct 2 on scirra.com or on Steam, read this: Review
B
22
S
9
G
1
Posts: 787
Reputation: 3,786

Post » Sun May 24, 2015 3:24 pm

Thanks for the responses.

I want to smoothly slide elements (text, buttons sprites, etc...) on and off the screen. It's for a side menu I'm creating. It works pretty well (now that I have sorted out the logic). I was just wondering if it is the most efficient way to do it.

@Kyatric - I will have a look at the bullet behavior - thanks for the tip.

@mindfaQ - I was worried about the fps response, but this is not a game I'm making (it's a simple MP4 video player), the response is great (on a pc anyway - I have not tested it on my windows tablet or android phone ..... yet).
B
12
S
2
Posts: 15
Reputation: 1,084


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher, NN81, plinkie, sublimate, TsubaRu and 10 guests