Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (755)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (842)
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  
  How to move one tile (Grid movement, like pokemon and zelda)  (Read 3777 times)
0 Members and 1 Guest are viewing this topic.
Offline printer

Junior Devvie


Medals: 1



« Posted 2016-06-20 11:33:52 »

Hello,

i have made a simple game. But i would love to know, how to move 1 tile. Now the Player is "jumping" 3-4 tiles and speed is to fast and animation is not showing due to that.

Main Thread:
http://pastebin.com/meyahFUY

Player:
http://pastebin.com/5URYsrgt

Creature Abstract class:
http://pastebin.com/jLV7RkwV

Animation, i'm using this:
http://gamedev.stackexchange.com/a/53709

PositionVector:
http://pastebin.com/b5i469Vi

DirectionVector:
http://pastebin.com/4Dgx2Kew

Map:
http://pastebin.com/dFJAktqV

Camera:
http://pastebin.com/QjBX2tUR

I would appricate all the help!
Offline SuperMario
« Reply #1 - Posted 2016-06-20 12:55:15 »

You could try to set a destination

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
if (!moving){
            if (keys.W is down) {
                targetY = y + tileSize;
                moving = true;
            }
        } else {
         updateAnim
         }
       
if (x < targetX)x++;
if (x > targetX)x--;
if (y < targetY)y++;
if (y > targetY)y--;
Offline printer

Junior Devvie


Medals: 1



« Reply #2 - Posted 2016-06-20 13:23:15 »

You could try to set a destination

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
if (!moving){
            if (keys.W is down) {
                targetY = y + tileSize;
                moving = true;
            }
        } else {
         updateAnim
         }
       
if (x < targetX)x++;
if (x > targetX)x--;
if (y < targetY)y++;
if (y > targetY)y--;


I woud like to make it work, with my current setup Sad Problem is that, the player moves. But it moves couple tiles, i would like to move one tile per time.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline SuperMario
« Reply #3 - Posted 2016-06-20 13:54:27 »

then only move when you've reached your next tile
Offline printer

Junior Devvie


Medals: 1



« Reply #4 - Posted 2016-06-20 13:59:04 »

I'm already doing that, i think  Tongue
Offline LostWarrior

Senior Devvie


Medals: 8
Exp: 5 years



« Reply #5 - Posted 2016-06-20 19:03:42 »

What I do is I keep the direction the player is moving towards stored in a variable. Then to get the smooth movement I interpolate between the position the player was standing and the position the player should move to. That way you get a nice movement, dependent on the delta and a specific speed. The player won't accidently move over the tile and get stuck a few pixels off, since the final position per tile is already decided. Once the alpha, or percentage of the step is at 1.0, you check if any direction keys are pressed and you do the whole thing all over again. This is a very simple but efficient and smooth way of achieving what you want.

Cows aren't sheep, because pigs already are.
Offline printer

Junior Devvie


Medals: 1



« Reply #6 - Posted 2016-06-20 19:09:21 »

Thank you for your answer. Could you please present me with code examples based on my current setup. Since i've been dealing with this for couple days with no luck Sad
Offline printer

Junior Devvie


Medals: 1



« Reply #7 - Posted 2016-06-21 10:48:41 »

None?
Offline ndnwarrior15
« Reply #8 - Posted 2016-07-10 05:51:12 »

Were you able to figure it out?
Pages: [1]
  ignore  |  Print  
 
 

 
DesertCoockie (52 views)
2018-05-13 18:23:11

nelsongames (83 views)
2018-04-24 18:15:36

nelsongames (74 views)
2018-04-24 18:14:32

ivj94 (759 views)
2018-03-24 14:47:39

ivj94 (87 views)
2018-03-24 14:46:31

ivj94 (643 views)
2018-03-24 14:43:53

Solater (102 views)
2018-03-17 05:04:08

nelsongames (184 views)
2018-03-05 17:56:34

Gornova (426 views)
2018-03-02 22:15:33

buddyBro (1086 views)
2018-02-28 16:59:18
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!