The Daily Click ::. Forums ::. Klik Coding Help ::. X and y positions using decimals
 

Post Reply  Post Oekaki 
 

Posted By Message

Ganymede Graphics

Possibly Insane

Registered
  17/04/2006
Points
  2711

GOTW JANUARY 2011
13th July, 2007 at 00:23:20 -

I've always had a little trouble using decimals with x and y positions. Its not hard to notice that MMF2 doesn't actually use decimals properly. Or, I don't know how to use them properly. For an example, If I just want to move a character to the right, with small acceleration I will say:

*repeat while right is pressed
-add 0.1 to alterable value a(char)

*always
-set x(char) to x(char) + alterable value a(char)

Looks alright to me. But I know something is sapping it because when I start it up, It does move for sure, but its kinda crappy because it doesn't actually read the decimals. What I'm trying is a little hard to explain. What its doing now is, when that 0.1 keeps rising, it eventually reaches 1, then the character, every frame starts to move one pixel to the right. then when it gets to 2, it starts moving 2 pixels every frame, so on, thats pretty simple. What I want it to do is, basically I want the x position reader thing to always add alterable value a to itself. So if I leave alterable value a at 0.1, then I'd think at around every 10th of a second, the character would move 1 pixel to the right. Right now if I did so, then nothing would happen at all, alterable value a would just stay at 0.1, and the character would just stay right where he is.

If you can let me know how I can get my character to move properly, the way I said I wanted if you could understand my...dodgy explanation I'l be really greatful. An example of what I was trying to achieve can be found in the new fastloop platform movement recently submitted. The character in that one was moving the way I want it. I'd tried to analyze the code, but I was never really able to duplicate the movement myself.

 
Especially that.

Airflow

imafirinmahlazr

Registered
  24/09/2003
Points
  -197

VIP MemberSonic SpeedSnow Cloud!Computer
13th July, 2007 at 01:52:15 -

It sounds like you're using acceleration to me. x=x+a, where 'a' increases. Instead:

setx(char) to x(char)+ 0.1

which doesn't work. Because I have roblems with decimals too. What you were trying to do was

*start of level
-set b(char) to x(char)

*repeat while right is pressed
-add 0.1 to alterable value a(char)

*always
-set x(char) to b(char) + alterable value a(char)

 
n/a

Ganymede Graphics

Possibly Insane

Registered
  17/04/2006
Points
  2711

GOTW JANUARY 2011
13th July, 2007 at 03:43:08 -

thanks for the help, but that way didn't really work. It did work in the way that the character moved very slowly, but there wasn't any acceleration. Maybe I didn't really explain properly. I want it to be like

*Repeat while right pressed
-add 1 to a(char)
*Always
-set x(char) to x(char) + a(char)

I want to have that, but have it increase very smoothly, so you don't get the jerky increase in speed every time
a(char) reaches a whole number.

 
Especially that.

Airflow

imafirinmahlazr

Registered
  24/09/2003
Points
  -197

VIP MemberSonic SpeedSnow Cloud!Computer
13th July, 2007 at 04:11:49 -

*repeat while right isn't pressed
-subtract 0.1 to alterable value a(char)

???

If you make multipul copies of the event, the decelleration will be slower. Or you could have it so that

*repeat while right isn't pressed
set value a(char) to zero

the stopping will be jerky, but therwise Metriod like.



 
n/a

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
13th July, 2007 at 04:57:47 -

Use alterable values to record the X/Y positions.

Have a value X and value Y, where:

Always:
Set position X to (value X / 10000)
Set position Y to (value Y / 10000)

Then you can simply alter the values, in place of the X/Y positions. The values will not hold decimals, but if you multiply everything by 10000, they act as if they had 4 decimal spots.




If you want to move it 1.0 pixel to the left, simply
*Add 10000 to value X

if you want to move it .1 pixel to the left
*Add 1000 to value X

Image Edited by the Author.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Ganymede Graphics

Possibly Insane

Registered
  17/04/2006
Points
  2711

GOTW JANUARY 2011
13th July, 2007 at 05:20:27 -

I'm not great with this. It probably takes something more to get this working properly. Pixel, Sorry to be a pain, but it still doesn't really do what I want it to. I want to have it to accelerate and basically have an infinite speed limit. I don't want it to just move a pixel every 10th of a second. Its a little hard to explain exactly what I want, a little more help would be greatly appreciated.

 
Especially that.

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
13th July, 2007 at 05:38:44 -

If you want it to accellerate, do the exact same thing, just with a twist:

Keep the X/Y = xposition and yposition, just add this:

Always
*Add to valueX valueXaccel
*Add to valueY valueYaccel


Repeat upon pressing Right
*Add to valueXaccel 100


Basically, have a 2nd pair of variables be your acceleration.
I use this EXACT kind of movement inside my 2d Advanced Space Scrolling download, if you want to check it out:
http://www.create-games.com/download.asp?id=6767

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Pixelthief

Dedicated klik scientist

Registered
  02/01/2002
Points
  3419

Game of the Week WinnerWeekly Picture Me This Winner!You've Been Circy'd!VIP MemberI like Aliens!Evil klikerThe SpinsterI donated an open source project
13th July, 2007 at 05:40:22 -

You'll also find, however, that the "infinite speed limit" will run into a wall when you hit +- 32000 pixels, on the X or Y

So using values entirely and completely skipping the x/y positions and scrollings that are built in are the only way to create extremely large areas.

 
Gridquest V2.00 is out!!
http://www.create-games.com/download.asp?id=7456

Joe.H

Evil Faker

Registered
  19/08/2002
Points
  3305
13th July, 2007 at 06:17:03 -

*1.0

 
My signature is never too big!!!

nim



Registered
  17/05/2002
Points
  7234
13th July, 2007 at 06:28:47 -

I think Pixelthief's reply is what you're looking for. In plain English, what you're doing is adding large values to a couple of alterable values (one for x, one for y) then dividing by a similarly large number at the end.

Try this single event and see what happens:

Always
Add 10 to Alterable value A("Active 1")
Set X("Active 1") to -> Alterable value A("Active 1")/1000

I can't try that out just now, but I reckon it should be what you're looking for. Basically it's the same as Pixelthief's example up there.

 
//

Fifth

Quadruped

Registered
  07/05/2003
Points
  5818

VIP MemberGOTW JULY 2010 WINNER!Kliktober Special Award TagGOTW HALLOWEEN 2011 WINNERPicture Me This Round 51 Winner!
13th July, 2007 at 12:26:10 -

Well, the simplest version of what I used in my movement is like this:

Always:
-Add Value A(Active) to Value B(Active)
-Set X(Active) to X(Active) + int( Value B(Active) / 10 )
-Subtract 10 * int( Value B(Active) / 10 ) from Value B(Active)

What this does is adds the speed value (value A) to the movement value (value B) every frame.
When the movement value exceeds 10 or -10, that movement/10 is added to the object's position (which is applied through the int(value B/10).
It then subtracts from the movement value the number of pixels that have been moved (which is the last line: divided by 10, integered, and multiplied by 10 again).

I hope that made some sense.
So you can adapt that by making the speed value equal your player speed whenever you're holding right.

 
Go Moon!
   

Post Reply



 



Advertisement

Worth A Click