How do I move this sprite with event

Get help using Construct 2

Post » Sat Nov 12, 2016 10:01 am

Hi , I want to move an sprite about 250px to right by 8-direction behavior when tapped another sprite,How I can Do it? Plz help me
B
4
Posts: 26
Reputation: 252

Post » Sat Nov 12, 2016 3:07 pm

Rexrainbow plugin 'moveto' is good for moving a number of pixels in any direction. If you mean just teleport 250px to the right then you can just set a new position for the sprite x+250.
B
45
S
15
G
73
Posts: 2,002
Reputation: 43,386

Post » Sat Nov 12, 2016 7:34 pm

if u woldv use bullet behavior u wold had the distance traveled.. however since your object is not a bullet and u dont want to mix the 2 of them cause of obvious glitches..


create a instance variable on the player with the movement controls.

when any key is pressed (left or right) that enables the movement, triger one time set the instance variable (lets say posx) to players.x then

compare two variables : distance(player.x,0,player.posx,0) is less then 250 simulate left or right control. that way ur char will only move when the buttons are pressed if the distance is less then 250 pixels. then when u release and press again everything should restart itself.


Distance limited movement


if that is what ur not looking for, then what @plinkie said for the "teleporting movement"setting the .x to + 250 or -250 wold do it.
B
70
S
20
G
67
Posts: 1,314
Reputation: 42,301

Post » Sun Nov 13, 2016 10:16 am

plinkie wrote:Rexrainbow plugin 'moveto' is good for moving a number of pixels in any direction. If you mean just teleport 250px to the right then you can just set a new position for the sprite x+250.

Rexrainbow plugin 'moveto' does work with Intel XDK ?
B
4
Posts: 26
Reputation: 252

Post » Sun Nov 13, 2016 10:42 am

@gamecorpstudio Your example was very good but I Want to move 250px just by one tap and not by isTouching , how should I do It?
B
4
Posts: 26
Reputation: 252

Post » Sun Nov 13, 2016 12:11 pm

I don't think the C2 plugins matter for Intel XDK, it's not a third party plugin that you add when building with the XDK it's just a thing that is included in the C2 project that you will export before you get to Intel XDK.
B
45
S
15
G
73
Posts: 2,002
Reputation: 43,386

Post » Sun Nov 13, 2016 1:19 pm

@plinkie Thanks Man !
B
4
Posts: 26
Reputation: 252

Post » Sun Nov 13, 2016 4:18 pm

amirreza225 wrote:@gamecorpstudio Your example was very good but I Want to move 250px just by one tap and not by isTouching , how should I do It?



that is easy also, however depends what you want to use it with or for, cause if u use some sort of physics, or collision feature behavior with it then u need to create a Boolean and basically change the "on keeping pressed" so it creates a loop, if you dont need physics, same applies, but instead of the 8 way behavior u use "move at angle - pixels "


edited the capx i added a description for the instance variables also(you can see the meaning of instance variable when u click the Sprite "player" and in left side instance variables, then at bottom of settings u should see a text explaining it.) you can also modify the speed it travels at, however i suggest to do the increase in speed to be something like this (400,800,1000 or any par number increased by power of 2), that wold avoid the player going sometimes to far by 1-5 -10 pixels sometimes.
B
70
S
20
G
67
Posts: 1,314
Reputation: 42,301


Return to How do I....?

Who is online

Users browsing this forum: Darth Crusher, NyxoGe, zsoldiers and 5 guests