Ariane Soft PPL2 Pocket Programming DataMite
  #1  
Old 12-20-2008, 12:44 PM
Nicknack Nicknack is offline
Senior Member
 
Join Date: Nov 2006
Location: Germany
Posts: 527
Default different sprite moves problem

i have created some codes which all uses different ways to retrieve the sprite position and i discovered that movesprite doesn't handle all those equally.
if you use spriteposint or spritex movesprite will floor the new position values (therefore moves the sprite in wrong direction), whereas spritepos and spritexint produces correct ones.
just click around, follow the sprite and tell me your thoughts about it
Attached Files
File Type: zip movetest.zip (3.8 KB, 179 views)
Reply With Quote
  #2  
Old 12-20-2008, 08:27 PM
Leginus Leginus is offline
Senior Member
 
Join Date: Mar 2008
Location: Chesterfield, Derbyshire, UK
Posts: 143
Default

Interesting discovery and it does the same here.
The saving fact is that although these are different, there isn't a need to use the different ones in a single scenario, but I guess you knew that and was just pointing the fact out that they are different.

Wow, don't I go on after a beer :-)
Reply With Quote
  #3  
Old 12-20-2008, 11:42 PM
zehlein zehlein is offline
Senior Member
 
Join Date: Sep 2006
Location: Leipzig, Germany
Posts: 596
Default

Contrary to what the help file tells us (and what it's meant to be) SpriteX() seems to give back an integer value and SpriteXInt() the float value of the sprite's position. Alain did it wrong in his code obviously.
Besides this, the sprite is acting as one should expect, not moving to higher x or y positions, only moving to the lower ones if you retrieve the position as an integer.
Reply With Quote
  #4  
Old 12-21-2008, 12:20 AM
Nicknack Nicknack is offline
Senior Member
 
Join Date: Nov 2006
Location: Germany
Posts: 527
Default

i thought it would be something like this, but why moves it only with lower integer values?
does ppl handles them then as float again?
Reply With Quote
  #5  
Old 12-21-2008, 08:44 AM
zehlein zehlein is offline
Senior Member
 
Join Date: Sep 2006
Location: Leipzig, Germany
Posts: 596
Default

If you use your debugger you can see pretty clearly what is happening let' say using SpritePosInt():
  • If you tap the screen right of Mario:
    angle$ becomes something between 0 and 10. Only if angle$ is exactly 0 (you have to tap the screen at x=100) cos360(angle$) will become 1. All other values will result in values lesser 1.
    Therefore after the line
    x$+=cos360(angle$);
    x$ will be in most cases 110<x<111 !
    Now the MoveSprite() uses the integer value of the x$ only, the sprite will not move to x=111.
    And, on top of this, at the next GameProc-call SpritePosInt() will set back x$ to 110 exactly - it returns integer values! Off you go - Mario won't move right (again, except for the case you tap the screen exactly at x=110)!
  • If you tap the screen left of Mario
    The x$-value becomes 109<x$<110. This will always move Mario to the left (x=109). After the next SpritPosInt()-call x$ is exactly 109 and if you tap left of Mario again, x$ becomes 108<x$<109. It will move left again.

Hope I could express myself clearly enough

Edit:
The simple
Code:
if (wParam$>x$)
  x$++;
else
  x$--;
end;
Is the better choice to deal with Mario here, except for the fact that the user would expect Mario to move left by tapping the screen at x=111 (he tapped in the left part of Mario's sprite!).
So the perfect solution would be
Code:
if (wParam$>(x$+SpriteWidth(sp$)/2))
  x$++;
else
  x$--;
end;

Last edited by zehlein; 12-21-2008 at 09:11 AM. Reason: Appended code
Reply With Quote
  #6  
Old 12-21-2008, 10:05 AM
Nicknack Nicknack is offline
Senior Member
 
Join Date: Nov 2006
Location: Germany
Posts: 527
Default

so in short, ppl floors the decimal values to get them as integer and therefore prefers most time the smaller position?
that would make sense, thanks for your great help
your other solutions might be only better if you don't care about straight lines as movement.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 09:13 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2021, Jelsoft Enterprises Ltd.
Copyright (c) ArianeSoft Inc.
Copyright © 2009 www.ppl-lang.com - All rights reserved
Web Design by BR Web Consulting Ltd