Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (108)
games submitted by our members
Games in WIP (536)
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 1106 times)
0 Members and 1 Guest are viewing this topic.
Offline cubemaster21
« Posted 2013-02-06 00: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.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
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
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline Z-Man
« Reply #1 - Posted 2013-02-06 00: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:
1  
2  
3  
4  
5  
6  
7  
8  
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-06 00: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 02: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
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline deepthought
« Reply #4 - Posted 2013-02-06 02: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 03: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 03:39:42 »

@deepthought
yeah, they're vectors.

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

Check out my game, Viking Supermarket Smash
http://www.java-gaming.org/topics/iconified/28984/view.html
Offline Agro
« Reply #7 - Posted 2013-02-06 03:45:20 »

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

Offline Axeman

Senior Member


Medals: 7



« Reply #8 - Posted 2013-02-07 01: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.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (16 views)
2014-07-30 21:08:39

Riven (23 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (33 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (43 views)
2014-07-24 01:59:36

Riven (42 views)
2014-07-23 21:16:32

Riven (30 views)
2014-07-23 21:07:15

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43
java-gaming.org 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‑gaming.org
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!