Panel:Center() is not centring the Derma Frame - garrys-mod

I've created a Derma Frame, and when I call Center() on that frame it doesn't properly center to the screen.
Screenshot:
Here's the code:
local ply = LocalPlayer()
hook.Add("OnPlayerChat", "Link:lnotify:OnPlayerChat", function(ply, text, teamChat, isDead)
if(ply:IsSuperAdmin()) then
if (text == "!lnotify") then
local lnotifyAdminMenu = vgui.Create("DFrame")
lnotifyAdminMenu:Center()
lnotifyAdminMenu:SetSize(1000, 720)
lnotifyAdminMenu:ShowCloseButton(true)
lnotifyAdminMenu:MakePopup()
end
else
Derma_Message("You're not permitted to use this menu", "Access Denied", "OK")
end
end)

The :Center() function does set the starting position of the frame in the middle a you can see on your screenshot. I am not sure, but I think that there is no function which automatically centers your frame.

I spoke to a few members on Discord. Credit to XXenix#2334 on Discord for resolving this.
It's actually quite logical. In my code, I'm using the :Center() function, before I've set the size. GLua is setting the position of the frame when the frame is 0px by 0px, and then once the game has set the size, the top left corner is in the center spot.
I hope this can help other newcomers with GLua.

Related

gsap Flip.fit svg element not moving to expected coordinates because of { duration: x }

I am confused with gsap's Flip.fit moving to coordinates.
I have a game board with 182 tiles and 182 playing tiles.
The goal
When the user clicks the bag, a random playing tile is selected and is "supposed" to move over the tile on the board.
If you change
Flip.fit(PTILE[tileArray], TILE[tileArray], {duration: 1 , scale: true});
when changing { duration: 0, ... } the move works as expected, however no animation. When duration is above zero, the final location is very random.
codepen
I'm not sure how the duration affects the final position, however, I found a way to get the positions right. That is reset the transform of your PTILE before telling GSAP to do the Flip animation.
// reset transform value
gsap.set(PTILE[tileArray], { transform: "" });
// animate with new transform value
Flip.fit(PTILE[tileArray], TILE[tileArray], {
duration: 1,
scale: true
});
My reason is that PTITLE and TITLE are placed in different <g> tags which means their transform systems are inconsistent. Plus, Flip.fit() will act like gsap.to() with new TITLE position is the to object, GSAP will try to calculate the from object from your original transforms which are already set in the SVG as transform:matrix(). This process, somehow, is messing up. So what I did is give GSAP an exact transform value for the from object, which is empty.
Ok, I found out that Inkscape stores the SVG with inline transforms that threw the animation off. I tried saving in plain or optimised, but still had no luck.
So there are two solutions.
Use SVGOMG an online SVG cleaner.
Use Affinity Designer application which can export and flatten transforms.
The key to rule out other factors is to use relative coordinates and flatten transforms.
I have included a screenshot of Affinity exporting options.
Affinity Export screenshot

How to invert the sprite position in GameMaker Studio 2 code?

