Hello, I have a working code with working sprites. But I'm trying to figure out how to make him stop moving when i don't hold down the key. Here is the code:
boolean operator) yes when using a Boolean you can 'ask' if it evaluates to false by prefacing it with a ! so if you say: if(!false) <- this evaluates to a 'true' condition because your asking for the opposite of the boolean
additionally one can use the != operator as in: if( x != 0 ) <- this says: "if x does not equal 0"
further, you can 'reverse' a boolean by using: myBoolean = !myBoolean; in this case regardless of the value of the boolean currently, it will 'change' the assignment to the opposite of the current value - this is very handy in situations like a 'mute' button where you wish to toggle the value
_xscale (AS2) scaleX (AS3) - yes, you can use scaling to 'flip' an instances transform property to a postive or a negative value, in addition to just simply scaling it to a percentage - so in this case i'm simply using the scale property to make it change from 100 to -100 (in as2 values, in as3 values are base on 0-1)
rateX) i simply used a property declaration there, so that it is simple to change the rate of movement by changing the property value - if speedX was a constant, then you would have to 'set' the x property directly, and this messes with the integration step - this is a 'clearer' way of adjusting the speed of the character movement
additionally, if one was to set up a more 'fluid' acceleration step you could increment the speedX value by 1 using the rateX value as a 'maximum' so that is slowly(relatively) increases it's speed until reaching the limit - much like the way that decrementing the y speed cause the impression of a gravitational force.
rateX) i simply used a property declaration there, so that it is simple to change the rate of movement by changing the property value - if speedX was a constant, then you would have to 'set' the x property directly, and this messes with the integration step - this is a 'clearer' way of adjusting the speed of the character movement
well, to be frank I dont use the integration step, I just do if (key.isdown(key.RIGHT)) { _x = _x + xspeed } lame huh?
no seriously, I don't get that your way is better.
the reason why, is only that it is more 'flexible' and just easier to change - for instance there are several areas that use the speed property - if it is a constant it cannot be adjusted without making the change to several instances or conditions - with this approach, you simply change the 'rate' prop and everything still works without having to adjust a properties or conditions in the code - when you have a large project that consists of several thousand lines, to go back through and adjust everything is a pain in the...
also, in effect you are integrating the property _x on every frame, but directly - what i have in the example is designed to 1) adjust the value of the speed (in this case it's a straight up change or similar to an impulse force) and 2) then use the adjusted property to affect the position of the instance.
imagine that you have multiple physical objects, when they collide, forces are applied to each body, and there also may be several forces of different vectors, first you sum the force vectors, then apply them all to the body - with a straight up method it's likely that the system won't handle this correctly.
I use xspeed a lot, mostly for consistency but it is very useful. Like you can make realistic free fall by having a yspeed variable, you can simulate friction using xspeed. For example, I had a helicopter that wouldn't instantly stop when I let go of left or right, but would deccelerate and continue to travel a little further even though I have let go of the arrow keys. This would also be useful for simulating icy floor in platformers where you might want the character to continue 'sliding' on the ice for some time after arrow keys are released.
Hey, you're right! I realized that I used that too when I made a thing that decelerates! And I realized also that I made a total crap that time...
And about _x += xspeed, yeah, I knew about it, but I'm not used to things like that or xspeed ++ or however it's written, I prefer to just go with the usual _x = _x + xspeed o_o
you're getting there Midmenj - i'd guess that the registration point is at center, and you're hitTest is using the reg point, rather than adding the half-height
also make sure that when you find the ground that you then 'set' the instance at the contact manifold - eg. the y point of the ground + the half-height (if reg is at center)
---- remember guys - "xspeed" is just a name, it can be anything you would like like xs, xsdp, x2, xreallylongpropertynamedblah... lol
If you are using the decreasing value way, it's like If (_root.hero.hitTest(_root.ground)) { If (decreasingValue > 0) { Gotoandstop(yourJumpingFrame) } Else { Gotoandstop(yourFallingFrame) } } I would do it this way, I dunno if beech is going to pwn me ;D