couple of questions about mouse effects

Hi guys,
does anyone know how to replace the mouse cursor with a self-created object,that also can change into another object once it goes over something else in the game?

Another thing that i need to know is how i can add objects from a list to a 3d grid, it´s for a level editor.

Any help would be greatly appreciated.

You need to things:
A Custom Cursor script. I could make you one, but there are plenty of superb examples here on the forums.
Level Editing can be hard, but there are a few examples here on the forums. Unfortunately the search function isn’t brilliant, so i suggest that you use google, but after your query type ‘site:blenderartists.org’.

ok i´ll search for that. thanks.

about the 3D Grid: i have made a script that creates a Dictionary (faster than a list) with an Object for every Position. Then you can Access to them and write what ever you need into the object.
It takes about 6 seconds at startup to create about 4000000 block-positions with 250000 objects in the dict.
Access is not expensive at all, so you can add an Object for the Positions you want to see in the Game Engine.
Imagine how long it would take to iterate over a list!!!

That’s a great idea sevi, mind sharing?

well, i can upload the script, but find out, how i t works, you have to do yourself, i dont know if it is helpful:


#############################################################################
#    Copyright (C) 2011 by Severin Stirnemann                                                                                                                            
#    [email protected]                                                                                                                                                                                                                                                                                                                                                    
#############################################################################
__version__ = "1.0"
__author__  = "Sevi"
__date__ = "2011-Jan-24"
__package__ = "Src"

import bge
import time
G = bge.logic
R = bge.render
import random

class Underground_Node(object):
    def __init__(self):
        """ initialises Object """
        self.ressource = {}
        self.dominant = None

class UndergroundManager(bge.types.KX_GameObject):
    """ registers and Indentify Objects """
    def __init__(self, this):
        """ initialises Object """
        # give Object a reference of its own
        bge.types.KX_GameObject.__init__(self)
        self['this'] = self
        self.block_Positions = {} 
        self.allMetalOres = ["ore_alu", "ore_copper",  "ore_gold" ,  "ore_iron",  "ore_silver", "ore_titanium" ]
        self.allMineralOres = ["ore_olivine",  "ore_quarz",  "ore_tritium", "ore_magnesium",  "ore_phosphor",  "ore_sulphur" ]
        self.allOres = self.allMetalOres +self.allMineralOres
        self.dirts = ['ore_granit',  'ore_sand']
        self.allUndergrounds =  self.allOres# + self.dirts
        self.allUnderground_spreading = {"ore_alu":3.0, "ore_copper":5.0,  "ore_gold":0.1 ,  "ore_iron":13.0,  "ore_silver":1.22, "ore_titanium":0.01 , 
                                                            "ore_olivine":4.0,  "ore_quarz":19.0,  "ore_tritium":0.07, "ore_magnesium":6.0,  "ore_phosphor":3.6,  "ore_sulphur":7.0, 
                                                            "granit":10.0,  "sand":28.0}
        self.developedUnderground = {}
        # goto state 2
        self.state = 2
    def create_Underground(self):
        sce = G.getCurrentScene()
        ob = sce.objects
        print ("UndergroundCreation.UndergroUndManager.create_Underground:")
        # get possible resssources including dirt
        start = time.clock()

        # set all Positions in Dict and set random Properties
        size = 200
    
        # amount of undergrounds
        variation = len(self.allUndergrounds)-1
        amount = 250000
        for a in range(0, amount): 
            # amount
            ra = random.randint(0, 500)
            # ressource
            rr = random.randint(0, variation)
            # position
            rx = random.randint(0, size-1)
            ry = random.randint(0, size-1)
            rz = random.randint(-50, -1)
            pos_ = (rx, ry, rz)
            # Node
            node = Underground_Node()
            node.__init__()
            # to Dict
            self.block_Positions[str(pos_)] = node
            # setValue
            self.block_Positions[str(pos_)].ressource[self.allUndergrounds[rr]] = self.allUnderground_spreading[self.allUndergrounds[rr]]*ra
        end = time.clock()
        print ("create_Underground  %.2gs" % (end-start))# 7 sec
        
    def underground_visualise(self,  cont):
        #print ("UndergroundCreation.UndergroundManager.underground_visualise: ")
        sce = G.getCurrentScene()
        ob = sce.objects
        own = cont.owner
        GUI= [scene for scene in G.getSceneList() if scene.name == 'GUI'][0]
        active = GUI.objects['MouseEvents'].activeObject
        prop = cont.sensors["Property"]
        update = cont.sensors["update"]
        if prop.positive or update.positive:
            
            # Dict Check
            x = int(own.worldPosition[0])
            y = int(own.worldPosition[1])
            z = int(own.worldPosition[2])
            
            # create Range List (Cubic)
            range_list = []
            for xr in range(-own['range'], own['range']):
                for yr in range(-own['range'], own['range']):
                    for zr in range(-own['range'], own['range']):
                        if not (x+xr, y+yr, z+zr) in  range_list:
                            range_list.append((x+xr, y+yr, z+zr))
                        if not (x-xr, y-yr, z-zr) in  range_list:
                            range_list.append((x-xr, y-yr, z-zr))
                        if not (x+xr, y-yr, z-zr) in  range_list:
                            range_list.append((x+xr, y-yr, z-zr))
                        if not (x-xr, y+yr, z-zr) in  range_list:
                            range_list.append((x-xr, y+yr, z-zr))
                        if not (x-xr, y-yr, z+zr) in  range_list:
                            range_list.append((x-xr, y-yr, z+zr))
                        if not (x+xr, y-yr, z+zr) in  range_list:
                            range_list.append((x+xr, y-yr, z+zr))
                        if not (x+xr, y+yr, z-zr) in  range_list:
                            range_list.append((x+xr, y+yr, z-zr))
                        if not (x-xr, y+yr, z+zr) in  range_list:
                            range_list.append((x-xr, y+yr, z+zr))
                            
                            
            # write to Dict in Manager and ActiveObject
            for pos in range_list:
                if str(pos) in self.block_Positions:
                    if self.block_Positions[str(pos)].ressource !={}:
                        ress = sce.addObject("radial_alu" ,  own,  25)
                        if not str(pos) in self.developedUnderground:
                            self.developedUnderground[str(pos)] = self.block_Positions[str(pos)]
                        if not str(pos) in active.developedUnderground:
                            active.developedUnderground[str(pos)]  = self.block_Positions[str(pos)]
                        ress.worldPosition = pos
                        mesh = [i for i in self.block_Positions[str(pos)].ressource][0]
                        ress.replaceMesh("radial_" +mesh.split("_")[1])
                        v = self.block_Positions[str(pos)].ressource[mesh]
                        
                        # rescale ressourceObjects
                        if v in range(0, 2):                                                                                                                                            
                            factor = 0.1
                            ress.scaling = (factor,  factor,  factor)
                        if v in range(2, 10):
                            factor = 0.5
                            ress.scaling = (factor,  factor,  factor)
                        if v in range(10, 100):
                            factor = 1
                            ress.scaling = (factor,  factor,  factor)
                        
    def main(self):
        print ("UndergroundCreation.UndergrondManager.main:")
        
        
def register(cont):
    own = cont.owner
    obj = UndergroundManager(own)
    #    print ( "UndergroundCreation.UndergrondManager.register:",own )
def create_Underground(cont):
    own = cont.owner
    own.create_Underground()
def main(cont):
    print ( "UndergroundCreation.UndergrondManager.main:")
    own = cont.owner
    own.main()

def underground_visualise(cont):
    own = cont.owner
    try:
        own.underground_visualise(cont)
    except AttributeError:
        pass


The Underground_Node Class simply stores a Dictionary of ressources or whatever you want to store.
The UndergroundManager Class stores all Positions and Creates Objects for the Positions.
The function underground_visualise creates KX_Game Objects at the Position fitting to the Ressource stored at this Position, in Range of own[‘Range’]. It works fine up to 4x4x4, higher values will slow down the Game Engine dramatically.