Sign in to follow this  

[java] Side Scrolling And Ramps

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

New to the forum & to Java Development, but I'll see if I can ask my question in a way that you'll understand what I'm trying to figure out. 1) Programing using Netbeans 6.0 for J2ME 2) Using the Sample/Mobility/MIDP/Sample game created with Game Builder as a starting point 3) Trying to figure out how to handle ramps. So when my character moves to the right there is collision detection using sprite.collidesWith(this.ActiveLevel, true) Where ActiveLevel = the Gray Area (I.E. the game map) but Is there a way to detect if he's near a ramp so he will move up / down the ramp correctly ? I saw a tutorial a month ago on this, but can't find the page Any help would be appreciated.

Share this post


Link to post
Share on other sites
Ok looking at going this route (any other ideas ?)

Check for collision (I.E. I Hit the background)
If moving left, check if I can move up & left, if true, them move up & left
Same for Right moves.

After every move(or none move) also add a check to see if player can move down, if so, move down (or down left / right)

Any other ideas ?

Share this post


Link to post
Share on other sites
A Different problem (trying to keep all this on one thread :) )

In both the Emulator & on my cell phone (Motorola Rzr) I've got what looks like a buffering problem



When it first starts it draws the sprite on the bottom half, then when I start to move up, only the top half will scroll.

(Also there's something strange on how it's rendering the layer, where the boulders are (See red circled areas)


The code for moving the window is

private void adjustViewport(int x, int y){
int sx = ActivePlayer.getX();
int sy = ActivePlayer.getY();

int xmin = viewPortX + MIN_BUFFER;
int ymin = viewPortY + MIN_BUFFER;

int xmax = viewPortX + this.getWidth() - ActivePlayer.getWidth() - MIN_BUFFER;
int ymax = viewPortY + this.getHeight() - ActivePlayer.getHeight() - MIN_BUFFER;

if (sx>=xmin && sx<=xmax && sy>=ymin && sy<=ymax){return;} // Not near the edge, don't adjust Viewport

// Check to see if we're moving off screen, if not, do nothing
if(LastDirection == LEFT && sx>=xmin){return;}
if(LastDirection == UP && sy>=ymin){return;}

if(LastDirection == RIGHT && sx<=xmax){return;}
if(LastDirection == DOWN && sy<=ymax){return;}

// X Adjustment
if (x<=ActiveBackground.getX()){viewPortX=ActiveBackground.getX();}
else if (x>ActiveBackground.getX()+ActiveBackground.getWidth()-this.getWidth())
{viewPortX=ActiveBackground.getX()+ActiveBackground.getWidth()-this.getWidth();}
else {viewPortX = x;}

// Y Adjustment
if (y<=ActiveBackground.getY()){viewPortY=ActiveBackground.getY();}
else if (y>ActiveBackground.getY()+ActiveBackground.getHeight()-this.getHeight())
{viewPortY=ActiveBackground.getY()+ActiveBackground.getHeight()-this.getHeight();}
else {viewPortY = y;}

ActiveLayer.setViewWindow(viewPortX, viewPortY, this.getWidth(), this.getHeight());

}

Share this post


Link to post
Share on other sites

This topic is 3587 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this