Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Problem with map groups (layers)
Started by d.mach Jan 22 2016 09:51 AM

5 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

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 849 posts
  • Corona SDK

I encountered a strange problem:

I have a map layer where my player sprite is in and I have another map layer for collision tiles (like the ground the player is moving on) and then I have another map layer for moving platforms. In the platform layers there are platforms which are groups containing platform tiles.

 

Now I want to put the player group (contains the sprite and some helper objects) into one of the platform groups when the player group is moved on a platform (means the player is walking on a platform).

 

This is what happens:

Once the player group is added to a platform group with

movingPlatform[1]:insert(groups.player)

the whole player group becomes invisible and not even groups.player:toFront() is working to bring it on top of this layer. The platform is in front and as I understand it the player group (now inside the same group) should get to the front with this command... but isn't.

 

Now I wonder if the whole group handling using the map.layer should be done different than "normal" and if there are some things to think of when moving objects between layers, and groups inside the layers?

 

I can't get this to work and it should be very easy... I just want to add the player group to the moving platform group as long as the player is standing on it, so it moves with the platform.

 

 



[TOPIC: post.html]
#2

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 849 posts
  • Corona SDK

I guess I have found the problem: Once the player group is inserted inside the platform group the collision check with the screen coordinates gets messed up because the x and y pos values are changed.

 

Now I wonder how to handle this best, so the tile collision check with the player group can be checked even when the player group is inside the platform group... tricky!

 

If anyone has encountered the same problem I would be thankful for some hints how to handle this best.

 

Thx!



[TOPIC: post.html]
#3

Alex@Panc

[GLOBAL: userInfoPane.html]
Alex@Panc
  • Corona Geek

  • 1,731 posts
  • Corona SDK

The best solution might be not to re-position the group layers, but simply apply the motion logic of the platforms, on collision, to the player object. That way, everything stays in their lane, but you can get the player to move as you see fit.



[TOPIC: post.html]
#4

Caleb P

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

  • 1,424 posts
  • Corona SDK

Sorry, I've been out of town for a couple of days. If you absolutely have to insert the player into the platform group, you should use a repositioning function which content-izes the coordinates then localizes them like so:

local changeObjectParent = function(obj, newGroup)
	local x, y = obj.parent:localToContent(obj.x, obj.y)
	newGroup:insert(obj)
	obj.x, obj.y = newGroup:contentToLocal(x, y)
end

But it sounds like for what you're doing you could just move the player with the platform instead of relying on Corona's group mechanisms. I did the same thing in my platformer, and all you need to do is translate the player each frame according to how much the platform moved. You won't even need extra physics code, because your physics engine (if you've written it "normally") will handle collisions relatively and not care about it.

if playerIsOnPlatform then
  player:translate(amountPlatformMovedThisFrameX, amountPlatformMovedThisFrameY)
end

updatePlayerPhysics()
yadaYadaYada()

- Caleb



[TOPIC: post.html]
#5

d.mach

[GLOBAL: userInfoPane.html]
d.mach
  • Contributor

  • 849 posts
  • Corona SDK

Thank you guys for the tips!

I'm now moving the player with the platform and it is working. I had some problems before because the player wasn't moved each frame the platform was. Now I've fixed this it works fine.

 

I now have the first basic platformer with my own physics working and even moving platforms. I guess that was 99% of the things I had to proof and everything which is coming now should not cause any problems.



[TOPIC: post.html]
#6

Caleb P

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

  • 1,424 posts
  • Corona SDK

Congratulations on implementing the bones of your game! That's a big step. After that, it's fairly easy to implement other stuff, unless you're building a ridiculously complex platformer with all sorts of mechanics and twists and stuff (like I'm doing... still got a loooong way to go :( ). Don't forget to leave a note when you're done with it and I'll put it up on GitHub as the beginnings of a Dusk showcase!

 

- Caleb




[topic_controls]
[/topic_controls]