I cannot figure out how to move from here, I kind of placed myself in a bad position..

Right now when moving in my game it moves with 1 tile per move, The tiles are 64*64 so it looks realy stupid when i want smooth movement. What i mean with smooth movement is that i want my map to be able to draw a half tile and not only whole tiles.

Here is my current code:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

publicvoiddrawLevel(Graphicsg2d, intscreenX, intscreenY){drawX = 0; //X cordinate for the map to draw atdrawY = 0; //Y Cordinate for the map to draw at

The screenX and screenY is incremented using screenX++; in the player move methods.the scrolling is working but i just cannot figure out how to make the scrolling smooth and not only moving tile per tile.

I thought of change it all to floats but wouldn't that mess with my 2D array?Also i cannot draw the whole array since its a big map of 500 tiles so i need to draw only whats on the screen.

That clumps up all my tiles in the top left corner.. I tried changing it to drawX += 1 and it wont draw the map just place all the tiles in the top corner.

Theese images im drawing is 7*7 tiles but im scaling them up to 63*63. Reason i put the drawX+= in the for loop was to make the tiles not like draw on top of eachother since x is just incremented with 1 and 1 cordinate compared to 63 wont work if u know what i mean.. I just suck at explaining.. Hope you understand me :S

The major difference between a float and a integer is that a float can have a decimal. Now while it is quite useful, it is unneeded here as the x and y variables draw to a pixel origin on the screen. But as you can't have a fraction of a pixel, you don't need decimals.

//Rendering Loopwhile(doRender){//This method draws the tiles into the compositionCanvas image.//The tiles are drawn based on the tilemap coordinates DrawTiles(cameraXpos/cellWidth, cameraYpos/cellWidth, compositionCanvas);

// Now draw the composed image into the app context, displacing it as needed.GraphicsContext.drawImage(compositionCanvas, cameraXpos, cameraYpos, null);

}

It's a very raw code example, just meant to get the idea across. Essentially, draw your tiles completely (say, if the screen shows 10*10 tiles at one time, draw 12*12) and then use the .drawImage method to position the resulting image smoothly.

You can also use this method to draw all tiles at 1:1 scale, and then scale up the resulting image by using the width and height attributes of the .drawImage method.

How often do you call drawLevel() and at what point in your program is it called?

Also, if you always start at drawX = 0 and drawY = 0, wouldn't drawLevel() render the image on the screen the same way everytime?

What I'm thinking is that you should start drawing your tiles depending on the movement of your character, so drawX and drawY should be initialized not to 0, but to a value that is relative/represents the position of your character at any given point in the game.

BTW: I have no idea what game you're developing and how things look like so I'm shooting blind here Screenshot, maybe?

I do understand. What I'm suggesting is that, instead of drawing directly to the screen, you first do exactly what you are doing, draw it all into an intermediate surface, and then draw that image into the screen with the proper position adjustment so it is smooth.

Think of it as taking a photo of your map, and the taking that photo and placing it into the frame in the position it needs to be at.

That way, only thing you need is to add an extra step to your pipeline instead of reworking the rendering algorithm, so if you have:

Movement -> Draw Tiles -> Screen

You'd have

Movement -> Draw Tiles -> Move Intermediate Image -> Screen

The bit about rendering more tiles is just to make sure you don't get empty spaces when positioning the intermediate image. In essence, the intermediate image is larger than the screen area, and you're just moving it around to "frame" the parts you want.

This did not make any difference in the game.. When movement is happended for example: if Player press "D" do screenX++; then i put it into the parameters to drawLevel method.. Maybe im overthinking this and thats why i cannot see the easy solution.. But it still makes every click "jump" 63 pixels everytime i want to move the screen..

EDIT:I know 100% sure this problem is appearing just because im using the drawX and drawY in the levelg2d.draw to get the tiles lined up correctly and not intersecting eachother in the top left. But i cannot find anything to replace it with.. I know thats the reason :S

For people who are trying to help me here, screenX and screenY is the cordinates of the top left corner of the screen that should be visible. I increment it when the player presses a movement button.. Example: screenX++;

For people who are trying to help me here, screenX and screenY is the cordinates of the top left corner of the screen that should be visible. I increment it when the player presses a movement button.. Example: screenX++;

In that case, maybe the problem is with how you're deriving screenX and screenY since those are the values that pretty much dictates where drawLevel() draws the tiles.

Where's the code that determines the value of screenX and screenY to be used when drawLevel() is called?

java-gaming.org is not responsible for the content posted by its members, including references to external websites,
and other references that may or may not have a relation with our primarily
gaming and game production oriented community.
inquiries and complaints can be sent via email to the info‑account of the
company managing the website of java‑gaming.org