is Efficient Tile-based Scrolling the right thing for my game?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
NoAim91
Prole
Posts: 38
Joined: Mon Feb 20, 2017 10:28 am
Location: Germany

is Efficient Tile-based Scrolling the right thing for my game?

Post by NoAim91 »

Hello, long story short I try to make a game like "dwarfs?!" or Age of Empieres ...

What is the better solution:
1.) Tile-base Scrolling
2.) Implement a Camera

I think I know the answer but I like to get a second opinion.
MasterLee
Party member
Posts: 141
Joined: Tue Mar 07, 2017 4:03 pm
Contact:

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by MasterLee »

The first point is an solution to archive part of the second point. But only an part the concept of an camera includes so much more possibilities. fisheye lens might be very funny om RTS games ;)
NoAim91
Prole
Posts: 38
Joined: Mon Feb 20, 2017 10:28 am
Location: Germany

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by NoAim91 »

Mmh, ok

I think I need to place an object at the tilemap

lets say I build at tilemap[1][1] .. then [1][1] = object
lets say the object has self.image = 1 (for the image)

will tilemap[1][1].image give back a 1 ???? -> I have tested it and its not 1 ... how do I make it?

edit: the problem is the if statement.

if tilemap[1][1] ~= nil then -> false, nothing with then
if tilemap[1][1] == Object then -> false, nothing with then
if i print tilemap[1][1] then the system say Object

edit2: i think i will sove it on another way ... but i´m still interested in a answer to my question :-)
User avatar
zorg
Party member
Posts: 3074
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by zorg »

NoAim91 wrote: Wed Mar 22, 2017 11:04 am Mmh, ok

I think I need to place an object at the tilemap

lets say I build at tilemap[1][1] .. then [1][1] = object
lets say the object has self.image = 1 (for the image)

will tilemap[1][1].image give back a 1 ???? -> I have tested it and its not 1 ... how do I make it?

edit: the problem is the if statement.

if tilemap[1][1] ~= nil then -> false, nothing with then
if tilemap[1][1] == Object then -> false, nothing with then
if i print tilemap[1][1] then the system say Object

edit2: i think i will sove it on another way ... but i´m still interested in a answer to my question :-)
Use code blocks, they're there for a reason.

Code: Select all

tilemap[1][1] = object
What's "object" there?

Code: Select all

tilemap[1][1].image = 1
Did you mean this, by self.image = 1 ?

Code: Select all

if tilemap[1][1] == Object
you used "object" above, without the capital O, is that relevant?

To be honest, only giving us code snippets like that means we can't give you exact help, for various reasons. You might be using self wrong, you might be assigning a love image object to that field of your tilemap table instead of a number, you might be comparing against a variable, and not a string, or you might have a capitalization error.

You give us more details, our answers may get more helpful. :3

p.s.: I tend to agree with MasterLee, Scrolling is a bit separate from cameras; The method of scrolling (tile-based, pixel-based, etc.) is part of a camera system, whether or not you coded any other parts of a camera.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
NoAim91
Prole
Posts: 38
Joined: Mon Feb 20, 2017 10:28 am
Location: Germany

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by NoAim91 »

Ok, more information.. :-)

