It looks like you're new here. If you want to get involved, click one of these buttons!
--getting the x and y coordinates when the object is pressed local function onMouseDown(self, event) if self:hitTestPoint(event.x, event.y) then self.isFocus = true self.x0 = event.x self.y0 = event.y event:stopPropagation() end end --calculating the x and y coordinates when the object is moved local function onMouseMove(self, event) if self.isFocus then local dx = event.x - self.x0 local dy = event.y - self.y0 self:setX(self:getX() + dx) self:setY(self:getY() + dy) self.x0 = event.x self.y0 = event.y event:stopPropagation() end end --x and y coordinates when the object is released local function onMouseUp(self, event) print(event.x, event.y) if self.isFocus then self.isFocus = false event:stopPropagation() end local a local b if (event.x < 40 and event.x > 40) and (event.y < 40 and event.y > 40) then a = 40 - event.x b = 40 - event.y self.x = event.x + a self.y = event.y + b self:setPosition(self.x, self.y) end end |
Comments
Anyways, to resolve your problem, I faced this while I was trying to write the compatibility layer for BeerSDK code to be used with Gideros. The solution.... get rid of the event:stopPropagation()
If that does not resolve your issue, will have to take a detailed look into the same.
Likes: QuasarCreator
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
(event.x < 40 and event.x > 40) and (event.y < 40 and event.y > 40) is always False, meybe
(event.x < 40 and event.x > 0) and (event.y < 40 and event.y > 0) ??
Second:
a = 40 - event.x
b = 40 - event.y
self.x = event.x + a = event.x + 40 - event.x = 40
self.y = event.y + b = event.y + 40 - event.y = 40
And I think it's better to use event:stopPropagation() after your logic in onMouseUp():
Likes: QuasarCreator
http://www.giderosmobile.com/forum/discussion/1255/making-a-square-grid
If I'm rigth then I think it's better to use two-dimensional table of sprites for bitmaps and use Sprite:hitTestPoint(event.x, event.y) in For statement for every element of grid.
Something like this:
But if you use grid in your own sprite (not in main.lua) don't forget to release memory then destroy this sprite. Something like this:
Likes: QuasarCreator
However, there is one little thing that won't work now. When I release my sprite or shape everything works fine, however, if I spawn another sprite and release it the other shape will move towards the other sprite. I am making a puzzle app so there will be multiple sprites on the screen that the user can control. Other than that everything works as I want. Again, I have to say thanks because this is a big part of my app and I was having a hard time getting this logic down. I guess I need to learn more about my lua tables.
I was going to make an if statement for each square. ~X( :-))
Likes: QuasarCreator
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Edit: Wow, I was looking at your blog and you got a lot of articles that would be very useful. Again thanks for sharing.
I was looking at your article of the SpriteEditor demo where you create a nice grid that you can interact with. Could I put my sprites or shapes in the grid made by your Sprite Editor?
I thought you want to use a lot of if statements. But gideros api can do it better I like lua tables and I use it for ai in my game. And don't forget about memory then you use tables. I got a memory leak and try to catch it about week
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Likes: ar2rsawseen
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill