Welcome Guest ( Log In | Click here to Register a free account now! )
Welcome to Bleeping Computer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.| Important Announcement: We have two terrific contests running on the site that I wanted all our members and guests to know about. The first contest is the HP Magic Giveaway, which is underway as of November 28th. More information can be found at this topic, which will be updated very soon with further information. The second contests, is for the chance to win two Seagate FreeAgent external hard drives. More information about this contest can be found here. These are both amazing contests and I suggest everyone submit an entry for them. - BleepingComputer Management |
![]() ![]() |
Mar 21 2008, 07:05 AM
Post
#1
|
|
|
Member ![]() ![]() Group: Members Posts: 86 Joined: 5-March 07 From: Brighton, UK Member No.: 115,537 |
Well, here's where I need help. When I detect when the left and right key has been pressed I want to switch the sprite to look the corresponding way. What I have tried so far is in my draw method, I use an if statement to check which way the sprite is travelling, then if the sprite is travelling left, I use a transform to set the way the sprite is looking. This is what I have so far: CODE public void draw(Graphics2D g) { // draw background g.drawImage(bgImage, 0, 0, null); // draw sprite g.drawImage(player.getImage(), Math.round(player.getX()), Math.round(player.getY()), null); //If the player is facing travelling left, then switch the sprite around to face left. transform = new AffineTransform(); if (player.getVelocityX() < 0){ transform.scale(-1,1); transform.translate(-player.getWidth(), 0); g.setTransform(transform); g.drawImage(player.getImage(), transform, null); } } Needless to say this didn't work, when I tried running, when I pressed the left key, a new sprite appeared in the top corner and was looking the same way as before so it didn't even switch. Any help would be great =] Dan |
|
|
|
![]() ![]() |
| Lo-Fi Version | Time is now: 2nd December 2008 - 02:47 AM |