LayerToCanvas not spawning in correct position

Get help using Construct 2

Post » Fri Jan 17, 2014 2:34 am

1. I'm trying to do an effect where, when you collect a coin, it spawns a new coin on your player and shoot's up to the coin display on the HUD so it looks like it's adding it to the cash reserve. However, when im on my ultrabook, the coin spawns correctly. When im on my desktop with larger monitor, it spawns to the bottom right of the player, so it makes no sense to me. The coin collision event is on event 141. There's 2 sprites involved, the regular coin, and the coin bullet sprite.

I'm creating it on layer HUD using create oobject at
X: LayerToCanvasX("Main", coin.X, Coin.Y)
Y: LayerToCanvasY("Main",Coin.x, Coin.Y)
It requires you to have 3 parameters, so i couldnt just put in an X then Y coordinate.
https://www.dropbox.com/s/ia4heogdjwym7ns/BugCheckFile.capx

2. Another problem we're having (not with this file but with the fuller version) is when the player dies and the level restarts, it cuts the FPS in half each time. There's about 300 objects on screen at once, but they are deleted between deaths so i don't see why that would hurt it.

Can anyone solve these two problems?
Thanks!!bscarl882014-01-17 02:35:14
B
35
S
5
Posts: 411
Reputation: 3,406

Post » Fri Jan 17, 2014 9:27 am

As it states in the manual , spawn creates at either an image point or defaults to the origin, so if you have the origin at the bottom, then it will spawn at the bottom. Maybe add an image point just for the spawn.

Have you tested for odd object creation in the profiler? Maybe run in debug and see what is happening.
If your vision so exceeds your ability, then look to something closer.
Moderator
B
131
S
29
G
81
Posts: 5,328
Reputation: 56,630

Post » Fri Jan 17, 2014 12:48 pm

The origin is at the bottom, but the coin is not spawning on the palyer, it is about 150 pixels off, diagonal to the bottom right of the player's origin, or nowhere near it. BUT only on my desktop, my laptop it spawns normally.

Ill check for the odd object creation, thanks!
B
35
S
5
Posts: 411
Reputation: 3,406

Post » Sat Jan 18, 2014 9:07 pm

bump?
B
35
S
5
Posts: 411
Reputation: 3,406

Post » Sat Jan 18, 2014 11:57 pm

zenox98 was trying to tell you to keep it as simple as possible - make an image point in your player sprite and spawn the coin on that imagepoint. That way it can't miss.

The canvasToLayer function will give you different results on different screen sizes and orientations, and only makes it more difficult to get the effect you want. Whenever possible, use the simplest method and let the power of C2 do the work.
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Sun Jan 19, 2014 12:25 am

Hi,
tried your capx - even with creating the coin at imagepoint of the player or the playerimage. But it always was off. (Desktop).

It worked though, as i set the Layer that it spawns on to "Main". Strange.
B
22
S
7
G
4
Posts: 154
Reputation: 3,699

Post » Sun Jan 19, 2014 3:21 am

Well, I just played around with your capx too.

The problem is that you are converting the coordinates of the Coin being collected to the actual canvas coordinates, but then you are not converting the canvas coordinates to the HUD layer's coordinates. So, when the game screen does not fully fill the monitor it is off.

I created two local variables for that section: canvasX and canvasY

and set them too:

canvasX = LayerToCanvasX("Main",Coin.X,Coin.Y)
canvasY = LayerToCanvasY("Main",Coin.X,Coin.Y)

then created the Coins object at:

Create object Coins on layer "HUD" at ( CanvasToLayerX("HUD",CanvasX,CanvasY), CanvasToLayerY("HUD",CanvasX,CanvasY) )


That seemed to work fine. (I slowed the speed of the Coins way down because they were moving almost too fast to see!)

I still think simple is better. Your capx sure has a lot of global variables and a lot of code. I would try to simplify it by using more instance variables, arrays, functions, etc...

But, the game looks good! You are well on your way to making some great games! :)

I can't really tell why the FPS would decrease. It does seem to work fine in the version you uploaded. Like zenox98 said, try using the debugger to see what is hogging all the processing time - you probably have more objects than you think, or something isn't getting reset...AllanR2014-01-19 03:30:17
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Post » Sun Jan 19, 2014 3:05 pm

Thanks so much! This isn't actually the real game, it's just a mini game of it. If you want to demo the actual game (Alpha release), click here
https://dl.dropboxusercontent.com/u/104143348/Can%20You%20Escape/index.html

It's still missing lots of art and menu stuff, but it's getting there.

Thanks again!
B
35
S
5
Posts: 411
Reputation: 3,406

Post » Sun Jan 19, 2014 11:20 pm

@AllanR

Ive tried this way and multiple ways to get it working, still nothing :/ Do you still have the capx you did it on? I gave the coin 2 instance variables, CanvasX & CanvasY, when player touches the coin, that's when it sets the variable and does the other actions.

I'm also doing it while scrolling instead of the capx I sent you that is just the player standing within 1 area.
B
35
S
5
Posts: 411
Reputation: 3,406

Post » Mon Jan 20, 2014 7:28 am

@bscarl88
Yes, I still had the capx file...
you can get it at: www.rieperts.com/games/forum/BugCheckFile.capxAllanR2014-01-20 07:32:20
B
94
S
33
G
20
Posts: 438
Reputation: 17,615

Next

Return to How do I....?

Who is online

Users browsing this forum: ezgaming420, marcinkowski and 2 guests