Thread: How To make a sprite move

Page 1 of 2 12 LastLast
Results 1 to 10 of 17
  1. #1 How To make a sprite move 
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    27
    Posts
    2,101
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Ok i'm gonna teach you guys how to do this.

    First you are going to open Sprite.java and add this:

    Code:
    	public int movingX , movingY = 0;
    	public boolean movedEnough = false;
    	private boolean startedMoving = false;
    
    	/**
    	 * Used to make sprites move
    	 * @param finalCoordX 
    	 * 				The final X coord of the sprite
    	 * @param finalCoordY 
    	 * 				The final Y coord of the sprite
    	 * @param startingX 
    	 * 				The starting X coord of the sprite
    	 * @param startingY 
    	 * 				The starting y coord of the sprite
    	 * @param speed 
    	 * 				How fast the sprite will move
    	 * @param coordToMove 
    	 * 				Which coord to move? x? y? or both?
    	 * @param advancedSprite 
    	 */
    	public void drawMovingSprite(int finalCoordX, int finalCoordY,int startingX, int startingY, 
    			int speed, char coordToMove, boolean advancedSprite) {
    		if(!startedMoving) {
    			movingX = startingX;
    			movingY = startingY;
    			startedMoving = true;
    		}
    		if(!movedEnough) {
    			if(coordToMove == 'y')
    				movingY += speed;
    			if(coordToMove == 'x')
    				movingX += speed;
    			if(coordToMove == 'b') {
    				movingX += speed;
    				movingY += speed;
    			}
    			if((speed < 0 ? movingX <= finalCoordX : movingX >= finalCoordX) && (coordToMove == 'x' || coordToMove == 'b')) {
    				movingX = finalCoordX;
    				movedEnough = true;
    			}
    			if((speed < 0 ? movingY <= finalCoordY : movingY >= finalCoordY) && (coordToMove == 'y' || coordToMove == 'b')) {
    				movingY = finalCoordY;
    				movedEnough = true;
    			}
    			setSprite(coordToMove == 'y' ? startingX : movingX,coordToMove == 'x' ? 
    					startingY : movingY, advancedSprite);
    		} else 
    			setSprite(coordToMove == 'y' ? startingX : movingX, coordToMove == 'x' ? 
    					startingY : movingY, advancedSprite);
    	}
    
    	public void setSprite(int spriteX, int spriteY, boolean advancedSprite) {
    		if(advancedSprite)
    			drawAdvancedSprite(spriteX, spriteY);
    		else
    			drawSprite(spriteX, spriteY);
    	}
    Now imagine you want to make your login Box move:

    Sprite loginBox = new Sprite(DIRECTORY);

    Now where you draw your loginscreen you would do something like this:

    loginBox.drawMovingSprite(FINAL X COORD, FINAL Y COORD, STARTING X COORD, STARTING Y COORD, SPEED, 'coordToMove', IS IT AN ADVANCED SPRITE?);

    *FINAL COORDS - This is where you set the final coordinates which means when the sprite stops moving it will stand at those coordinates.
    *STARTING COORDS - This is where you set the starting coordinates which means the sprite will start moving from those coordinates and will keep moving until it reaches the final coordinates.
    *SPEED - that is pretty obvious, it's the speed you want the sprite to move.
    *coordToMove - 'x', 'y', 'b' - This is where you choose what coordinate do you want to play with the x coord or y coord or even both.


    This works pretty nicely, but i think it can get a few improvements, feel free to do them yourself
    Reply With Quote  
     

  2. #2  
    Registered Member jelleplomp's Avatar
    Join Date
    Oct 2012
    Age
    26
    Posts
    549
    Thanks given
    73
    Thanks received
    6
    Rep Power
    11
    nice (:
    Reply With Quote  
     

  3. #3  
    « Pokémon Master »
    Ash Ketchum's Avatar
    Join Date
    Jun 2011
    Age
    29
    Posts
    1,423
    Thanks given
    275
    Thanks received
    153
    Rep Power
    39
    So this is kind of like overloadx's sprite that moves across screen on login? It seems as if that's what it is, but this seems a lot more, uhm, well can't think of the word right now but im sure it has more applications rather than just changing the x and y. Im sure this would be interesting for drawing your loginbox when your client finishes loading. This is actually kind of a neat thing. Im on my phone right now so when I get home I will take another look at this and possibly come up with a few different ways to use it.

    Good job
    Attached image
    Spoiler for Galkon:

    Spoiler for Great Quotes:
    Quote Originally Posted by i am prod View Post
    **** YOU this just erased everyones passwords and no one can log in!!!
    Quote Originally Posted by blade2 View Post
    did i ****ing say it was a ****ing virus u dip shit i said virus scan dont scan java files i didn't say its a virus... l2****ingreadkid
    Spoiler for (╯°□°)╯︵┻━┻:
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Mar 2013
    Posts
    181
    Thanks given
    63
    Thanks received
    39
    Rep Power
    25
    No way... This is from your project-exile client isn't it?! Thanks so much, gonna use
    Reply With Quote  
     

  5. #5  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    27
    Posts
    2,101
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Yes this is from project-exile and what it does is move a sprite pretty much
    Reply With Quote  
     

  6. #6  
    Google it ffs

    Reich's Avatar
    Join Date
    Mar 2011
    Age
    30
    Posts
    825
    Thanks given
    120
    Thanks received
    174
    Rep Power
    105
    Could be done in a lot less work but it's good i guess...
    Programmers are machines that convert caffeine into code
    Reply With Quote  
     

  7. #7  
    Donator

    Tringan's Avatar
    Join Date
    Feb 2011
    Age
    27
    Posts
    2,101
    Thanks given
    381
    Thanks received
    334
    Rep Power
    297
    Quote Originally Posted by Reich View Post
    Could be done in a lot less work but it's good i guess...
    Yes it could, i made this very long time ago, that's why i said this deserves some improvement, it's not hard to make it better yourselves.
    Reply With Quote  
     

  8. #8  
    Kneel before me.

    Join Date
    Sep 2012
    Posts
    200
    Thanks given
    202
    Thanks received
    91
    Rep Power
    125
    gj
    Reply With Quote  
     

  9. #9  
    Google it ffs

    Reich's Avatar
    Join Date
    Mar 2011
    Age
    30
    Posts
    825
    Thanks given
    120
    Thanks received
    174
    Rep Power
    105
    Use a boolean and 2 integers to correctly tick. Instead of making a new drawSprite method in the sprites just update the x and y
    Programmers are machines that convert caffeine into code
    Reply With Quote  
     

  10. #10  
    only shallow

    Join Date
    Apr 2011
    Age
    26
    Posts
    1
    Thanks given
    2,907
    Thanks received
    413
    Rep Power
    0
    Quote Originally Posted by Tringan View Post
    *coordToMove - 'x', 'y', 'b' - This is where you choose what coordinate do you want to play with the x coord or y coord or even both.
    what the hell is that supposed to mean?
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. How to make a sprite move
    By Cronicman1 in forum Tutorials
    Replies: 29
    Last Post: 11-09-2012, 09:10 AM
  2. Replies: 3
    Last Post: 06-17-2012, 03:43 AM
  3. How to make npc's move..
    By Samsterz in forum Configuration
    Replies: 14
    Last Post: 04-18-2009, 09:19 PM
  4. How to make transparent sprites!
    By Yarnova in forum Tutorials
    Replies: 55
    Last Post: 03-26-2009, 01:54 PM
  5. Replies: 29
    Last Post: 04-18-2008, 02:44 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •