Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

dusk problem with x value
Started by pokemon124 Sep 18 2016 12:30 PM

4 replies to this topic
[TOPIC CONTROLS]
This topic has been archived. This means that you cannot reply to this topic.
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

pokemon124

[GLOBAL: userInfoPane.html]
pokemon124
  • Observer

  • 4 posts
  • Corona SDK

I am using dusk for my tiled map. I have character moving on enterFrame. But after character.x get on 600 value it give this error: attempt to perform arithmetic on field "x" (a nil value)

I dont know where is problem maybe in camera system but i am new to dusk.

 


[TOPIC: post.html]
#2

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,492 posts
  • Corona SDK

You're trying to manipulate an object that has been removed/deleted.

 

You need to determine why it is being deleted.

 

My 'guess' is that you're letting dusk manage the object and dusk has decided it remove it based on it's position relative to the camera.



[TOPIC: post.html]
#3

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

Without more information I really can't know what's happening here. If you are in fact trying to move a Dusk object around as though it's a normal object, that's probably the issue. You'll need to use an object of your own if you want to move it around or modify it or the like; Dusk will cull objects when they go off the screen. For objects in an object layer, "going offscreen" is defined as when their initial position is offscreen. This allows Dusk to be much more heavily optimized for object layer culling.

 

I recommend that you use an object of your own if you want to move it around. There are a number of pages in which I talk about the concept of "object types," a sort of replacing of Dusk's objects with your own; that might be what you're looking for. I think I have a fairly in-depth introduction to them I can find if you need it.

 

- Caleb



[TOPIC: post.html]
#4

pokemon124

[GLOBAL: userInfoPane.html]
pokemon124
  • Observer

  • 4 posts
  • Corona SDK

yes i find that i need to use an object of my own. And i find some build function: 

 

local function addObjectType(params)
      params.objects = params.objects or {}
      local function buildObject(event)
            local obj = params.build(event)
 
            event.object.builtObject = obj
            obj.mapObject = event.object
            params.objects[obj] = obj
      end
 
            for layer, index in map:getLayers("tile") do
            layer.addObjectListener("type", params.objectType, "drawn", buildObject)
            layer.addObjectListener("type", params.objectType, "erased", function(event)
                  params.objects[event.object.builtObject] = nil
                  params.remove(event.object.builtObject)
            end)
      end
 
      objectTypes[#objectTypes + 1] = params
end
 
 
and the data for that i have like this: 
 
 
local objectType = {}
 
objectType.objectType = "mySpecialObjectType"
 
 
objectType.build = function(event)
  local object = display.newRect(0, 0, event.object.width, event.object.height)
  object.x, object.y = event.object.x, event.object.y
  event.object.parent:insert(object)
  return object
end
 
 
objectType.remove = function(object)
  display.remove(object)
end
 
addObjectType(objectType)
 
 
but i dont seems to get it work :D i understand the basic of how it works but i dont understand how to make it works. And i would be greatfull  if you could send me some of the articles


[TOPIC: post.html]
#5

Caleb P

[GLOBAL: userInfoPane.html]
Caleb P
  • Corona Geek

  • 1,424 posts
  • Corona SDK

If you want to make a persistent object (say, your player or the like), you should create it yourself and manually insert and position it. If you're looking for something that can be removed when it goes offscreen, you can use object types. Basically, make the object in Tiled extend as far as you want the object to be able to travel. That way, the object will be removed when it's offscreen but not as long as it's visible.

 

- Caleb




[topic_controls]
[/topic_controls]