FIFE forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

FIFE 0.4.0 has been released on 15th of January, 2017!

Pages: [1] 2 3

Author Topic: Basics of instance and object manipulation  (Read 6101 times)

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Basics of instance and object manipulation
« on: December 10, 2012, 07:27:04 am »

Hi.
I've just recently started to use FIFE and, to familiarize myself with it, i'm writing a simple app for solving sudoku puzzles.
What i can not figure out myself is the best way to transform values inside cells.
I've decided not to use runtime text output, but to create an atlas of 10 squares, with numbers alredy drawn on them (from 1 to 9 and and empty one). So the tileset has 10 objects with ids from 'tile:1' to 'tile:9', and 'tile:0' for the empty square.
My first intention was to use Object.setId method to transform a tile, but it does not seem to make any visible alterations. The id gets changed(getId() now returns different value for this object), but engine renders same image on top of the object.
So now i'm trying to delete current object, and create a new one in old one's place. I use Layer.deleteInstance method, and it works fine. But when i try to create a new one, the app breaks somewhere inside engine's pump() method, and my Python debugger doesn't catch any exceptions to trace.
That's how i try to create a new object and add it to current layer:
Code: [Select]
object = instance.getObject()
coordinates = instance.getLocation().getMapCoordinates()
self._scene.kill_object(instance)
new_object = Object('tile:0', 'http://192.168.1.1')
self._cell_layer.createInstance(new_object, coordinates)
Can you give me a hint to what i'm doing wrong? Sorry for my english grammar, it's probably horrible.
Logged

helios

  • Developer
  • Jr. Member
  • *
  • Posts: 60
    • View Profile
Re: Basics of instance and object manipulation
« Reply #1 on: December 10, 2012, 07:36:52 pm »

Hey Kresp,
You have different options. If you have already 10 objects and each holds one static image then you have to code something like this:

Code: [Select]
def changeTile(instance, id="tile:1")
    # save old location
    layer = instance.getLocation().getLayer()
    emc = instance.getLocation().getExactLayerCoordinates()
    # delete old instance
    layer.deleteInstance(instance)
    # get object
    object = self.model.getObject(id, "yourNamespace")
    # create new instance
    newInstance = layer.createInstance(object, emc)
    fife.InstanceVisual.create(newInstance)


The other option is that you create only one object which holds all the images but use different directions. Lets say tile0 have direction 0, tile1 a direction of 10, tile2 of 20 and so on.
Then you can call instance.setRotation(0) to get the empty square displayed or setRotation(10) to get the square with 1. It's a bit hacky but so you have not to delete and create new instances on the fly.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #2 on: December 10, 2012, 10:00:52 pm »

Thanks, the first option works perfectly.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #3 on: December 14, 2012, 09:03:33 am »

I need to draw borders around some sides of some objects, with different width and different colors. What's a cleanest way to do it?
http://www.fifengine.net/doxygen/class_f_i_f_e_1_1_render_backend.html#a854a5f3811269b680c59b90d97bc5343
I can't locate drawLine method inside python documentation.
Logged

ChrisOelmueller

  • Newbie
  • Posts: 15
    • View Profile
Re: Basics of instance and object manipulation
« Reply #4 on: December 14, 2012, 01:42:33 pm »

Heya,

you might be interested in the GenericRenderer: http://www.fifengine.net/epydoc/fife.fife.GenericRenderer-class.html#addLine
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #5 on: December 14, 2012, 09:53:55 pm »

Thanks, Chris.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #6 on: December 16, 2012, 01:41:32 am »

How can i make precise outline?
If i fit coordinates for the lines so there is no gaps between them, it all breaks when i change zoom.
Attached picture - zoom 0.6 instead of 1.0. White is outline color, all different colored pixels are part of tile sprite.

And is there a way to may thick lines except to draw a few lines close to each other?
Logged

flutschfinger

  • Newbie
  • Posts: 14
    • View Profile
Re: Basics of instance and object manipulation
« Reply #7 on: December 16, 2012, 05:20:34 am »

Maybe your are looking for the Instance renderer, there you can add a outline http://wiki.fifengine.net/Instance_Renderer
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #8 on: December 16, 2012, 05:51:48 am »