I put this code for my sprite to reverse the position according to its direction but it reverses the position and it looks skinny. How to fix this?
key_left = keyboard_check(ord("A"))
key_right = keyboard_check(ord("D"))
key_jump = keyboard_check(vk_space)
var move = key_right - key_left
hspd = move * spd;
vspd = vspd + grv;
if (hspd != 0) {
image_xscale = sign(hspd)
}
The code's correct. You must have resized the sprite in the room editor, delete the instance and put it in again and don't resize it, it should work.
Also if you need it a little bigger you can (If 1.5 doesn't satisfy you, feel free to use a bigger number).
image_xscale = sign(hspd) * 1.5;
The code seem to be correct, have you tried setting the origin point at the center? By default the origin point is on the top-left, and once it's set at the center of your sprite, it won't change positions when turning around.
You can set the origin point at the sprite window.

Parallax Scrolling SpriteKit

I have found a tutorial on parallax scrolling in spritekit using objective-C though I have been trying to port it to swift without much success, very little in fact.
Parallax Scrolling
Does anyone have any other tutorials or methods of doing parallax scrolling in swift.
This is a SUPER simple way of starting a parallax background. WITH SKACTIONS! I am hoping it helps you understand the basics before moving to a harder but more effective way of coding this.
So I'll start with the code that get a background moving and then you try duplicating the code for the foreground or objects you want to put in your scene.
//declare ground picture. If Your putting this image over the top of another image (use a png file).
var groundImage = SKTexture(imageNamed: "background.jpg")
//make your SKActions that will move the image across the screen. this one goes from right to left.
var moveBackground = SKAction.moveByX(-groundImage.size().width, y: 0, duration: NSTimeInterval(0.01 * groundImage.size().width))
//This resets the image to begin again on the right side.
var resetBackGround = SKAction.moveByX(groundImage.size().width, y: 0, duration: 0.0)
//this moves the image run forever and put the action in the correct sequence.
var moveBackgoundForever = SKAction.repeatActionForever(SKAction.sequence([moveBackground, resetBackGround]))
//then run a for loop to make the images line up end to end.
for var i:CGFloat = 0; i<2 + self.frame.size.width / (groundImage.size().width); ++i {
var sprite = SKSpriteNode(texture: groundImage)
sprite.position = CGPointMake(i * sprite.size.width, sprite.size.height / 2)
sprite.runAction(moveBackgoundForever)
self.addChild(sprite)
}
}
//once this is done repeat for a forground or other items but them run at a different speed.
/*make sure your pictures line up visually end to end. Just duplicating this code will NOT work as you will see but it is a starting point. hint. if your using items like simple obstructions then using actions to spawns a function that creates that obstruction maybe a good way to go too. If there are more then two separate parallax objects then using an array for those objects would help performance. There are many ways to handle this so my point is simple: If you can't port it from ObjectiveC then rethink it in Swift. Good luck!

XNA game studio simple sprite animation

Ok so im writing 2d game like bubble-bobble i have sprites i have done the physics (moving,jumping,falling so far :D) i have done some kind of shooting but now i want to make my player sprite(rectangle image) animated,but i dont want some kind of very complicated animation. I want something like this : i have 2 player images Right faced creature and Left faced creature the rectangle size of the images is exactly the same ,i also have :
Vector2 playerPosition declared
player = Content.Load<Texture2D>("PlayerRight"); in my LoadContent
spriteBatch.Draw(player, playerPosition, Color.White); in my draw function
all i want is when i press Right/Left - arrow buttons my player image switch between
Right/Left faced images
i dont know what kind of code and where i have to write for that task.
if you need more information about the task please let me know
this is not best solution, but it could give you hint.
playerRight = Content.Load<Texture2D>("PlayerRight");
playerLeft = Content.Load<Texture2D>("PlayerLeft");
playerCameraFacing = Content.Load<Texture2D>("playerCameraFacing");
declare PlayerSprite as Texture2D in player class
update funciton pseudo:
PlayerSprite = playerCameraFacing ;
if key.left then PlayerSprite = playerLeft;
if key.right then PlayerSprite = playerRight;
draw function pseudo:
draw(PlayerSprite, Position, Color)
i put all my animation frames into single image, and then show them using "sourceRectangle".
what is source rectangle in spritebatch.draw in xna
http://msdn.microsoft.com/en-us/library/ff433988.aspx

PyGame animated sprite facing left problems

I am having problems with the following piece of code:
def handle_image_flip(self, old_rect):
new_rect = self.last_frame.get_rect()
self.owner.rect = new_rect
self.owner.rect.y = old_rect.y
if self.owner.facing == -1:
self.owner.rect.right = old_rect.right
else:
self.owner.rect.x = old_rect.x
def animate(self, tick):
if tick - self.last_update > self.image_info[self.action]["frame_rate"]:
self.last_frame = self.get_next_frame(tick)
old_rect = self.owner.rect.copy()
self.owner.image = self.last_frame
self.handle_image_flip(old_rect)
self.last_update = tick
Where:
self.owner is the sprite this piece of code handles
self.owner.facing is the direction the sprite is facing
self.last_frame is the new image I want to display
Since the sprites have different widths, I am getting glitchy animations when facing
LEFT (-1).
There are no problems when moving RIGHT whatsoever.
Any ideas?
If you track player's location using Rect.center or Rect.centerx vs default of topleft then different widths can work.
Depending on your game, using sprite sheets may be beneficial.
in your if statement, in one case you change self.owner.rect.right, in the other case you change self.owner.rect.x.
This could be part of the problem since when you are moving left, you are changing .right rather than .x

Resources