I like to make a clone of the Game "dwarfs?!". (http://store.steampowered.com/app/213650/)

to display the Ground and the Tiles which can be dismanteled I use the Efficient Tile-based Scrolling Tutorial. (https://love2d.org/wiki/Tutorial:Effici ... _Scrolling)

and i use a simple camera (http://nova-fusion.com/2011/04/19/camer ... he-basics/)

Now if I place a building on the map, 2 things happen:
1.) I draw the building with the Efficient Tile-based Scrolling technic
2.) I create a object with a constructor which is the building. I display this object with a little rectangel, to present it. (if it all works I will remove the rectangel)

Now I use the Efficient Tile-based Scrolling to move the drawing of the building
AND I use the camera to move the object which is the building.
But the speed isn´t the same, thats a big problem.... if the speed would be the same I think it would be a solution. (a bad solution, but a solution)

Code: Select all

function controls(dt)
  if love.keyboard.isDown("up")  then
    moveMap(0, -0.8 * tileSize * dt)
    camera:move(0, -25.62 * tileSize * dt)
  end
  if love.keyboard.isDown("down")  then
	moveMap(0, 0.8 * tileSize * dt)
        camera:move(0, 25.62 * tileSize * dt)
  end
  if love.keyboard.isDown("left")  then
    moveMap(-0.8 * tileSize * dt, 0)
    camera:move(-25.62 * tileSize * dt, 0)
  end
  if love.keyboard.isDown("right")  then
    moveMap(0.8 * tileSize * dt, 0)
    camera:move(25.62 * tileSize * dt, 0)
  end
end
edit1: when i move the map with 0.8 and the camera with 25.62 the move very very similar, but one of them is a little bit slower.

I think the problem is not realy the code itself, but the problem is that i don´t know what I have to code.
I can uploade the full project .. but I think no one wants to dig through the code.
User avatar
zorg
Party member
Posts: 3074
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by zorg »

The point of a camera is to move that instead of your world (or, in other words, your tiles and everything else).

Edit: Everything else includes your map too. You don't move your map, that's what the camera is for, as i just said.
Last edited by zorg on Wed Mar 22, 2017 11:09 pm, edited 1 time in total.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
NoAim91
Prole
Posts: 38
Joined: Mon Feb 20, 2017 10:28 am
Location: Germany

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by NoAim91 »

Yes I know. And with tiledScrolling I move the map. That is a big problem. But I need the function that only the Tiles which I can see will be drawn.

My current map size is 1200x1200 Tiles, so I can not draw all the tiles all the time.

edit1: could I make this function with a collision check? ... let me throw away the tiled Scrolling and place a function in the constructor that only the buildings which are in my field of view will be drawn. And the same for the tiles.... I think I got it xD
User avatar
Nikki
Prole
Posts: 33
Joined: Wed Jan 25, 2017 5:42 pm

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by Nikki »

I'd rethink your setup a little bit, the camera code you're using is not good enough,
I think you want a camera that :
- uses the whole world (just the data in arrays)
- has some offset x, y
- has a width and height
Then you can calculate which tiles you actually need to render.

First just build this using tile offset, not pixel offsets,
So for example write this function
DrawPartOfWorld(tileX, tileY, widthInTiles, HeightInTiles)
Extra kudos for making it so you can scale this camera, make the output bigger and smaller. Using the same amount of tiles.

Anyway, when this is working, I'd study the scroling code some more and try to adapt your camera so you can make it
Pixel precise, instead of tile precise.
NoAim91
Prole
Posts: 38
Joined: Mon Feb 20, 2017 10:28 am
Location: Germany

Re: is Efficient Tile-based Scrolling the right thing for my game?

Post by NoAim91 »

Nikki wrote: Thu Mar 23, 2017 8:10 am I'd rethink your setup a little bit, the camera code you're using is not good enough,
I think you want a camera that :
- uses the whole world (just the data in arrays)
- has some offset x, y
- has a width and height
Then you can calculate which tiles you actually need to render.
This is exactly what I've been thinking about the whole night :-)

It is lightweight if I only render things which are in the arrays of my view. Let´s say in my field of view is array[10][10] up to array [60][60]. All things in this range will be drawn. Thats fine, until Objects come along the way. The first things are buidlings and the second thing are units (which can move).
I could store the buidling in the array, but than I´m not able to read data out of the object. (maybe its possible, but i don´t know how)
The second thing are the units, which are moving pixel precise. Would i only draw out of the array i they can only move tile precise and i have to store the units after moving in another position in the array.

However ... I will work on it .. i have a little idea of what i´m doing and hopefully it will work better than expected xD



If there is the question what do I mean with Objects?
-> I use the classic libary and the sheepolution Tutorial about Objects. (https://youtu.be/Z9ssHdZnGI0)
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests