LayerToCanvas not spawning in correct position

0 favourites
  • 11 posts
From the Asset Store
2D fighting template based in the game that defined the fighting games genre.
  • 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.

    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!!

  • 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.

  • 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!

  • bump?

  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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.

  • 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...

  • 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

    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!

  • 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.

  • bscarl88

    Yes, I still had the capx file...

    you can get it at: rieperts.com/games/forum/BugCheckFile.capx

  • ah, i was making it a local variable on the coin and it wasn't working for some reason, but now it does! Thanks again!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)