Maybe your are looking for the Instance renderer, there you can add a outline http://wiki.fifengine.net/Instance_Renderer
I'm unsure about how it works. Left and right sides remains untouched for any Threshold values i've tried.
And anyway it can't outline only one particular side.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #9 on: December 16, 2012, 11:49:17 am »

Code: [Select]
clickpoint = fife.ScreenPoint(event.getX(), event.getY())
if event.getButton() == fife.MouseEvent.LEFT:
instances = self.get_instances_at(clickpoint, self._layers['ground_layer'])
instance = instances[0]
points_A = []
points_B = []
def add_point(points, x, y):
zoom = self._cameras['main'].getZoom()
points.append(fife.Point(int(round(x * zoom)), int(round(y * zoom))))
add_point(points_A, 0, -70)
add_point(points_A, 0, -69)
add_point(points_A, -1, -69)
add_point(points_B, 60, -34)
add_point(points_B, 59, -34)
add_point(points_B, 60, -33)
for point_A in points_A:
for point_B in points_B:
i1 = fife.RendererNode(instance, point_A)
i2 = fife.RendererNode(instance, point_B)
self._generic_renderer.addLine('123', i1, i2, 255, 255, 255)
Something like this works as intended, but only for 1.0 zoom (attached picture zoom 0.5). Code looks bad, but i can not figure out a better way to do the same thing. Will have to "whitelist" available zoom values and calibrate each of them manually later on.

And one more thing. ref_cell_height in map file is ignored if ref_cell_width was set before. Hard to make hexagonal tiles to be placed tight, when each tile must lay inside a box with 1:2*3^-0.5 ratio sides. Thinking about using square hexagons Imperialism-style.
Logged

helios

  • Developer
  • Jr. Member
  • *
  • Posts: 60
    • View Profile
Re: Basics of instance and object manipulation
« Reply #10 on: December 16, 2012, 01:06:23 pm »

I'm not sure what is your goal but if you want to outline the cells on the grid then you can try something like this. It should work as long as your tile size match the cell grid size.

Code: [Select]
clickpoint = fife.ScreenPoint(event.getX(), event.getY())
if event.getButton() == fife.MouseEvent.LEFT:
instances = self.get_instances_at(clickpoint, self._layers['ground_layer'])
instance = instances[0]
loc = instance.getLocationRef()
grid = loc.getLayer().getCellGrid()

vertices = grid.getVertices(loc.getLayerCoordinates())
for i in vertices:
firstpt = self._cameras['main'].toScreenCoordinates(grid.toMapCoordinates(i))
...

But zooming is always a problem because in some situations the pixel position can not be determined clearly. thanks for the pointer to ref_cell_height, I'll take a look at it.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #11 on: December 16, 2012, 09:56:23 pm »

I'm not sure what is your goal
Basically i want to draw borders, while border color should indicate which player owns the outlined tiles.
Attached - screenshot from civ5.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #12 on: December 17, 2012, 12:04:23 am »

Code: [Select]
vertices = grid.getVertices(loc.getLayerCoordinates())
Code: [Select]
TypeError: CellGrid_getVertices() takes exactly 3 arguments (2 given)
http://www.fifengine.net/epydoc/fife.fife.CellGrid-class.html#getVertices
What exactly this method should receive?
Logged

helios

  • Developer
  • Jr. Member
  • *
  • Posts: 60
    • View Profile
Re: Basics of instance and object manipulation
« Reply #13 on: December 17, 2012, 06:38:15 am »

Sorry seems that there was a bug  :-\
The output parameter was missing, is now fixed in trunk.
Logged

Kresp

  • Newbie
  • Posts: 22
    • View Profile
Re: Basics of instance and object manipulation
« Reply #14 on: December 17, 2012, 08:09:29 am »

Code: [Select]
C:\Program Files\SlikSvn\bin>svn.exe co http://fife.svn.cvsdude.com/engine/trunk
...
Checked out revision 4075.
Code: [Select]
C:\Program Files\SlikSvn\bin\trunk>c:\Python27\python.exe setup.py install
running install
running build
running build_py
running install_lib
running install_data
running install_egg_info
Removing c:\Python27\Lib\site-packages\fife-0.3.3r3-py2.7.egg-info
Writing c:\Python27\Lib\site-packages\fife-0.3.3r3-py2.7.egg-info
Still get the same error.
Have i used wrong repository?
Logged
Pages: [1] 2 3