Hi !
Featured games (84)
games approved by the League of Dukes
Games in Showcase (601)
Games in Android Showcase (171)
games submitted by our members
Games in WIP (649)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  lastPosition always equals current Position  (Read 1716 times)
0 Members and 1 Guest are viewing this topic.
Offline cubemaster21
« Posted 2013-02-05 23:25:00 »

I'm having the problem that is said in the title and have no idea why it's happening.  This is the code that i believe is causing the problem. There's gotta be something weird going on with it.
public void moveTo(double x, double y){
      double x1 = pos.x;
      double y1 = pos.y;
      lastPos.x = x1;
      lastPos.y = y1;
      if(map.get((int)x,(int) y).walkable){
         this.pos.x = x;
         this.pos.y = y;

Check out my game, Viking Supermarket Smash
Offline Z-Man
« Reply #1 - Posted 2013-02-05 23:47:52 »

Well you probably don't want to update the last position unless you can actually move to the new one, and there's no need for the x1 and y1 variables. I can't really see what would be causing your problem but I'd change the method to something like this:
public void moveTo(double x, double y) {
   if(map.get((int)x, (int)y).walkable) {
      lastPos.x = pos.x;
      lastPos.y = pos.y;
      pos.x = x;
      pos.y = y;

Have you tried printing all the variables before and after to see what's actually happening? That can be helpful.
Offline Agro
« Reply #2 - Posted 2013-02-05 23:49:25 »

Try printing out what the values are at given breakpoints. Cheesy

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline cubemaster21
« Reply #3 - Posted 2013-02-06 01:35:14 »

I plugged in a couple of println statements for lastPos.x and it equals where i am going to move for some reason, even before i set lastPos.x = pos.x. I had the x1 and y1 in their because I thought it was some sort of pointer problem.

Check out my game, Viking Supermarket Smash
Offline deepthought
« Reply #4 - Posted 2013-02-06 01:49:44 »

what are pos and lastpos? vecmath vectors?

if not, what type is x and y?

jocks rule the highschools. GEEKS RULE THE WORLD MWAHAHAHA!!
captain failure test game
Offline Agro
« Reply #5 - Posted 2013-02-06 02:23:18 »

It might be a problem with the if statement. The position will never change. I think that's your only solution here, because other than that, there's nothing seem to be wrong.

Offline cubemaster21
« Reply #6 - Posted 2013-02-06 02:39:42 »

yeah, they're vectors.

movement works fine other than the fact that the lastPos variable is always wrong.

Check out my game, Viking Supermarket Smash
Offline Agro
« Reply #7 - Posted 2013-02-06 02:45:20 »

initialize a new vector of lastpos that has the value lastx and lasty

Offline Axeman

Senior Devvie

Medals: 7

« Reply #8 - Posted 2013-02-07 00:06:35 »

Do you perhaps assign lastPos = pos somewhere in your code? It can happen if you´re not careful, thinking you´re copying the x,y-values of pos when you´re actually copying the reference to pos. It can cause quite a mess.
Pages: [1]
  ignore  |  Print  
You cannot reply to this message, because it is very, very old.

Jesse (11 views)
2015-07-29 04:35:27

Riven (33 views)
2015-07-27 16:38:00

Riven (16 views)
2015-07-27 15:35:20

Riven (20 views)
2015-07-27 12:26:13

Riven (10 views)
2015-07-27 12:23:39

BurntPizza (28 views)
2015-07-25 00:14:37

BurntPizza (39 views)
2015-07-24 22:06:39

BurntPizza (22 views)
2015-07-24 06:06:53

NoxInc (25 views)
2015-07-22 22:16:53

NoxInc (17 views)
2015-07-22 22:13:39
List of Learning Resources
by gouessej
2015-07-09 11:29:36

How Do I Expand My Game?
by bashfrog
2015-06-14 11:34:43

List of Learning Resources
by PocketCrafter7
2015-05-31 05:37:30

Intersection Methods
by Roquen
2015-05-29 08:19:33

List of Learning Resources
by SilverTiger
2015-05-05 10:20:32

How to: JGO Wiki
by Mac70
2015-02-17 20:56:16

2D Dynamic Lighting
by ThePixelPony
2015-01-01 20:25:42

How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!