Find Your Forum
  
Welcome, Guest. Please login or register.
Did you miss your activation email?

News: Do you like Samsung Instinct?      
Instinct Forum, Samsung Instinct message board, Samsung Instinct By Sprint, Samsung Instinct phone, new Samsung Instinct, Samsung Instinct phone, Sprint Instinct, Samsung Instinct phone
Best Screen Protector for Samsung Instinct                 Free Sprint Phones and Cheap Plans
                Samsung Instinct Scratch Protection
Pages: [1]
Reply Print
Author Topic: How to get screen point dragged.  (Read 1346 times)
playermanny2
[I][N]
**

Cookies: 0
Hometown: New Orleans
Posts: 17


Email
« on: August 15, 2009, 08:20:37 AM »

Well, I'm making a simple pong game, and i  need to get the interaction between the screen and the pong pad. So how would i make it so that when the screen is dragged up, it goes up, and when the screen is dragged down it goes down. Right now i have it dragging down, but when i try to drag down it never drags up
Code:
public void pointerDragged(int paramInt1, int paramInt2)  {
pointPressY = paramInt2;
if (pointPressY > padY) {
padY -= padYVel;
} else
if (pointPressY < padY) {
padY += padYVel;
}   
repaint();
}


Before i had something else that made it drag up, but never down. Can anyone help me?
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #1 on: August 15, 2009, 08:35:08 AM »

You should save the last PointPressY and compare to that.
Logged
playermanny2
[I][N]
**

Cookies: 0
Hometown: New Orleans
Posts: 17


Email
« Reply #2 on: August 15, 2009, 10:19:33 AM »

ok, so i should save it in the pointpressed method or in my movepad method
Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #3 on: August 15, 2009, 10:22:18 AM »

The best answer I can give you without seeing the whole app is that you need something that will persist between pointer presses and drags, telling you the last location of the touch, so you can figure out which direction the touch point is moving.
Logged
playermanny2
[I][N]
**

Cookies: 0
Hometown: New Orleans
Posts: 17


Email
« Reply #4 on: August 15, 2009, 02:03:11 PM »

ok, im on my fone, so when i get back ill post the app

So, i got it to move up and down, but when i press down, it moves, up and vise versa. Also when i try to switch directions, but don't release my finger from the screen it keeps going the same way, can you help?
Code:
package pong;

import java.io.IOException;
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

public class PongCanvas extends GameCanvas implements Runnable {

private int sleepTime = 30;

private boolean dragging = false;

private Image ballImg;
private Image padImg;
private Sprite ballSprite;
private Sprite padSprite;

private int pointPressY = 0;

private int ballX = getWidth() / 2;
private int ballY = getHeight() / 2;
private int padX = 10;
private int padY = getHeight() / 2;

private int ballDirection = 1;

private final static int ballXVel = 3;
private final static int ballYVel = 1;
private final static int padYVel = 2;

public PongCanvas() {
super(false);
setFullScreenMode(true);
}

public void run() {

while(true) {

updateScreen(getGraphics());

try {
Thread.sleep(sleepTime);
} catch (Exception e) {

}
}

}

public void start() {

try {
ballImg = Image.createImage("/ball.png");
padImg = Image.createImage("/pad.png");
} catch (IOException ioex) {
System.out.println(ioex);
}

ballSprite = new Sprite(ballImg, 3, 3);
ballSprite.defineReferencePixel(2, 2);
ballSprite.setRefPixelPosition(ballX, ballY);
padSprite = new Sprite(padImg, 3, 20);
padSprite.defineReferencePixel(1, 10);
padSprite.setRefPixelPosition(padX, padY);

Thread runner = new Thread(this);
runner.start();
}

private void createBackground(Graphics g) {
g.setColor(0x000000);
g.fillRect(0, 0, getWidth(), getHeight());
}

private void updateScreen(Graphics g) {

createBackground(g);

ballSprite.setRefPixelPosition(ballX, ballY);
ballSprite.paint(g);

padSprite.setRefPixelPosition(padX, padY);
padSprite.paint(g);

moveBall();
movePad();

flushGraphics();

}

private void moveBall() {


if (ballDirection == 0) {
ballX -= ballXVel;
ballY -= ballYVel;
} else if (ballDirection == 1) {
ballX += ballXVel;
ballY -= ballYVel;
} else if (ballDirection == 2) {
ballX += ballXVel;
ballY += ballYVel;
} else if (ballDirection == 3) {
ballX -= ballXVel;
ballY += ballYVel;
}

if (ballDirection == 0 && ballX < 0) {
ballDirection = 1;
} else if (ballDirection == 0 && ballY < 0) {
ballDirection = 3;
} else if (ballDirection == 1 && ballY < 0) {
ballDirection = 2;
} else if (ballDirection == 1 && ballX > getWidth()) {
ballDirection = 0;
if (sleepTime > 5) sleepTime--;
} else if (ballDirection == 2 && ballY > getHeight()) {
ballDirection = 1;
} else if (ballDirection == 2 && ballX > getWidth()) {
ballDirection = 3;
if (sleepTime > 5) sleepTime--;
} else if (ballDirection == 3 && ballY > getHeight()) {
ballDirection = 0;
} else if (ballDirection == 3 && ballX < 0) {
ballDirection = 2;
}

if (ballDirection == 0 && ballSprite.collidesWith(padSprite, false)) {
ballDirection = 1;
} else if (ballDirection == 3 && ballSprite.collidesWith(padSprite, false)) {
ballDirection = 2;
}
}

private void movePad() {

}

public void pointerPressed(int paramInt1, int paramInt2) {
pointPressY = paramInt2;
repaint();
}

public void pointerReleased(int paramInt1, int paramInt2) {
pointPressY = paramInt2;
repaint();
    }

public void pointerDragged(int paramInt1, int paramInt2)  {
if (pointPressY > padY) {
padY += padYVel;
} else
if (pointPressY < padY) {
padY -= padYVel;
}
repaint();
}
}
« Last Edit: August 15, 2009, 03:49:34 PM by playermanny2 » Logged
KillerBeagle
Instinct Fanatic
******

Cookies: 234
Hometown: Wilmington
Posts: 1282



« Reply #5 on: August 15, 2009, 08:45:10 PM »

I see at least one problem, but if I tell you what it is, that doesn't really help you in the long term.  You have already identified two of the issues: your math is backwards so up is down and down is up, and your algorithm doesn't work correctly when the pointer is dragged. What I would do in this case is run it in the emulator with a bunch of debug output statements added, so you can watch the values of your variables and see what's happening.

For example,
               java.lang.System.err.println("Y value in pointerPressed is " + pointPressY );
Logged
playermanny2
[I][N]
**

Cookies: 0
Hometown: New Orleans
Posts: 17


Email
« Reply #6 on: August 15, 2009, 11:23:19 PM »

I got it working, thanks for all your help. i plan on adding different levels later.
Logged
Pages: [1]
Reply Print
Jump to:  

Got a new phone? Find the forum here


Subject Started by Replies Views Last post
Fix my screen?
How To....
MGP 3 1179 Last post August 30, 2008, 06:09:18 PM
by 4syth1
Excellent point regarding Instinct Applications « 1 2 »
The Raves Room
pwagner 17 2938 Last post October 29, 2008, 09:34:29 PM
by fjord
point of this board? « 1 2 3 »
Free Games
zoolake 39 5224 Last post February 05, 2009, 01:53:04 PM
by mjc111
Anyone might be interested in an Weight Watchers point calculator?
Third-Party Instinct Software
BeMeCollective 13 3015 Last post June 12, 2009, 02:22:05 PM
by nels1316
New LCD Screen?
How To....
berniemacman 0 587 Last post December 10, 2009, 10:55:25 AM
by berniemacman




Galaxy S3 | Galaxy Note | Galaxy Nexus | Kindle Fire | Atrix 4G | Motorola Xoom | Windows Phone 7
Nokia Lumia | Top Hosts | Samsung Galaxy Tab | Samsung Galaxy S2 | Samsung Galaxy S | Samsung Wave
HTC Evo 3D | HTC Evo 4G | HTC Incredible | HTC Incredible 2 | HTC Incredible S | HTC Thunderbolt
Motorola Droid Razr
| HTC Desire | HTC Desire HD | HTC Desire Z | HTC Desire S | HTC Wildfire
Motorola Droid | Galaxy Indulge | Nokia N8 | Droid Charge | Droid X | Droid X2 | Droid 2| Droid 3 | Fascinate
HTC Sensation | HTC Flyer | LG Revolution | Asus Transformer | Xperia Play | iPhone 4 | Nexus S | Droid Bionic
HTC One | HTC Wildfire S | HTC Droid Eris


This is an Un-Official fan based Website. The views expressed on this website are solely those of the proprietor, or contributors to the site, and do not necessarily reflect the views or opinions of the parties it covers, and is not affiliated with, endorsed or sponsored by parties involved.
If you have a problem with any of the content posted on this website, please contact "sales@verticalscope.com"
Term of Use | Privacy Policy | BlackRain 2006 by, Crip





















CopyRight 2008 www.instinct-samsung.com
Powered by SMF 1.1.11 | SMF © 2006-2007, Simple Machines LLC