# A long shot but I thought I'd ask

**URL:** <https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209>\
**Category:** Million Tile Engine\
**Created:** [April 2, 2014, 5:16pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209 "2014-04-02T17:16:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 5:16pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/1 "2014-04-02T17:16:51Z")

</div>

Hi dyson,

i’m trying to use particle candy with mte for firing at sprites.&nbsp; I can get my player shooting properly, but I can’t seem to get any collision detection working.

No code errors – I just dont get any collisions, is this because my fire is ‘outside’ the mte engine?

Any ideas greatly appreciated, Greg

I Create my particle:

Particles.CreateParticleType (“Shots”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imagePath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = “torpedo.png”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imageWidth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 32,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imageHeight&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 32,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;velocityStart&nbsp;&nbsp;&nbsp;&nbsp; = 500,&nbsp;&nbsp; &nbsp;  
–&nbsp;&nbsp; &nbsp;velocityChange = 1,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeInSpeed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.5,&nbsp;&nbsp; &nbsp;– PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;rotationChange = 1000,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;autoOrientation&nbsp;&nbsp; = false,&nbsp;&nbsp; &nbsp;– ROTATE TO MOVEMENT DIRECTION  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;killOutsideScreen = true,&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;lifeTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 2000, &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;alphaStart&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.00,&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;blendMode&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = “add”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;sounds&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = torpedo,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} )  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Particles.PhysicsMaterial = { density = 0.75, friction = 0.5, bounce = 0, radius=16 }  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;Particles.PhysicsProperties ={ isFixedRotation = false, isSleepingAllowed = false, name=“photon” }&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;

I add my emitter to my player:

&nbsp;&nbsp;&nbsp; Particles.CreateEmitter(“E1”, player.x, player.y, 0, false, true)  
&nbsp;&nbsp;&nbsp; Particles.AttachParticleType(“E1”, “Shots”, 1, 5000,2000)  
&nbsp;&nbsp;&nbsp; Particles.StartEmitter(“E1”)

I add a listener to my enemy:

physics.addBody( object, “static”,&nbsp; { density = 3.0, friction = 1.0, bounce = 0.1 } , {radius=400, isSensor = true})  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;object.collision = onenemyCollision  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;object:addEventListener( “collision”, object )

My collision listener:

function onenemyCollision(self,event)

&nbsp;&nbsp; &nbsp;if event.phase==“began” then  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;collisiontype = event.other.id  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;print ("Collision detected: "… collisiontype)  
&nbsp;&nbsp; &nbsp;end  
&nbsp;&nbsp; &nbsp;  
end&nbsp;&nbsp; &nbsp;  
&nbsp;

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 2, 2014, 6:23pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/2 "2014-04-02T18:23:22Z")

</div>

I don’t have experience with ParticleCandy, but it looks like you’re assigning onenemyCollision as an event listener before onenemyCollision exists. Try moving your onenemyCollision function above the physics.addBody call for your enemy.&nbsp;

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 7:00pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/3 "2014-04-02T19:00:07Z")

</div>

I think that particle candy uses general physics tranisitons which are outside the mte scope.&nbsp; So the two don’t currently work together… too bad!

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 2, 2014, 7:22pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/4 "2014-04-02T19:22:37Z")

</div>

This sort of thing seems to come up a lot. Calls to the physics library through MTE and outside in Corona SDK go to the same place. Some of my samples use mte.physics.\*, but this is exactly identical to calling physics.\* directly. Only one physics simulation is running, you’re just calling it indirectly in the first case, passing through MTE to get there. The concept of scope doesn’t really apply here.

As an example, try adding the following code to the bottom of main.lua in the Platformer - Angled PHYSICS sample project:

```
local mapObj = mte.getMapObj() local newBall = display.newCircle(mapObj[3], 1650, 600, 32) physics.addBody(newBall, {radius = 32})

```

As you can see, the circle happily collides with those objects created by and held in MTE.&nbsp;

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 8:02pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/5 "2014-04-02T20:02:56Z")

</div>

Thats great to hear, but for example , if I fire a slow moving weapon with transition.to and then I touch scroll, will the weapon stay in tune with my touch scroll, or will it follow its transition.to path?

(That’s what I though mte.movespriteto did… wrapped a sprite within the scope of the tile engine)

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 2, 2014, 8:38pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/6 "2014-04-02T20:38:56Z")

