Jump to content

  • Log In with Google      Sign In   
  • Create Account


P0jahn

Member Since 21 Nov 2012
Offline Last Active Sep 11 2014 10:20 AM

Topics I've Started

[2D]Make a camera follow multiple characters.

24 August 2014 - 03:47 PM

I am developing a 2D game(platformer) where to top-left corner is x:0,y:0. As you move rightwards, the x coordinate increase and y increasing when moving downwards(in other words, standard coordinate system for 2D games).

 

As in every platformer, the camera is focused on the main character, following her/him. Some games however have more than one main character. In these games, the camera would zoom out if the characters are to far away from each other and at the same time "follow" them.

 

I need to implement this in my game but not sure how. It need to support 1-4 characters.

 

The variables translateX, translateY and scale(where 1.0 is the normal size of the world) need to be set.

 

Language can be either Java, C#, C, C++ or anything that look alike.


Rotate at a point

10 April 2014 - 12:41 PM

I am in process of writing my own laser drawing function and I have ran into a math problem.

Have a look at the following image:

 

img.png

 

The laser is set to fire at a certain point(the top-left corner of the red guy), which it actually does. The top-left, or the bottom-left(not sure which one) corner of the laser beam is exactly at the target coordinate.

What I want to do is to have the lasers middle point at the target point, not the corner.

Here is my code, I am using the following method to draw the laser:

 

SpriteBatch.draw(TextureRegion region, 
                 float x, 
                 float y, 
                 float originX, 
                 float originY, 
                 float width, 
                 float height, 
                 float scaleX, 
                 float scaleY, 
                 float rotation)

And here is my code:

float angle = MathStuff.getAngle(srcX, srcY, destX, destY); //Calculate the angle between the source and destination point.

batch.draw(beamImage, 
           srcX, 
           srcY, 
           0, 
           0, 
           MathStuff.distance(srcX, srcY, destX, destY), 
           beamImage.getHeight(), 
           1, 
           1, 
           angle);

Get position of rotated rectangle

06 April 2014 - 12:09 PM

I am developing a 2D game where the top-left corner is (x:0, y:0) thus x increasing when moving right and y increasing when moving down.

 

 

Same applies to all the rectangles rendered in the game, their top-left corner is their position.

 

So I am rotating an rectangle around its position(orginX:0 relative and orginY:0 relative).

I want to calculate the rectangles top-right position, taking the rotation into account.

 


Render enteties visible on the screen

25 March 2014 - 07:08 AM

I need a formula for my 2D game that calculates whether or not a game object/entity should be rendered.

This means, if an entity is not visible on the screen(the translated view), skip the rendering it.

 

Info:

- The entity stores its position in X and Y(which is the top-left corner of its image). It also stores its width and height.

- The size of the game window/screen is 800x600. The total size of the stage is stageWidth and stageHeight.

- The translation is set not to film areas outside the stage's boundaries. 


Getting a direction constant from normalized vector

17 March 2014 - 04:02 PM

I have a method which returns the direction of a vector.

 

The direction can be either N, NE, E, SE, S, SW, W, NW(8 total).

 

Here is my method, which is horrible buggy: 

	public static Direction getDirection(Point2D.Float normalizedPoint)
	{
		int x = Math.round(normalizedPoint.x);
		int y = Math.round(normalizedPoint.y);
		
		if	   (x == 1 && y == 1)
			return Direction.NW;
		else if(x == 1 && y == 0)
			return Direction.W;
		else if(x == 1 && y == -1)
			return Direction.SW;
		else if(x == 0 && y == -1)
			return Direction.S;
		else if(x == -1 && y == -1)
			return Direction.SE;
		else if(x == -1 &&  y == 0)
			return Direction.E;
		else if(x == -1 && y == 1)
			return Direction.NE;
		else if(x == 0 && y == 1)
			return Direction.E;
		
		return null;
	} 

 

How do I resolve this?

 


PARTNERS