</div>

Lets say you created a sprite and you neither inserted it into any group nor used addSprite on it. That display object will be placed on Corona’s Stage. If you place the sprite in the top left corner of the screen and use transition.to to send it to the bottom right corner of the screen, it will move from one corner to the other whether MTE’s map is in motion or not. No matter what you do with MTE’s camera, that sprite will always move from the top left to the bottom right corner of your screen. This is because MTE does not move the Stage.&nbsp;

Now imagine that you created a sprite and used addSprite to put it on the map. What’s happened is that MTE has moved the sprite from the Stage into another Group. Groups, like the Stage, have their own internal coordinate system. In most cases the coordinate system will match that of the Stage when you first create the Group. If you use transition.to to send the sprite from one corner of the screen to another it will do so just like before- but only if MTE’s camera isn’t moving. If the camera moves, for example because of touch scroll, the sprite’s path will remain synchronized with the MAP, not the screen. It is still doing exactly what you told it to do; it’s moving from it’s current position to a new position, but those positions are relative to the Group containing the sprite, and the group is in motion too.

Adding a sprite to MTE, or placing it directly on one of MTE’s group objects, doesn’t wrap the sprite in the tile engine’s scope so much as give the engine access to the sprite so that it can manipulate the sprite. A display object can have many references all pointing to the same object, all in the scopes of different functions and libraries.&nbsp;

Are you adding your player and enemy sprite’s to the map? I’m sure we can get Particle Candy working, we just have to figure out where the problem’s hiding.

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 9:13pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/7 "2014-04-02T21:13:53Z")

</div>

thanks for the clarification!&nbsp; Yes I am adding all sprites to the map, except for the torpedo that I am firing.&nbsp; If you remember, my map is in a container

local mapObj = mte.getMapObj()  
&nbsp;&nbsp;&nbsp; newGroup1 = display.newContainer(display.contentWidth \*.6, display.contentHeight\*.88)  
&nbsp;&nbsp; &nbsp;newGroup1.x =display.contentWidth / 3.5  
&nbsp;&nbsp; &nbsp;newGroup1.y = display.contentHeight / 2.2  
&nbsp;&nbsp; &nbsp;newGroup1:insert(mapObj)

When if fire the torpedo to the right, it goes out and past the container, as particle candy is using the display as its extents.

So yes, as per your explanation, the particles / emitter&nbsp; have to be added to the mte group.

This is where the add to mte needs to happen:

&nbsp; Particles.CreateEmitter(“E1”, player.x, player.y, 0, false, true)  
&nbsp; Particles.AttachParticleType(“E1”, “Shots”, 1, 5000,2000)

&nbsp; Particles.StartEmitter(“E1”)

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 3, 2014, 12:23pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/8 "2014-04-03T12:23:44Z")

</div>

Ah, alright, according to Particle Candy documentation the emitters are actually display objects, which means you can add them to the Map like any other. You can retrieve an emitter by calling GetEmitter(name). Try doing one of the following before you call Particles.StartEmitter(“E1”):

```
local setup = {levelPosX = player.x, levelPosY = player.y, layer = 1} mte.addSprite(Particles.GetEmitter("E1"), setup)

```

Or

```
local mapObj = mte.getMapObj() local layer = 1 mapObj[layer]:insert(Particles.GetEmitter("E1"))
```

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 3, 2014, 12:44pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/9 "2014-04-03T12:44:58Z")

</div>

Hi Dyson,

I’ll give it a try.

Mike had this to say:

usually, particles are not meant to be used as game objects. They’re meant  
to be used as “volatile” objects to create visual effects. If you need to access  
an individual particle’s properties, you can loop through the particles and  
access each one individually –see “sample…”.

This allows you to retrieve a particles position, scale, rotation etc.  
However, you should NOT remove this particle manually or move to another parent  
–just let the particle engine handle this.

Particles.CreateEmitter(“E1”, screenW\*0.1, screenH\*0.5, 90, true, true)

Sample…

&nbsp;&nbsp; &nbsp;– DEFINE PARTICLE TYPE PROPERTIES  
&nbsp;&nbsp; &nbsp;Particles.CreateParticleType (“Arrow”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imagePath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = “gfx\_particles/arrow.png”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imageWidth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 32,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– PARTICLE IMAGE WIDTH&nbsp; (newImageRect)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imageHeight&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 32,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– PARTICLE IMAGE HEIGHT (newImageRect)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;velocityStart&nbsp;&nbsp;&nbsp;&nbsp; = 300,&nbsp;&nbsp; &nbsp;– PIXELS PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;autoOrientation&nbsp;&nbsp; = true,&nbsp;&nbsp; &nbsp;– ROTATE TO MOVEMENT DIRECTION  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;killOutsideScreen = true,&nbsp;&nbsp; &nbsp;– KILL PARTICLES WHEN OFF-SCREEN  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;lifeTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 4000,&nbsp;&nbsp; &nbsp;– MAX. LIFETIME OF A PARTICLE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;alphaStart&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– PARTICLE START ALPHA  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeInSpeed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.0,&nbsp;&nbsp; &nbsp;– PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeOutSpeed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = -1.0,&nbsp;&nbsp; &nbsp;– PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeOutDelay&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1000,&nbsp;&nbsp; &nbsp;– TIME TO BEGIN FADE-OUT AFTER SPAWN  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} )

&nbsp;&nbsp; &nbsp;– FEED EMITTERS (EMITTER NAME, PARTICLE TYPE NAME, EMISSION RATE, DURATION, DELAY)  
&nbsp;&nbsp; &nbsp;Particles.AttachParticleType(“E1”, “Arrow”, 4, 99999,0)

&nbsp;&nbsp; &nbsp;– TRIGGER THE EMITTERS  
&nbsp;&nbsp; &nbsp;Particles.StartEmitter(“E1”)

local numParticles = Particles.GetMaxParticles()  
&nbsp;&nbsp; &nbsp;for i = 1, numParticles do  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local Particle = Particles.GetParticle(i)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if Particle ~= nil then  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.x&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S X-COORDINATE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.y&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S Y-COORDINATE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.xScale&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S X-SCALE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.yScale&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S Y-SCALE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.alpha&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S ALPHA  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.xSpeed&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S X-SPEED (NON PHYSICS)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.ySpeed&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S Y-SPEED (NON PHYSICS)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.killTime&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET OR SET PARTICLE’S KILL TIME (IF SMALLER THAN CURR. TIME, PARTICLE WILL BE REMOVED)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.emitterName&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET EMITTER’S NAME  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.isPhysicsParticle &nbsp;&nbsp;&nbsp; &nbsp;– IS PHYSICS PARTICLE?  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.PType.name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE TYPE’S NAME  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end  
&nbsp;&nbsp; &nbsp;end

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 3, 2014, 1:50pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/10 "2014-04-03T13:50:42Z")

</div>

We aren’t manipulated the particles here, just the emitter. According to their docs the particles will automatically spawn into the parent of the emitter. Once we get the emitter into the layer group the rest should fall into line without additional input.

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 4, 2014, 11:40am UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/11 "2014-04-04T11:40:27Z")

</div>

Good call, it works!!!&nbsp; Mike from particle candy also confirmed it:

, ok, so you want to add emitters to the tile maps, not individual particles.  
Yes, you can place emitters within any display group, the particles are then  
drawn within that group. Using the correct physics setup for your particle  
types, you can also make them interact with any other physics items.

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 2, 2014, 6:23pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/12 "2014-04-02T18:23:22Z")

</div>

I don’t have experience with ParticleCandy, but it looks like you’re assigning onenemyCollision as an event listener before onenemyCollision exists. Try moving your onenemyCollision function above the physics.addBody call for your enemy.&nbsp;

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 7:00pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/13 "2014-04-02T19:00:07Z")

</div>

I think that particle candy uses general physics tranisitons which are outside the mte scope.&nbsp; So the two don’t currently work together… too bad!

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 2, 2014, 7:22pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/14 "2014-04-02T19:22:37Z")

</div>

This sort of thing seems to come up a lot. Calls to the physics library through MTE and outside in Corona SDK go to the same place. Some of my samples use mte.physics.\*, but this is exactly identical to calling physics.\* directly. Only one physics simulation is running, you’re just calling it indirectly in the first case, passing through MTE to get there. The concept of scope doesn’t really apply here.

As an example, try adding the following code to the bottom of main.lua in the Platformer - Angled PHYSICS sample project:

```
local mapObj = mte.getMapObj() local newBall = display.newCircle(mapObj[3], 1650, 600, 32) physics.addBody(newBall, {radius = 32})

```

As you can see, the circle happily collides with those objects created by and held in MTE.&nbsp;

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 8:02pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/15 "2014-04-02T20:02:56Z")

</div>

Thats great to hear, but for example , if I fire a slow moving weapon with transition.to and then I touch scroll, will the weapon stay in tune with my touch scroll, or will it follow its transition.to path?

(That’s what I though mte.movespriteto did… wrapped a sprite within the scope of the tile engine)

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 2, 2014, 8:38pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/16 "2014-04-02T20:38:56Z")

</div>

Lets say you created a sprite and you neither inserted it into any group nor used addSprite on it. That display object will be placed on Corona’s Stage. If you place the sprite in the top left corner of the screen and use transition.to to send it to the bottom right corner of the screen, it will move from one corner to the other whether MTE’s map is in motion or not. No matter what you do with MTE’s camera, that sprite will always move from the top left to the bottom right corner of your screen. This is because MTE does not move the Stage.&nbsp;

Now imagine that you created a sprite and used addSprite to put it on the map. What’s happened is that MTE has moved the sprite from the Stage into another Group. Groups, like the Stage, have their own internal coordinate system. In most cases the coordinate system will match that of the Stage when you first create the Group. If you use transition.to to send the sprite from one corner of the screen to another it will do so just like before- but only if MTE’s camera isn’t moving. If the camera moves, for example because of touch scroll, the sprite’s path will remain synchronized with the MAP, not the screen. It is still doing exactly what you told it to do; it’s moving from it’s current position to a new position, but those positions are relative to the Group containing the sprite, and the group is in motion too.

Adding a sprite to MTE, or placing it directly on one of MTE’s group objects, doesn’t wrap the sprite in the tile engine’s scope so much as give the engine access to the sprite so that it can manipulate the sprite. A display object can have many references all pointing to the same object, all in the scopes of different functions and libraries.&nbsp;

Are you adding your player and enemy sprite’s to the map? I’m sure we can get Particle Candy working, we just have to figure out where the problem’s hiding.

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 2, 2014, 9:13pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/17 "2014-04-02T21:13:53Z")

</div>

thanks for the clarification!&nbsp; Yes I am adding all sprites to the map, except for the torpedo that I am firing.&nbsp; If you remember, my map is in a container

local mapObj = mte.getMapObj()  
&nbsp;&nbsp;&nbsp; newGroup1 = display.newContainer(display.contentWidth \*.6, display.contentHeight\*.88)  
&nbsp;&nbsp; &nbsp;newGroup1.x =display.contentWidth / 3.5  
&nbsp;&nbsp; &nbsp;newGroup1.y = display.contentHeight / 2.2  
&nbsp;&nbsp; &nbsp;newGroup1:insert(mapObj)

When if fire the torpedo to the right, it goes out and past the container, as particle candy is using the display as its extents.

So yes, as per your explanation, the particles / emitter&nbsp; have to be added to the mte group.

This is where the add to mte needs to happen:

&nbsp; Particles.CreateEmitter(“E1”, player.x, player.y, 0, false, true)  
&nbsp; Particles.AttachParticleType(“E1”, “Shots”, 1, 5000,2000)

&nbsp; Particles.StartEmitter(“E1”)

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 3, 2014, 12:23pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/18 "2014-04-03T12:23:44Z")

</div>

Ah, alright, according to Particle Candy documentation the emitters are actually display objects, which means you can add them to the Map like any other. You can retrieve an emitter by calling GetEmitter(name). Try doing one of the following before you call Particles.StartEmitter(“E1”):

```
local setup = {levelPosX = player.x, levelPosY = player.y, layer = 1} mte.addSprite(Particles.GetEmitter("E1"), setup)

```

Or

```
local mapObj = mte.getMapObj() local layer = 1 mapObj[layer]:insert(Particles.GetEmitter("E1"))
```

---

<div class="post-metadata">

**Author:** ![greg\_brady](https://forums.solar2d.com/user_avatar/forums.solar2d.com/greg_brady/32/430_2.png) [@greg\_brady](https://forums.solar2d.com/u/greg_brady)\
**Post date:** [April 3, 2014, 12:44pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/19 "2014-04-03T12:44:58Z")

</div>

Hi Dyson,

I’ll give it a try.

Mike had this to say:

usually, particles are not meant to be used as game objects. They’re meant  
to be used as “volatile” objects to create visual effects. If you need to access  
an individual particle’s properties, you can loop through the particles and  
access each one individually –see “sample…”.

This allows you to retrieve a particles position, scale, rotation etc.  
However, you should NOT remove this particle manually or move to another parent  
–just let the particle engine handle this.

Particles.CreateEmitter(“E1”, screenW\*0.1, screenH\*0.5, 90, true, true)

Sample…

&nbsp;&nbsp; &nbsp;– DEFINE PARTICLE TYPE PROPERTIES  
&nbsp;&nbsp; &nbsp;Particles.CreateParticleType (“Arrow”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imagePath&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = “gfx\_particles/arrow.png”,  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imageWidth&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 32,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– PARTICLE IMAGE WIDTH&nbsp; (newImageRect)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;imageHeight&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 32,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– PARTICLE IMAGE HEIGHT (newImageRect)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;velocityStart&nbsp;&nbsp;&nbsp;&nbsp; = 300,&nbsp;&nbsp; &nbsp;– PIXELS PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;autoOrientation&nbsp;&nbsp; = true,&nbsp;&nbsp; &nbsp;– ROTATE TO MOVEMENT DIRECTION  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;killOutsideScreen = true,&nbsp;&nbsp; &nbsp;– KILL PARTICLES WHEN OFF-SCREEN  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;lifeTime&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 4000,&nbsp;&nbsp; &nbsp;– MAX. LIFETIME OF A PARTICLE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;alphaStart&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 0,&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– PARTICLE START ALPHA  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeInSpeed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1.0,&nbsp;&nbsp; &nbsp;– PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeOutSpeed&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = -1.0,&nbsp;&nbsp; &nbsp;– PER SECOND  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;fadeOutDelay&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1000,&nbsp;&nbsp; &nbsp;– TIME TO BEGIN FADE-OUT AFTER SPAWN  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;} )

&nbsp;&nbsp; &nbsp;– FEED EMITTERS (EMITTER NAME, PARTICLE TYPE NAME, EMISSION RATE, DURATION, DELAY)  
&nbsp;&nbsp; &nbsp;Particles.AttachParticleType(“E1”, “Arrow”, 4, 99999,0)

&nbsp;&nbsp; &nbsp;– TRIGGER THE EMITTERS  
&nbsp;&nbsp; &nbsp;Particles.StartEmitter(“E1”)

local numParticles = Particles.GetMaxParticles()  
&nbsp;&nbsp; &nbsp;for i = 1, numParticles do  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;local Particle = Particles.GetParticle(i)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if Particle ~= nil then  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.x&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S X-COORDINATE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.y&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S Y-COORDINATE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.xScale&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S X-SCALE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.yScale&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S Y-SCALE  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.alpha&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S ALPHA  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.xSpeed&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S X-SPEED (NON PHYSICS)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.ySpeed&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE’S Y-SPEED (NON PHYSICS)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.killTime&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET OR SET PARTICLE’S KILL TIME (IF SMALLER THAN CURR. TIME, PARTICLE WILL BE REMOVED)  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.emitterName&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET EMITTER’S NAME  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.isPhysicsParticle &nbsp;&nbsp;&nbsp; &nbsp;– IS PHYSICS PARTICLE?  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– Particle.PType.name&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;– GET PARTICLE TYPE’S NAME  
&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end  
&nbsp;&nbsp; &nbsp;end

---

<div class="post-metadata">

**Author:** ![dyson122](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@dyson122](https://forums.solar2d.com/u/dyson122)\
**Post date:** [April 3, 2014, 1:50pm UTC](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209/20 "2014-04-03T13:50:42Z")

</div>

We aren’t manipulated the particles here, just the emitter. According to their docs the particles will automatically spawn into the parent of the emitter. Once we get the emitter into the layer group the rest should fall into line without additional input.

[Next page](https://forums.solar2d.com/t/a-long-shot-but-i-thought-id-ask/324209.md?page=2)
